blob: e5a5b1915be252a7f6a48fc784a5ef0bb90b4115 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * 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)
45 * - w_topfill (filler line above the first line)
46 * - 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
92/*
93 * The attributes that are actually active for writing to the screen.
94 */
95static int screen_attr = 0;
96
97/*
98 * Positioning the cursor is reduced by remembering the last position.
99 * Mostly used by windgoto() and screen_char().
100 */
101static int screen_cur_row, screen_cur_col; /* last known cursor position */
102
103#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104static match_T search_hl; /* used for 'hlsearch' highlight matching */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105#endif
106
107#ifdef FEAT_FOLDING
108static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */
109#endif
110
111/*
112 * Buffer for one screen line (characters and attributes).
113 */
114static schar_T *current_ScreenLine;
115
116static void win_update __ARGS((win_T *wp));
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000117static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118#ifdef FEAT_FOLDING
119static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row));
120static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum));
121static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr));
122#endif
Bram Moolenaar4770d092006-01-12 23:22:24 +0000123static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124static int char_needs_redraw __ARGS((int off_from, int off_to, int cols));
125#ifdef FEAT_RIGHTLEFT
126static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag));
127# define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl))
128#else
129static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width));
130# define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c))
131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132#ifdef FEAT_VERTSPLIT
133static void draw_vsep_win __ARGS((win_T *wp, int row));
134#endif
Bram Moolenaar238a5642006-02-21 22:12:05 +0000135#ifdef FEAT_STL_OPT
Bram Moolenaar362f3562009-11-03 16:20:34 +0000136static void redraw_custom_statusline __ARGS((win_T *wp));
Bram Moolenaar238a5642006-02-21 22:12:05 +0000137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6ee10162007-07-26 20:58:42 +0000139#define SEARCH_HL_PRIORITY 0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140static void start_search_hl __ARGS((void));
141static void end_search_hl __ARGS((void));
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +0200142static void init_search_hl __ARGS((win_T *wp));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum));
144static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol));
145#endif
146static void screen_start_highlight __ARGS((int attr));
147static void screen_char __ARGS((unsigned off, int row, int col));
148#ifdef FEAT_MBYTE
149static void screen_char_2 __ARGS((unsigned off, int row, int col));
150#endif
151static void screenclear2 __ARGS((void));
152static void lineclear __ARGS((unsigned off, int width));
153static void lineinvalid __ARGS((unsigned off, int width));
154#ifdef FEAT_VERTSPLIT
155static void linecopy __ARGS((int to, int from, win_T *wp));
156static void redraw_block __ARGS((int row, int end, win_T *wp));
157#endif
158static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del));
159static void win_rest_invalid __ARGS((win_T *wp));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160static void msg_pos_mode __ARGS((void));
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000161#if defined(FEAT_WINDOWS)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +0000162static void draw_tabline __ARGS((void));
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164#if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
165static int fillchar_status __ARGS((int *attr, int is_curwin));
166#endif
167#ifdef FEAT_VERTSPLIT
168static int fillchar_vsep __ARGS((int *attr));
169#endif
170#ifdef FEAT_STL_OPT
Bram Moolenaar9372a112005-12-06 19:59:18 +0000171static void win_redr_custom __ARGS((win_T *wp, int draw_ruler));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172#endif
173#ifdef FEAT_CMDL_INFO
174static void win_redr_ruler __ARGS((win_T *wp, int always));
175#endif
176
177#if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
178/* Ugly global: overrule attribute used by screen_char() */
179static int screen_char_attr = 0;
180#endif
181
182/*
183 * Redraw the current window later, with update_screen(type).
184 * Set must_redraw only if not already set to a higher value.
185 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
186 */
187 void
188redraw_later(type)
189 int type;
190{
191 redraw_win_later(curwin, type);
192}
193
194 void
195redraw_win_later(wp, type)
196 win_T *wp;
197 int type;
198{
199 if (wp->w_redr_type < type)
200 {
201 wp->w_redr_type = type;
202 if (type >= NOT_VALID)
203 wp->w_lines_valid = 0;
204 if (must_redraw < type) /* must_redraw is the maximum of all windows */
205 must_redraw = type;
206 }
207}
208
209/*
210 * Force a complete redraw later. Also resets the highlighting. To be used
211 * after executing a shell command that messes up the screen.
212 */
213 void
214redraw_later_clear()
215{
216 redraw_all_later(CLEAR);
Bram Moolenaar4c3f5362006-04-11 21:38:50 +0000217#ifdef FEAT_GUI
218 if (gui.in_use)
219 /* Use a code that will reset gui.highlight_mask in
220 * gui_stop_highlight(). */
221 screen_attr = HL_ALL + 1;
222 else
223#endif
224 /* Use attributes that is very unlikely to appear in text. */
225 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226}
227
228/*
229 * Mark all windows to be redrawn later.
230 */
231 void
232redraw_all_later(type)
233 int type;
234{
235 win_T *wp;
236
237 FOR_ALL_WINDOWS(wp)
238 {
239 redraw_win_later(wp, type);
240 }
241}
242
243/*
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000244 * Mark all windows that are editing the current buffer to be updated later.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245 */
246 void
247redraw_curbuf_later(type)
248 int type;
249{
250 redraw_buf_later(curbuf, type);
251}
252
253 void
254redraw_buf_later(buf, type)
255 buf_T *buf;
256 int type;
257{
258 win_T *wp;
259
260 FOR_ALL_WINDOWS(wp)
261 {
262 if (wp->w_buffer == buf)
263 redraw_win_later(wp, type);
264 }
265}
266
267/*
268 * Changed something in the current window, at buffer line "lnum", that
269 * requires that line and possibly other lines to be redrawn.
270 * Used when entering/leaving Insert mode with the cursor on a folded line.
271 * Used to remove the "$" from a change command.
272 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
273 * may become invalid and the whole window will have to be redrawn.
274 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 void
276redrawWinline(lnum, invalid)
277 linenr_T lnum;
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000278 int invalid UNUSED; /* window line height is invalid now */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279{
280#ifdef FEAT_FOLDING
281 int i;
282#endif
283
284 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum)
285 curwin->w_redraw_top = lnum;
286 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum)
287 curwin->w_redraw_bot = lnum;
288 redraw_later(VALID);
289
290#ifdef FEAT_FOLDING
291 if (invalid)
292 {
293 /* A w_lines[] entry for this lnum has become invalid. */
294 i = find_wl_entry(curwin, lnum);
295 if (i >= 0)
296 curwin->w_lines[i].wl_valid = FALSE;
297 }
298#endif
299}
300
Bram Moolenaar9d6650f2010-06-06 23:04:47 +0200301#if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \
Bram Moolenaarfd3e5dc2010-05-30 19:00:15 +0200302 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303/*
304 * update all windows that are editing the current buffer
305 */
306 void
307update_curbuf(type)
308 int type;
309{
310 redraw_curbuf_later(type);
311 update_screen(type);
312}
Bram Moolenaarfd3e5dc2010-05-30 19:00:15 +0200313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314
315/*
316 * update_screen()
317 *
318 * Based on the current value of curwin->w_topline, transfer a screenfull
319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
320 */
321 void
322update_screen(type)
323 int type;
324{
325 win_T *wp;
326 static int did_intro = FALSE;
327#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
328 int did_one;
329#endif
330
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000331 /* Don't do anything if the screen structures are (not yet) valid. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332 if (!screen_valid(TRUE))
333 return;
334
335 if (must_redraw)
336 {
337 if (type < must_redraw) /* use maximal type */
338 type = must_redraw;
Bram Moolenaar943fae42007-07-30 20:00:38 +0000339
340 /* must_redraw is reset here, so that when we run into some weird
341 * reason to redraw while busy redrawing (e.g., asynchronous
342 * scrolling), or update_topline() in win_update() will cause a
343 * scroll, the screen will be redrawn later or in win_update(). */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344 must_redraw = 0;
345 }
346
347 /* Need to update w_lines[]. */
348 if (curwin->w_lines_valid == 0 && type < NOT_VALID)
349 type = NOT_VALID;
350
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000351 /* Postpone the redrawing when it's not needed and when being called
352 * recursively. */
353 if (!redrawing() || updating_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354 {
355 redraw_later(type); /* remember type for next time */
356 must_redraw = type;
357 if (type > INVERTED_ALL)
358 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */
359 return;
360 }
361
362 updating_screen = TRUE;
363#ifdef FEAT_SYN_HL
364 ++display_tick; /* let syntax code know we're in a next round of
365 * display updating */
366#endif
367
368 /*
369 * if the screen was scrolled up when displaying a message, scroll it down
370 */
371 if (msg_scrolled)
372 {
373 clear_cmdline = TRUE;
374 if (msg_scrolled > Rows - 5) /* clearing is faster */
375 type = CLEAR;
376 else if (type != CLEAR)
377 {
378 check_for_delay(FALSE);
379 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL)
380 type = CLEAR;
381 FOR_ALL_WINDOWS(wp)
382 {
383 if (W_WINROW(wp) < msg_scrolled)
384 {
385 if (W_WINROW(wp) + wp->w_height > msg_scrolled
386 && wp->w_redr_type < REDRAW_TOP
387 && wp->w_lines_valid > 0
388 && wp->w_topline == wp->w_lines[0].wl_lnum)
389 {
390 wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
391 wp->w_redr_type = REDRAW_TOP;
392 }
393 else
394 {
395 wp->w_redr_type = NOT_VALID;
396#ifdef FEAT_WINDOWS
397 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp)
398 <= msg_scrolled)
399 wp->w_redr_status = TRUE;
400#endif
401 }
402 }
403 }
404 redraw_cmdline = TRUE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000405#ifdef FEAT_WINDOWS
Bram Moolenaar997fb4b2006-02-17 21:53:23 +0000406 redraw_tabline = TRUE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408 }
409 msg_scrolled = 0;
410 need_wait_return = FALSE;
411 }
412
413 /* reset cmdline_row now (may have been changed temporarily) */
414 compute_cmdrow();
415
416 /* Check for changed highlighting */
417 if (need_highlight_changed)
418 highlight_changed();
419
420 if (type == CLEAR) /* first clear screen */
421 {
422 screenclear(); /* will reset clear_cmdline */
423 type = NOT_VALID;
424 }
425
426 if (clear_cmdline) /* going to clear cmdline (done below) */
427 check_for_delay(FALSE);
428
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000429#ifdef FEAT_LINEBREAK
Bram Moolenaar64486672010-05-16 15:46:46 +0200430 /* Force redraw when width of 'number' or 'relativenumber' column
431 * changes. */
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000432 if (curwin->w_redr_type < NOT_VALID
Bram Moolenaar64486672010-05-16 15:46:46 +0200433 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
434 ? number_width(curwin) : 0))
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000435 curwin->w_redr_type = NOT_VALID;
436#endif
437
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438 /*
439 * Only start redrawing if there is really something to do.
440 */
441 if (type == INVERTED)
442 update_curswant();
443 if (curwin->w_redr_type < type
444 && !((type == VALID
445 && curwin->w_lines[0].wl_valid
446#ifdef FEAT_DIFF
447 && curwin->w_topfill == curwin->w_old_topfill
448 && curwin->w_botfill == curwin->w_old_botfill
449#endif
450 && curwin->w_topline == curwin->w_lines[0].wl_lnum)
451#ifdef FEAT_VISUAL
452 || (type == INVERTED
Bram Moolenaarb0c9a852006-11-28 15:14:56 +0000453 && VIsual_active
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
455 && curwin->w_old_visual_mode == VIsual_mode
456 && (curwin->w_valid & VALID_VIRTCOL)
457 && curwin->w_old_curswant == curwin->w_curswant)
458#endif
459 ))
460 curwin->w_redr_type = type;
461
Bram Moolenaar5a305422006-04-28 22:38:25 +0000462#ifdef FEAT_WINDOWS
463 /* Redraw the tab pages line if needed. */
464 if (redraw_tabline || type >= NOT_VALID)
465 draw_tabline();
466#endif
467
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468#ifdef FEAT_SYN_HL
469 /*
470 * Correct stored syntax highlighting info for changes in each displayed
471 * buffer. Each buffer must only be done once.
472 */
473 FOR_ALL_WINDOWS(wp)
474 {
475 if (wp->w_buffer->b_mod_set)
476 {
477# ifdef FEAT_WINDOWS
478 win_T *wwp;
479
480 /* Check if we already did this buffer. */
481 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
482 if (wwp->w_buffer == wp->w_buffer)
483 break;
484# endif
485 if (
486# ifdef FEAT_WINDOWS
487 wwp == wp &&
488# endif
Bram Moolenaar860cae12010-06-05 23:22:07 +0200489 syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490 syn_stack_apply_changes(wp->w_buffer);
491 }
492 }
493#endif
494
495 /*
496 * Go from top to bottom through the windows, redrawing the ones that need
497 * it.
498 */
499#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
500 did_one = FALSE;
501#endif
502#ifdef FEAT_SEARCH_EXTRA
503 search_hl.rm.regprog = NULL;
504#endif
505 FOR_ALL_WINDOWS(wp)
506 {
507 if (wp->w_redr_type != 0)
508 {
509 cursor_off();
510#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
511 if (!did_one)
512 {
513 did_one = TRUE;
514# ifdef FEAT_SEARCH_EXTRA
515 start_search_hl();
516# endif
517# ifdef FEAT_CLIPBOARD
518 /* When Visual area changed, may have to update selection. */
519 if (clip_star.available && clip_isautosel())
520 clip_update_selection();
521# endif
522#ifdef FEAT_GUI
523 /* Remove the cursor before starting to do anything, because
524 * scrolling may make it difficult to redraw the text under
525 * it. */
526 if (gui.in_use)
527 gui_undraw_cursor();
528#endif
529 }
530#endif
531 win_update(wp);
532 }
533
534#ifdef FEAT_WINDOWS
535 /* redraw status line after the window to minimize cursor movement */
536 if (wp->w_redr_status)
537 {
538 cursor_off();
539 win_redr_status(wp);
540 }
541#endif
542 }
543#if defined(FEAT_SEARCH_EXTRA)
544 end_search_hl();
545#endif
546
547#ifdef FEAT_WINDOWS
548 /* Reset b_mod_set flags. Going through all windows is probably faster
549 * than going through all buffers (there could be many buffers). */
550 for (wp = firstwin; wp != NULL; wp = wp->w_next)
551 wp->w_buffer->b_mod_set = FALSE;
552#else
553 curbuf->b_mod_set = FALSE;
554#endif
555
556 updating_screen = FALSE;
557#ifdef FEAT_GUI
558 gui_may_resize_shell();
559#endif
560
561 /* Clear or redraw the command line. Done last, because scrolling may
562 * mess up the command line. */
563 if (clear_cmdline || redraw_cmdline)
564 showmode();
565
566 /* May put up an introductory message when not editing a file */
567 if (!did_intro && bufempty()
568 && curbuf->b_fname == NULL
569#ifdef FEAT_WINDOWS
570 && firstwin->w_next == NULL
571#endif
572 && vim_strchr(p_shm, SHM_INTRO) == NULL)
573 intro_message(FALSE);
574 did_intro = TRUE;
575
576#ifdef FEAT_GUI
577 /* Redraw the cursor and update the scrollbars when all screen updating is
578 * done. */
579 if (gui.in_use)
580 {
581 out_flush(); /* required before updating the cursor */
582 if (did_one)
583 gui_update_cursor(FALSE, FALSE);
584 gui_update_scrollbars(FALSE);
585 }
586#endif
587}
588
Bram Moolenaar860cae12010-06-05 23:22:07 +0200589#if defined(FEAT_CONCEAL) || defined(PROTO)
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200590/*
591 * Return TRUE if the cursor line in window "wp" may be concealed, according
592 * to the 'concealcursor' option.
593 */
594 int
595conceal_cursor_line(wp)
596 win_T *wp;
597{
598 int c;
599
600 if (*wp->w_p_cocu == NUL)
601 return FALSE;
602 if (get_real_state() & VISUAL)
603 c = 'v';
604 else if (State & INSERT)
605 c = 'i';
606 else if (State & NORMAL)
607 c = 'n';
Bram Moolenaarca8c9862010-07-24 15:00:38 +0200608 else if (State & CMDLINE)
609 c = 'c';
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200610 else
611 return FALSE;
612 return vim_strchr(wp->w_p_cocu, c) != NULL;
613}
614
615/*
616 * Check if the cursor line needs to be redrawn because of 'concealcursor'.
617 */
618 void
Bram Moolenaar8e469272010-07-28 19:38:16 +0200619conceal_check_cursur_line()
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200620{
621 if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin))
622 {
623 need_cursor_line_redraw = TRUE;
624 /* Need to recompute cursor column, e.g., when starting Visual mode
625 * without concealing. */
626 curs_columns(TRUE);
627 }
628}
629
Bram Moolenaar860cae12010-06-05 23:22:07 +0200630 void
631update_single_line(wp, lnum)
632 win_T *wp;
633 linenr_T lnum;
634{
635 int row;
636 int j;
637
638 if (lnum >= wp->w_topline && lnum < wp->w_botline
Bram Moolenaar370df582010-06-22 05:16:38 +0200639 && foldedCount(wp, lnum, &win_foldinfo) == 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200640 {
641# ifdef FEAT_GUI
642 /* Remove the cursor before starting to do anything, because scrolling
643 * may make it difficult to redraw the text under it. */
644 if (gui.in_use)
645 gui_undraw_cursor();
646# endif
647 row = 0;
648 for (j = 0; j < wp->w_lines_valid; ++j)
649 {
650 if (lnum == wp->w_lines[j].wl_lnum)
651 {
652 screen_start(); /* not sure of screen cursor */
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +0200653# ifdef FEAT_SEARCH_EXTRA
654 init_search_hl(wp);
Bram Moolenaar860cae12010-06-05 23:22:07 +0200655 start_search_hl();
656 prepare_search_hl(wp, lnum);
657# endif
658 win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE);
659# if defined(FEAT_SEARCH_EXTRA)
660 end_search_hl();
661# endif
662 break;
663 }
664 row += wp->w_lines[j].wl_size;
665 }
666# ifdef FEAT_GUI
667 /* Redraw the cursor */
668 if (gui.in_use)
669 {
670 out_flush(); /* required before updating the cursor */
671 gui_update_cursor(FALSE, FALSE);
672 }
673# endif
674 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200675 need_cursor_line_redraw = FALSE;
Bram Moolenaar860cae12010-06-05 23:22:07 +0200676}
677#endif
678
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679#if defined(FEAT_SIGNS) || defined(FEAT_GUI)
680static void update_prepare __ARGS((void));
681static void update_finish __ARGS((void));
682
683/*
684 * Prepare for updating one or more windows.
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000685 * Caller must check for "updating_screen" already set to avoid recursiveness.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000686 */
687 static void
688update_prepare()
689{
690 cursor_off();
691 updating_screen = TRUE;
692#ifdef FEAT_GUI
693 /* Remove the cursor before starting to do anything, because scrolling may
694 * make it difficult to redraw the text under it. */
695 if (gui.in_use)
696 gui_undraw_cursor();
697#endif
698#ifdef FEAT_SEARCH_EXTRA
699 start_search_hl();
700#endif
701}
702
703/*
704 * Finish updating one or more windows.
705 */
706 static void
707update_finish()
708{
709 if (redraw_cmdline)
710 showmode();
711
712# ifdef FEAT_SEARCH_EXTRA
713 end_search_hl();
714# endif
715
716 updating_screen = FALSE;
717
718# ifdef FEAT_GUI
719 gui_may_resize_shell();
720
721 /* Redraw the cursor and update the scrollbars when all screen updating is
722 * done. */
723 if (gui.in_use)
724 {
725 out_flush(); /* required before updating the cursor */
726 gui_update_cursor(FALSE, FALSE);
727 gui_update_scrollbars(FALSE);
728 }
729# endif
730}
731#endif
732
733#if defined(FEAT_SIGNS) || defined(PROTO)
734 void
735update_debug_sign(buf, lnum)
736 buf_T *buf;
737 linenr_T lnum;
738{
739 win_T *wp;
740 int doit = FALSE;
741
742# ifdef FEAT_FOLDING
743 win_foldinfo.fi_level = 0;
744# endif
745
746 /* update/delete a specific mark */
747 FOR_ALL_WINDOWS(wp)
748 {
749 if (buf != NULL && lnum > 0)
750 {
751 if (wp->w_buffer == buf && lnum >= wp->w_topline
752 && lnum < wp->w_botline)
753 {
754 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum)
755 wp->w_redraw_top = lnum;
756 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum)
757 wp->w_redraw_bot = lnum;
758 redraw_win_later(wp, VALID);
759 }
760 }
761 else
762 redraw_win_later(wp, VALID);
763 if (wp->w_redr_type != 0)
764 doit = TRUE;
765 }
766
Bram Moolenaar738f8fc2012-01-10 12:42:09 +0100767 /* Return when there is nothing to do, screen updating is already
768 * happening (recursive call) or still starting up. */
769 if (!doit || updating_screen
770#ifdef FEAT_GUI
771 || gui.starting
772#endif
773 || starting)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 return;
775
776 /* update all windows that need updating */
777 update_prepare();
778
779# ifdef FEAT_WINDOWS
780 for (wp = firstwin; wp; wp = wp->w_next)
781 {
782 if (wp->w_redr_type != 0)
783 win_update(wp);
784 if (wp->w_redr_status)
785 win_redr_status(wp);
786 }
787# else
788 if (curwin->w_redr_type != 0)
789 win_update(curwin);
790# endif
791
792 update_finish();
793}
794#endif
795
796
797#if defined(FEAT_GUI) || defined(PROTO)
798/*
799 * Update a single window, its status line and maybe the command line msg.
800 * Used for the GUI scrollbar.
801 */
802 void
803updateWindow(wp)
804 win_T *wp;
805{
Bram Moolenaar19f990e2009-11-25 12:08:03 +0000806 /* return if already busy updating */
807 if (updating_screen)
808 return;
809
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 update_prepare();
811
812#ifdef FEAT_CLIPBOARD
813 /* When Visual area changed, may have to update selection. */
814 if (clip_star.available && clip_isautosel())
815 clip_update_selection();
816#endif
Bram Moolenaar4c7ed462006-02-15 22:18:42 +0000817
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 win_update(wp);
Bram Moolenaar4c7ed462006-02-15 22:18:42 +0000819
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820#ifdef FEAT_WINDOWS
Bram Moolenaar4c7ed462006-02-15 22:18:42 +0000821 /* When the screen was cleared redraw the tab pages line. */
Bram Moolenaar997fb4b2006-02-17 21:53:23 +0000822 if (redraw_tabline)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +0000823 draw_tabline();
Bram Moolenaar4c7ed462006-02-15 22:18:42 +0000824
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825 if (wp->w_redr_status
826# ifdef FEAT_CMDL_INFO
827 || p_ru
828# endif
829# ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +0000830 || *p_stl != NUL || *wp->w_p_stl != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831# endif
832 )
833 win_redr_status(wp);
834#endif
835
836 update_finish();
837}
838#endif
839
840/*
841 * Update a single window.
842 *
843 * This may cause the windows below it also to be redrawn (when clearing the
844 * screen or scrolling lines).
845 *
846 * How the window is redrawn depends on wp->w_redr_type. Each type also
847 * implies the one below it.
848 * NOT_VALID redraw the whole window
Bram Moolenaar600dddc2006-03-12 22:05:10 +0000849 * SOME_VALID redraw the whole window but do scroll when possible
Bram Moolenaar071d4272004-06-13 20:20:40 +0000850 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
851 * INVERTED redraw the changed part of the Visual area
852 * INVERTED_ALL redraw the whole Visual area
853 * VALID 1. scroll up/down to adjust for a changed w_topline
854 * 2. update lines at the top when scrolled down
855 * 3. redraw changed text:
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000856 * - if wp->w_buffer->b_mod_set set, update lines between
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857 * b_mod_top and b_mod_bot.
858 * - if wp->w_redraw_top non-zero, redraw lines between
859 * wp->w_redraw_top and wp->w_redr_bot.
860 * - continue redrawing when syntax status is invalid.
861 * 4. if scrolled up, update lines at the bottom.
862 * This results in three areas that may need updating:
863 * top: from first row to top_end (when scrolled down)
864 * mid: from mid_start to mid_end (update inversion or changed text)
865 * bot: from bot_start to last row (when scrolled up)
866 */
867 static void
868win_update(wp)
869 win_T *wp;
870{
871 buf_T *buf = wp->w_buffer;
872 int type;
873 int top_end = 0; /* Below last row of the top area that needs
874 updating. 0 when no top area updating. */
875 int mid_start = 999;/* first row of the mid area that needs
876 updating. 999 when no mid area updating. */
877 int mid_end = 0; /* Below last row of the mid area that needs
878 updating. 0 when no mid area updating. */
879 int bot_start = 999;/* first row of the bot area that needs
880 updating. 999 when no bot area updating */
881#ifdef FEAT_VISUAL
882 int scrolled_down = FALSE; /* TRUE when scrolled down when
883 w_topline got smaller a bit */
884#endif
885#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6ee10162007-07-26 20:58:42 +0000886 matchitem_T *cur; /* points to the match list */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 int top_to_mod = FALSE; /* redraw above mod_top */
888#endif
889
890 int row; /* current window row to display */
891 linenr_T lnum; /* current buffer lnum to display */
892 int idx; /* current index in w_lines[] */
893 int srow; /* starting row of the current line */
894
895 int eof = FALSE; /* if TRUE, we hit the end of the file */
896 int didline = FALSE; /* if TRUE, we finished the last line */
897 int i;
898 long j;
899 static int recursive = FALSE; /* being called recursively */
900 int old_botline = wp->w_botline;
901#ifdef FEAT_FOLDING
902 long fold_count;
903#endif
904#ifdef FEAT_SYN_HL
905 /* remember what happened to the previous line, to know if
906 * check_visual_highlight() can be used */
907#define DID_NONE 1 /* didn't update a line */
908#define DID_LINE 2 /* updated a normal line */
909#define DID_FOLD 3 /* updated a folded line */
910 int did_update = DID_NONE;
911 linenr_T syntax_last_parsed = 0; /* last parsed text line */
912#endif
913 linenr_T mod_top = 0;
914 linenr_T mod_bot = 0;
915#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
916 int save_got_int;
917#endif
918
919 type = wp->w_redr_type;
920
921 if (type == NOT_VALID)
922 {
923#ifdef FEAT_WINDOWS
924 wp->w_redr_status = TRUE;
925#endif
926 wp->w_lines_valid = 0;
927 }
928
929 /* Window is zero-height: nothing to draw. */
930 if (wp->w_height == 0)
931 {
932 wp->w_redr_type = 0;
933 return;
934 }
935
936#ifdef FEAT_VERTSPLIT
937 /* Window is zero-width: Only need to draw the separator. */
938 if (wp->w_width == 0)
939 {
940 /* draw the vertical separator right of this window */
941 draw_vsep_win(wp, 0);
942 wp->w_redr_type = 0;
943 return;
944 }
945#endif
946
947#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +0200948 init_search_hl(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949#endif
950
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000951#ifdef FEAT_LINEBREAK
Bram Moolenaar64486672010-05-16 15:46:46 +0200952 /* Force redraw when width of 'number' or 'relativenumber' column
953 * changes. */
954 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +0000955 if (wp->w_nrwidth != i)
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000956 {
957 type = NOT_VALID;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +0000958 wp->w_nrwidth = i;
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000959 }
960 else
961#endif
962
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0)
964 {
965 /*
966 * When there are both inserted/deleted lines and specific lines to be
967 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
968 * everything (only happens when redrawing is off for while).
969 */
970 type = NOT_VALID;
971 }
972 else
973 {
974 /*
975 * Set mod_top to the first line that needs displaying because of
976 * changes. Set mod_bot to the first line after the changes.
977 */
978 mod_top = wp->w_redraw_top;
979 if (wp->w_redraw_bot != 0)
980 mod_bot = wp->w_redraw_bot + 1;
981 else
982 mod_bot = 0;
983 wp->w_redraw_top = 0; /* reset for next time */
984 wp->w_redraw_bot = 0;
985 if (buf->b_mod_set)
986 {
987 if (mod_top == 0 || mod_top > buf->b_mod_top)
988 {
989 mod_top = buf->b_mod_top;
990#ifdef FEAT_SYN_HL
991 /* Need to redraw lines above the change that may be included
992 * in a pattern match. */
Bram Moolenaar860cae12010-06-05 23:22:07 +0200993 if (syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {
Bram Moolenaar860cae12010-06-05 23:22:07 +0200995 mod_top -= buf->b_s.b_syn_sync_linebreaks;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996 if (mod_top < 1)
997 mod_top = 1;
998 }
999#endif
1000 }
1001 if (mod_bot == 0 || mod_bot < buf->b_mod_bot)
1002 mod_bot = buf->b_mod_bot;
1003
1004#ifdef FEAT_SEARCH_EXTRA
1005 /* When 'hlsearch' is on and using a multi-line search pattern, a
1006 * change in one line may make the Search highlighting in a
1007 * previous line invalid. Simple solution: redraw all visible
1008 * lines above the change.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001009 * Same for a match pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 */
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001011 if (search_hl.rm.regprog != NULL
1012 && re_multiline(search_hl.rm.regprog))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 top_to_mod = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001014 else
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001015 {
1016 cur = wp->w_match_head;
1017 while (cur != NULL)
1018 {
1019 if (cur->match.regprog != NULL
1020 && re_multiline(cur->match.regprog))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00001021 {
1022 top_to_mod = TRUE;
1023 break;
1024 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00001025 cur = cur->next;
1026 }
1027 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#endif
1029 }
1030#ifdef FEAT_FOLDING
1031 if (mod_top != 0 && hasAnyFolding(wp))
1032 {
1033 linenr_T lnumt, lnumb;
1034
1035 /*
1036 * A change in a line can cause lines above it to become folded or
1037 * unfolded. Find the top most buffer line that may be affected.
1038 * If the line was previously folded and displayed, get the first
1039 * line of that fold. If the line is folded now, get the first
1040 * folded line. Use the minimum of these two.
1041 */
1042
1043 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
1044 * the line below it. If there is no valid entry, use w_topline.
1045 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
1046 * to this line. If there is no valid entry, use MAXLNUM. */
1047 lnumt = wp->w_topline;
1048 lnumb = MAXLNUM;
1049 for (i = 0; i < wp->w_lines_valid; ++i)
1050 if (wp->w_lines[i].wl_valid)
1051 {
1052 if (wp->w_lines[i].wl_lastlnum < mod_top)
1053 lnumt = wp->w_lines[i].wl_lastlnum + 1;
1054 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot)
1055 {
1056 lnumb = wp->w_lines[i].wl_lnum;
1057 /* When there is a fold column it might need updating
1058 * in the next line ("J" just above an open fold). */
1059 if (wp->w_p_fdc > 0)
1060 ++lnumb;
1061 }
1062 }
1063
1064 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL);
1065 if (mod_top > lnumt)
1066 mod_top = lnumt;
1067
1068 /* Now do the same for the bottom line (one above mod_bot). */
1069 --mod_bot;
1070 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL);
1071 ++mod_bot;
1072 if (mod_bot < lnumb)
1073 mod_bot = lnumb;
1074 }
1075#endif
1076
1077 /* When a change starts above w_topline and the end is below
1078 * w_topline, start redrawing at w_topline.
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001079 * If the end of the change is above w_topline: do like no change was
1080 * made, but redraw the first line to find changes in syntax. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 if (mod_top != 0 && mod_top < wp->w_topline)
1082 {
1083 if (mod_bot > wp->w_topline)
1084 mod_top = wp->w_topline;
1085#ifdef FEAT_SYN_HL
Bram Moolenaar860cae12010-06-05 23:22:07 +02001086 else if (syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 top_end = 1;
1088#endif
1089 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001090
1091 /* When line numbers are displayed need to redraw all lines below
1092 * inserted/deleted lines. */
1093 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu)
1094 mod_bot = MAXLNUM;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 }
1096
1097 /*
1098 * When only displaying the lines at the top, set top_end. Used when
1099 * window has scrolled down for msg_scrolled.
1100 */
1101 if (type == REDRAW_TOP)
1102 {
1103 j = 0;
1104 for (i = 0; i < wp->w_lines_valid; ++i)
1105 {
1106 j += wp->w_lines[i].wl_size;
1107 if (j >= wp->w_upd_rows)
1108 {
1109 top_end = j;
1110 break;
1111 }
1112 }
1113 if (top_end == 0)
1114 /* not found (cannot happen?): redraw everything */
1115 type = NOT_VALID;
1116 else
1117 /* top area defined, the rest is VALID */
1118 type = VALID;
1119 }
1120
Bram Moolenaar367329b2007-08-30 11:53:22 +00001121 /* Trick: we want to avoid clearing the screen twice. screenclear() will
Bram Moolenaar943fae42007-07-30 20:00:38 +00001122 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1123 * non-zero and thus not FALSE) will indicate that screenclear() was not
1124 * called. */
1125 if (screen_cleared)
1126 screen_cleared = MAYBE;
1127
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 /*
1129 * If there are no changes on the screen that require a complete redraw,
1130 * handle three cases:
1131 * 1: we are off the top of the screen by a few lines: scroll down
1132 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1133 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1134 * w_lines[] that needs updating.
1135 */
Bram Moolenaar600dddc2006-03-12 22:05:10 +00001136 if ((type == VALID || type == SOME_VALID
1137 || type == INVERTED || type == INVERTED_ALL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138#ifdef FEAT_DIFF
1139 && !wp->w_botfill && !wp->w_old_botfill
1140#endif
1141 )
1142 {
1143 if (mod_top != 0 && wp->w_topline == mod_top)
1144 {
1145 /*
1146 * w_topline is the first changed line, the scrolling will be done
1147 * further down.
1148 */
1149 }
1150 else if (wp->w_lines[0].wl_valid
1151 && (wp->w_topline < wp->w_lines[0].wl_lnum
1152#ifdef FEAT_DIFF
1153 || (wp->w_topline == wp->w_lines[0].wl_lnum
1154 && wp->w_topfill > wp->w_old_topfill)
1155#endif
1156 ))
1157 {
1158 /*
1159 * New topline is above old topline: May scroll down.
1160 */
1161#ifdef FEAT_FOLDING
1162 if (hasAnyFolding(wp))
1163 {
1164 linenr_T ln;
1165
1166 /* count the number of lines we are off, counting a sequence
1167 * of folded lines as one */
1168 j = 0;
1169 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln)
1170 {
1171 ++j;
1172 if (j >= wp->w_height - 2)
1173 break;
1174 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL);
1175 }
1176 }
1177 else
1178#endif
1179 j = wp->w_lines[0].wl_lnum - wp->w_topline;
1180 if (j < wp->w_height - 2) /* not too far off */
1181 {
1182 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1);
1183#ifdef FEAT_DIFF
1184 /* insert extra lines for previously invisible filler lines */
1185 if (wp->w_lines[0].wl_lnum != wp->w_topline)
1186 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum)
1187 - wp->w_old_topfill;
1188#endif
1189 if (i < wp->w_height - 2) /* less than a screen off */
1190 {
1191 /*
1192 * Try to insert the correct number of lines.
1193 * If not the last window, delete the lines at the bottom.
1194 * win_ins_lines may fail when the terminal can't do it.
1195 */
1196 if (i > 0)
1197 check_for_delay(FALSE);
1198 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK)
1199 {
1200 if (wp->w_lines_valid != 0)
1201 {
1202 /* Need to update rows that are new, stop at the
1203 * first one that scrolled down. */
1204 top_end = i;
1205#ifdef FEAT_VISUAL
1206 scrolled_down = TRUE;
1207#endif
1208
1209 /* Move the entries that were scrolled, disable
1210 * the entries for the lines to be redrawn. */
1211 if ((wp->w_lines_valid += j) > wp->w_height)
1212 wp->w_lines_valid = wp->w_height;
1213 for (idx = wp->w_lines_valid; idx - j >= 0; idx--)
1214 wp->w_lines[idx] = wp->w_lines[idx - j];
1215 while (idx >= 0)
1216 wp->w_lines[idx--].wl_valid = FALSE;
1217 }
1218 }
1219 else
1220 mid_start = 0; /* redraw all lines */
1221 }
1222 else
1223 mid_start = 0; /* redraw all lines */
1224 }
1225 else
1226 mid_start = 0; /* redraw all lines */
1227 }
1228 else
1229 {
1230 /*
1231 * New topline is at or below old topline: May scroll up.
1232 * When topline didn't change, find first entry in w_lines[] that
1233 * needs updating.
1234 */
1235
1236 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1237 j = -1;
1238 row = 0;
1239 for (i = 0; i < wp->w_lines_valid; i++)
1240 {
1241 if (wp->w_lines[i].wl_valid
1242 && wp->w_lines[i].wl_lnum == wp->w_topline)
1243 {
1244 j = i;
1245 break;
1246 }
1247 row += wp->w_lines[i].wl_size;
1248 }
1249 if (j == -1)
1250 {
1251 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1252 * lines */
1253 mid_start = 0;
1254 }
1255 else
1256 {
1257 /*
1258 * Try to delete the correct number of lines.
1259 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1260 */
1261#ifdef FEAT_DIFF
1262 /* If the topline didn't change, delete old filler lines,
1263 * otherwise delete filler lines of the new topline... */
1264 if (wp->w_lines[0].wl_lnum == wp->w_topline)
1265 row += wp->w_old_topfill;
1266 else
1267 row += diff_check_fill(wp, wp->w_topline);
1268 /* ... but don't delete new filler lines. */
1269 row -= wp->w_topfill;
1270#endif
1271 if (row > 0)
1272 {
1273 check_for_delay(FALSE);
1274 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK)
1275 bot_start = wp->w_height - row;
1276 else
1277 mid_start = 0; /* redraw all lines */
1278 }
1279 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0)
1280 {
1281 /*
1282 * Skip the lines (below the deleted lines) that are still
1283 * valid and don't need redrawing. Copy their info
1284 * upwards, to compensate for the deleted lines. Set
1285 * bot_start to the first row that needs redrawing.
1286 */
1287 bot_start = 0;
1288 idx = 0;
1289 for (;;)
1290 {
1291 wp->w_lines[idx] = wp->w_lines[j];
1292 /* stop at line that didn't fit, unless it is still
1293 * valid (no lines deleted) */
1294 if (row > 0 && bot_start + row
1295 + (int)wp->w_lines[j].wl_size > wp->w_height)
1296 {
1297 wp->w_lines_valid = idx + 1;
1298 break;
1299 }
1300 bot_start += wp->w_lines[idx++].wl_size;
1301
1302 /* stop at the last valid entry in w_lines[].wl_size */
1303 if (++j >= wp->w_lines_valid)
1304 {
1305 wp->w_lines_valid = idx;
1306 break;
1307 }
1308 }
1309#ifdef FEAT_DIFF
1310 /* Correct the first entry for filler lines at the top
1311 * when it won't get updated below. */
1312 if (wp->w_p_diff && bot_start > 0)
1313 wp->w_lines[0].wl_size =
1314 plines_win_nofill(wp, wp->w_topline, TRUE)
1315 + wp->w_topfill;
1316#endif
1317 }
1318 }
1319 }
1320
1321 /* When starting redraw in the first line, redraw all lines. When
1322 * there is only one window it's probably faster to clear the screen
1323 * first. */
1324 if (mid_start == 0)
1325 {
1326 mid_end = wp->w_height;
1327 if (lastwin == firstwin)
Bram Moolenaarbc1a7c32006-09-14 19:04:14 +00001328 {
Bram Moolenaar943fae42007-07-30 20:00:38 +00001329 /* Clear the screen when it was not done by win_del_lines() or
1330 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1331 * then. */
1332 if (screen_cleared != TRUE)
1333 screenclear();
Bram Moolenaarbc1a7c32006-09-14 19:04:14 +00001334#ifdef FEAT_WINDOWS
1335 /* The screen was cleared, redraw the tab pages line. */
1336 if (redraw_tabline)
1337 draw_tabline();
1338#endif
1339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 }
Bram Moolenaar943fae42007-07-30 20:00:38 +00001341
1342 /* When win_del_lines() or win_ins_lines() caused the screen to be
1343 * cleared (only happens for the first window) or when screenclear()
1344 * was called directly above, "must_redraw" will have been set to
1345 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1346 if (screen_cleared == TRUE)
1347 must_redraw = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 }
1349 else
1350 {
1351 /* Not VALID or INVERTED: redraw all lines. */
1352 mid_start = 0;
1353 mid_end = wp->w_height;
1354 }
1355
Bram Moolenaar600dddc2006-03-12 22:05:10 +00001356 if (type == SOME_VALID)
1357 {
1358 /* SOME_VALID: redraw all lines. */
1359 mid_start = 0;
1360 mid_end = wp->w_height;
1361 type = NOT_VALID;
1362 }
1363
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364#ifdef FEAT_VISUAL
1365 /* check if we are updating or removing the inverted part */
1366 if ((VIsual_active && buf == curwin->w_buffer)
1367 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID))
1368 {
1369 linenr_T from, to;
1370
1371 if (VIsual_active)
1372 {
1373 if (VIsual_active
1374 && (VIsual_mode != wp->w_old_visual_mode
1375 || type == INVERTED_ALL))
1376 {
1377 /*
1378 * If the type of Visual selection changed, redraw the whole
1379 * selection. Also when the ownership of the X selection is
1380 * gained or lost.
1381 */
1382 if (curwin->w_cursor.lnum < VIsual.lnum)
1383 {
1384 from = curwin->w_cursor.lnum;
1385 to = VIsual.lnum;
1386 }
1387 else
1388 {
1389 from = VIsual.lnum;
1390 to = curwin->w_cursor.lnum;
1391 }
1392 /* redraw more when the cursor moved as well */
1393 if (wp->w_old_cursor_lnum < from)
1394 from = wp->w_old_cursor_lnum;
1395 if (wp->w_old_cursor_lnum > to)
1396 to = wp->w_old_cursor_lnum;
1397 if (wp->w_old_visual_lnum < from)
1398 from = wp->w_old_visual_lnum;
1399 if (wp->w_old_visual_lnum > to)
1400 to = wp->w_old_visual_lnum;
1401 }
1402 else
1403 {
1404 /*
1405 * Find the line numbers that need to be updated: The lines
1406 * between the old cursor position and the current cursor
1407 * position. Also check if the Visual position changed.
1408 */
1409 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum)
1410 {
1411 from = curwin->w_cursor.lnum;
1412 to = wp->w_old_cursor_lnum;
1413 }
1414 else
1415 {
1416 from = wp->w_old_cursor_lnum;
1417 to = curwin->w_cursor.lnum;
1418 if (from == 0) /* Visual mode just started */
1419 from = to;
1420 }
1421
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001422 if (VIsual.lnum != wp->w_old_visual_lnum
1423 || VIsual.col != wp->w_old_visual_col)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {
1425 if (wp->w_old_visual_lnum < from
1426 && wp->w_old_visual_lnum != 0)
1427 from = wp->w_old_visual_lnum;
1428 if (wp->w_old_visual_lnum > to)
1429 to = wp->w_old_visual_lnum;
1430 if (VIsual.lnum < from)
1431 from = VIsual.lnum;
1432 if (VIsual.lnum > to)
1433 to = VIsual.lnum;
1434 }
1435 }
1436
1437 /*
1438 * If in block mode and changed column or curwin->w_curswant:
1439 * update all lines.
1440 * First compute the actual start and end column.
1441 */
1442 if (VIsual_mode == Ctrl_V)
1443 {
1444 colnr_T fromc, toc;
1445
1446 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
1447 ++toc;
1448 if (curwin->w_curswant == MAXCOL)
1449 toc = MAXCOL;
1450
1451 if (fromc != wp->w_old_cursor_fcol
1452 || toc != wp->w_old_cursor_lcol)
1453 {
1454 if (from > VIsual.lnum)
1455 from = VIsual.lnum;
1456 if (to < VIsual.lnum)
1457 to = VIsual.lnum;
1458 }
1459 wp->w_old_cursor_fcol = fromc;
1460 wp->w_old_cursor_lcol = toc;
1461 }
1462 }
1463 else
1464 {
1465 /* Use the line numbers of the old Visual area. */
1466 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum)
1467 {
1468 from = wp->w_old_cursor_lnum;
1469 to = wp->w_old_visual_lnum;
1470 }
1471 else
1472 {
1473 from = wp->w_old_visual_lnum;
1474 to = wp->w_old_cursor_lnum;
1475 }
1476 }
1477
1478 /*
1479 * There is no need to update lines above the top of the window.
1480 */
1481 if (from < wp->w_topline)
1482 from = wp->w_topline;
1483
1484 /*
1485 * If we know the value of w_botline, use it to restrict the update to
1486 * the lines that are visible in the window.
1487 */
1488 if (wp->w_valid & VALID_BOTLINE)
1489 {
1490 if (from >= wp->w_botline)
1491 from = wp->w_botline - 1;
1492 if (to >= wp->w_botline)
1493 to = wp->w_botline - 1;
1494 }
1495
1496 /*
1497 * Find the minimal part to be updated.
1498 * Watch out for scrolling that made entries in w_lines[] invalid.
1499 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1500 * top_end; need to redraw from top_end to the "to" line.
1501 * A middle mouse click with a Visual selection may change the text
1502 * above the Visual area and reset wl_valid, do count these for
1503 * mid_end (in srow).
1504 */
1505 if (mid_start > 0)
1506 {
1507 lnum = wp->w_topline;
1508 idx = 0;
1509 srow = 0;
1510 if (scrolled_down)
1511 mid_start = top_end;
1512 else
1513 mid_start = 0;
1514 while (lnum < from && idx < wp->w_lines_valid) /* find start */
1515 {
1516 if (wp->w_lines[idx].wl_valid)
1517 mid_start += wp->w_lines[idx].wl_size;
1518 else if (!scrolled_down)
1519 srow += wp->w_lines[idx].wl_size;
1520 ++idx;
1521# ifdef FEAT_FOLDING
1522 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid)
1523 lnum = wp->w_lines[idx].wl_lnum;
1524 else
1525# endif
1526 ++lnum;
1527 }
1528 srow += mid_start;
1529 mid_end = wp->w_height;
1530 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */
1531 {
1532 if (wp->w_lines[idx].wl_valid
1533 && wp->w_lines[idx].wl_lnum >= to + 1)
1534 {
1535 /* Only update until first row of this line */
1536 mid_end = srow;
1537 break;
1538 }
1539 srow += wp->w_lines[idx].wl_size;
1540 }
1541 }
1542 }
1543
1544 if (VIsual_active && buf == curwin->w_buffer)
1545 {
1546 wp->w_old_visual_mode = VIsual_mode;
1547 wp->w_old_cursor_lnum = curwin->w_cursor.lnum;
1548 wp->w_old_visual_lnum = VIsual.lnum;
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001549 wp->w_old_visual_col = VIsual.col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 wp->w_old_curswant = curwin->w_curswant;
1551 }
1552 else
1553 {
1554 wp->w_old_visual_mode = 0;
1555 wp->w_old_cursor_lnum = 0;
1556 wp->w_old_visual_lnum = 0;
Bram Moolenaar6c131c42005-07-19 22:17:30 +00001557 wp->w_old_visual_col = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 }
1559#endif /* FEAT_VISUAL */
1560
1561#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1562 /* reset got_int, otherwise regexp won't work */
1563 save_got_int = got_int;
1564 got_int = 0;
1565#endif
1566#ifdef FEAT_FOLDING
1567 win_foldinfo.fi_level = 0;
1568#endif
1569
1570 /*
1571 * Update all the window rows.
1572 */
1573 idx = 0; /* first entry in w_lines[].wl_size */
1574 row = 0;
1575 srow = 0;
1576 lnum = wp->w_topline; /* first line shown in window */
1577 for (;;)
1578 {
1579 /* stop updating when reached the end of the window (check for _past_
1580 * the end of the window is at the end of the loop) */
1581 if (row == wp->w_height)
1582 {
1583 didline = TRUE;
1584 break;
1585 }
1586
1587 /* stop updating when hit the end of the file */
1588 if (lnum > buf->b_ml.ml_line_count)
1589 {
1590 eof = TRUE;
1591 break;
1592 }
1593
1594 /* Remember the starting row of the line that is going to be dealt
1595 * with. It is used further down when the line doesn't fit. */
1596 srow = row;
1597
1598 /*
1599 * Update a line when it is in an area that needs updating, when it
1600 * has changes or w_lines[idx] is invalid.
1601 * bot_start may be halfway a wrapped line after using
1602 * win_del_lines(), check if the current line includes it.
1603 * When syntax folding is being used, the saved syntax states will
1604 * already have been updated, we can't see where the syntax state is
1605 * the same again, just update until the end of the window.
1606 */
1607 if (row < top_end
1608 || (row >= mid_start && row < mid_end)
1609#ifdef FEAT_SEARCH_EXTRA
1610 || top_to_mod
1611#endif
1612 || idx >= wp->w_lines_valid
1613 || (row + wp->w_lines[idx].wl_size > bot_start)
1614 || (mod_top != 0
1615 && (lnum == mod_top
1616 || (lnum >= mod_top
1617 && (lnum < mod_bot
1618#ifdef FEAT_SYN_HL
1619 || did_update == DID_FOLD
1620 || (did_update == DID_LINE
Bram Moolenaar860cae12010-06-05 23:22:07 +02001621 && syntax_present(wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 && (
1623# ifdef FEAT_FOLDING
1624 (foldmethodIsSyntax(wp)
1625 && hasAnyFolding(wp)) ||
1626# endif
1627 syntax_check_changed(lnum)))
1628#endif
1629 )))))
1630 {
1631#ifdef FEAT_SEARCH_EXTRA
1632 if (lnum == mod_top)
1633 top_to_mod = FALSE;
1634#endif
1635
1636 /*
1637 * When at start of changed lines: May scroll following lines
1638 * up or down to minimize redrawing.
1639 * Don't do this when the change continues until the end.
Bram Moolenaar76b9b362012-02-04 23:35:00 +01001640 * Don't scroll when dollar_vcol >= 0, keep the "$".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 */
1642 if (lnum == mod_top
1643 && mod_bot != MAXLNUM
Bram Moolenaar76b9b362012-02-04 23:35:00 +01001644 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645 {
1646 int old_rows = 0;
1647 int new_rows = 0;
1648 int xtra_rows;
1649 linenr_T l;
1650
1651 /* Count the old number of window rows, using w_lines[], which
1652 * should still contain the sizes for the lines as they are
1653 * currently displayed. */
1654 for (i = idx; i < wp->w_lines_valid; ++i)
1655 {
1656 /* Only valid lines have a meaningful wl_lnum. Invalid
1657 * lines are part of the changed area. */
1658 if (wp->w_lines[i].wl_valid
1659 && wp->w_lines[i].wl_lnum == mod_bot)
1660 break;
1661 old_rows += wp->w_lines[i].wl_size;
1662#ifdef FEAT_FOLDING
1663 if (wp->w_lines[i].wl_valid
1664 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot)
1665 {
1666 /* Must have found the last valid entry above mod_bot.
1667 * Add following invalid entries. */
1668 ++i;
1669 while (i < wp->w_lines_valid
1670 && !wp->w_lines[i].wl_valid)
1671 old_rows += wp->w_lines[i++].wl_size;
1672 break;
1673 }
1674#endif
1675 }
1676
1677 if (i >= wp->w_lines_valid)
1678 {
1679 /* We can't find a valid line below the changed lines,
1680 * need to redraw until the end of the window.
1681 * Inserting/deleting lines has no use. */
1682 bot_start = 0;
1683 }
1684 else
1685 {
1686 /* Able to count old number of rows: Count new window
1687 * rows, and may insert/delete lines */
1688 j = idx;
1689 for (l = lnum; l < mod_bot; ++l)
1690 {
1691#ifdef FEAT_FOLDING
1692 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL))
1693 ++new_rows;
1694 else
1695#endif
1696#ifdef FEAT_DIFF
1697 if (l == wp->w_topline)
1698 new_rows += plines_win_nofill(wp, l, TRUE)
1699 + wp->w_topfill;
1700 else
1701#endif
1702 new_rows += plines_win(wp, l, TRUE);
1703 ++j;
1704 if (new_rows > wp->w_height - row - 2)
1705 {
1706 /* it's getting too much, must redraw the rest */
1707 new_rows = 9999;
1708 break;
1709 }
1710 }
1711 xtra_rows = new_rows - old_rows;
1712 if (xtra_rows < 0)
1713 {
1714 /* May scroll text up. If there is not enough
1715 * remaining text or scrolling fails, must redraw the
1716 * rest. If scrolling works, must redraw the text
1717 * below the scrolled text. */
1718 if (row - xtra_rows >= wp->w_height - 2)
1719 mod_bot = MAXLNUM;
1720 else
1721 {
1722 check_for_delay(FALSE);
1723 if (win_del_lines(wp, row,
1724 -xtra_rows, FALSE, FALSE) == FAIL)
1725 mod_bot = MAXLNUM;
1726 else
1727 bot_start = wp->w_height + xtra_rows;
1728 }
1729 }
1730 else if (xtra_rows > 0)
1731 {
1732 /* May scroll text down. If there is not enough
1733 * remaining text of scrolling fails, must redraw the
1734 * rest. */
1735 if (row + xtra_rows >= wp->w_height - 2)
1736 mod_bot = MAXLNUM;
1737 else
1738 {
1739 check_for_delay(FALSE);
1740 if (win_ins_lines(wp, row + old_rows,
1741 xtra_rows, FALSE, FALSE) == FAIL)
1742 mod_bot = MAXLNUM;
1743 else if (top_end > row + old_rows)
1744 /* Scrolled the part at the top that requires
1745 * updating down. */
1746 top_end += xtra_rows;
1747 }
1748 }
1749
1750 /* When not updating the rest, may need to move w_lines[]
1751 * entries. */
1752 if (mod_bot != MAXLNUM && i != j)
1753 {
1754 if (j < i)
1755 {
1756 int x = row + new_rows;
1757
1758 /* move entries in w_lines[] upwards */
1759 for (;;)
1760 {
1761 /* stop at last valid entry in w_lines[] */
1762 if (i >= wp->w_lines_valid)
1763 {
1764 wp->w_lines_valid = j;
1765 break;
1766 }
1767 wp->w_lines[j] = wp->w_lines[i];
1768 /* stop at a line that won't fit */
1769 if (x + (int)wp->w_lines[j].wl_size
1770 > wp->w_height)
1771 {
1772 wp->w_lines_valid = j + 1;
1773 break;
1774 }
1775 x += wp->w_lines[j++].wl_size;
1776 ++i;
1777 }
1778 if (bot_start > x)
1779 bot_start = x;
1780 }
1781 else /* j > i */
1782 {
1783 /* move entries in w_lines[] downwards */
1784 j -= i;
1785 wp->w_lines_valid += j;
1786 if (wp->w_lines_valid > wp->w_height)
1787 wp->w_lines_valid = wp->w_height;
1788 for (i = wp->w_lines_valid; i - j >= idx; --i)
1789 wp->w_lines[i] = wp->w_lines[i - j];
1790
1791 /* The w_lines[] entries for inserted lines are
1792 * now invalid, but wl_size may be used above.
1793 * Reset to zero. */
1794 while (i >= idx)
1795 {
1796 wp->w_lines[i].wl_size = 0;
1797 wp->w_lines[i--].wl_valid = FALSE;
1798 }
1799 }
1800 }
1801 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 }
1803
1804#ifdef FEAT_FOLDING
1805 /*
1806 * When lines are folded, display one line for all of them.
1807 * Otherwise, display normally (can be several display lines when
1808 * 'wrap' is on).
1809 */
1810 fold_count = foldedCount(wp, lnum, &win_foldinfo);
1811 if (fold_count != 0)
1812 {
1813 fold_line(wp, fold_count, &win_foldinfo, lnum, row);
1814 ++row;
1815 --fold_count;
1816 wp->w_lines[idx].wl_folded = TRUE;
1817 wp->w_lines[idx].wl_lastlnum = lnum + fold_count;
1818# ifdef FEAT_SYN_HL
1819 did_update = DID_FOLD;
1820# endif
1821 }
1822 else
1823#endif
1824 if (idx < wp->w_lines_valid
1825 && wp->w_lines[idx].wl_valid
1826 && wp->w_lines[idx].wl_lnum == lnum
1827 && lnum > wp->w_topline
1828 && !(dy_flags & DY_LASTLINE)
1829 && srow + wp->w_lines[idx].wl_size > wp->w_height
1830#ifdef FEAT_DIFF
1831 && diff_check_fill(wp, lnum) == 0
1832#endif
1833 )
1834 {
1835 /* This line is not going to fit. Don't draw anything here,
1836 * will draw "@ " lines below. */
1837 row = wp->w_height + 1;
1838 }
1839 else
1840 {
1841#ifdef FEAT_SEARCH_EXTRA
1842 prepare_search_hl(wp, lnum);
1843#endif
1844#ifdef FEAT_SYN_HL
1845 /* Let the syntax stuff know we skipped a few lines. */
1846 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum
Bram Moolenaar860cae12010-06-05 23:22:07 +02001847 && syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 syntax_end_parsing(syntax_last_parsed + 1);
1849#endif
1850
1851 /*
1852 * Display one line.
1853 */
Bram Moolenaar4770d092006-01-12 23:22:24 +00001854 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855
1856#ifdef FEAT_FOLDING
1857 wp->w_lines[idx].wl_folded = FALSE;
1858 wp->w_lines[idx].wl_lastlnum = lnum;
1859#endif
1860#ifdef FEAT_SYN_HL
1861 did_update = DID_LINE;
1862 syntax_last_parsed = lnum;
1863#endif
1864 }
1865
1866 wp->w_lines[idx].wl_lnum = lnum;
1867 wp->w_lines[idx].wl_valid = TRUE;
1868 if (row > wp->w_height) /* past end of screen */
1869 {
1870 /* we may need the size of that too long line later on */
Bram Moolenaar76b9b362012-02-04 23:35:00 +01001871 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE);
1873 ++idx;
1874 break;
1875 }
Bram Moolenaar76b9b362012-02-04 23:35:00 +01001876 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 wp->w_lines[idx].wl_size = row - srow;
1878 ++idx;
1879#ifdef FEAT_FOLDING
1880 lnum += fold_count + 1;
1881#else
1882 ++lnum;
1883#endif
1884 }
1885 else
1886 {
1887 /* This line does not need updating, advance to the next one */
1888 row += wp->w_lines[idx++].wl_size;
1889 if (row > wp->w_height) /* past end of screen */
1890 break;
1891#ifdef FEAT_FOLDING
1892 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1;
1893#else
1894 ++lnum;
1895#endif
1896#ifdef FEAT_SYN_HL
1897 did_update = DID_NONE;
1898#endif
1899 }
1900
1901 if (lnum > buf->b_ml.ml_line_count)
1902 {
1903 eof = TRUE;
1904 break;
1905 }
1906 }
1907 /*
1908 * End of loop over all window lines.
1909 */
1910
1911
1912 if (idx > wp->w_lines_valid)
1913 wp->w_lines_valid = idx;
1914
1915#ifdef FEAT_SYN_HL
1916 /*
1917 * Let the syntax stuff know we stop parsing here.
1918 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02001919 if (syntax_last_parsed != 0 && syntax_present(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 syntax_end_parsing(syntax_last_parsed + 1);
1921#endif
1922
1923 /*
1924 * If we didn't hit the end of the file, and we didn't finish the last
1925 * line we were working on, then the line didn't fit.
1926 */
1927 wp->w_empty_rows = 0;
1928#ifdef FEAT_DIFF
1929 wp->w_filler_rows = 0;
1930#endif
1931 if (!eof && !didline)
1932 {
1933 if (lnum == wp->w_topline)
1934 {
1935 /*
1936 * Single line that does not fit!
1937 * Don't overwrite it, it can be edited.
1938 */
1939 wp->w_botline = lnum + 1;
1940 }
1941#ifdef FEAT_DIFF
1942 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow)
1943 {
1944 /* Window ends in filler lines. */
1945 wp->w_botline = lnum;
1946 wp->w_filler_rows = wp->w_height - srow;
1947 }
1948#endif
1949 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */
1950 {
1951 /*
1952 * Last line isn't finished: Display "@@@" at the end.
1953 */
1954 screen_fill(W_WINROW(wp) + wp->w_height - 1,
1955 W_WINROW(wp) + wp->w_height,
1956 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp),
1957 '@', '@', hl_attr(HLF_AT));
1958 set_empty_rows(wp, srow);
1959 wp->w_botline = lnum;
1960 }
1961 else
1962 {
1963 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT);
1964 wp->w_botline = lnum;
1965 }
1966 }
1967 else
1968 {
1969#ifdef FEAT_VERTSPLIT
1970 draw_vsep_win(wp, row);
1971#endif
1972 if (eof) /* we hit the end of the file */
1973 {
1974 wp->w_botline = buf->b_ml.ml_line_count + 1;
1975#ifdef FEAT_DIFF
1976 j = diff_check_fill(wp, wp->w_botline);
1977 if (j > 0 && !wp->w_botfill)
1978 {
1979 /*
1980 * Display filler lines at the end of the file
1981 */
1982 if (char2cells(fill_diff) > 1)
1983 i = '-';
1984 else
1985 i = fill_diff;
1986 if (row + j > wp->w_height)
1987 j = wp->w_height - row;
1988 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED);
1989 row += j;
1990 }
1991#endif
1992 }
Bram Moolenaar76b9b362012-02-04 23:35:00 +01001993 else if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 wp->w_botline = lnum;
1995
1996 /* make sure the rest of the screen is blank */
1997 /* put '~'s on rows that aren't part of the file. */
1998 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT);
1999 }
2000
2001 /* Reset the type of redrawing required, the window has been updated. */
2002 wp->w_redr_type = 0;
2003#ifdef FEAT_DIFF
2004 wp->w_old_topfill = wp->w_topfill;
2005 wp->w_old_botfill = wp->w_botfill;
2006#endif
2007
Bram Moolenaar76b9b362012-02-04 23:35:00 +01002008 if (dollar_vcol == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {
2010 /*
2011 * There is a trick with w_botline. If we invalidate it on each
2012 * change that might modify it, this will cause a lot of expensive
2013 * calls to plines() in update_topline() each time. Therefore the
2014 * value of w_botline is often approximated, and this value is used to
2015 * compute the value of w_topline. If the value of w_botline was
2016 * wrong, check that the value of w_topline is correct (cursor is on
2017 * the visible part of the text). If it's not, we need to redraw
2018 * again. Mostly this just means scrolling up a few lines, so it
2019 * doesn't look too bad. Only do this for the current window (where
2020 * changes are relevant).
2021 */
2022 wp->w_valid |= VALID_BOTLINE;
2023 if (wp == curwin && wp->w_botline != old_botline && !recursive)
2024 {
2025 recursive = TRUE;
2026 curwin->w_valid &= ~VALID_TOPLINE;
2027 update_topline(); /* may invalidate w_botline again */
2028 if (must_redraw != 0)
2029 {
2030 /* Don't update for changes in buffer again. */
2031 i = curbuf->b_mod_set;
2032 curbuf->b_mod_set = FALSE;
2033 win_update(curwin);
2034 must_redraw = 0;
2035 curbuf->b_mod_set = i;
2036 }
2037 recursive = FALSE;
2038 }
2039 }
2040
2041#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
2042 /* restore got_int, unless CTRL-C was hit while redrawing */
2043 if (!got_int)
2044 got_int = save_got_int;
2045#endif
2046}
2047
2048#ifdef FEAT_SIGNS
2049static int draw_signcolumn __ARGS((win_T *wp));
2050
2051/*
2052 * Return TRUE when window "wp" has a column to draw signs in.
2053 */
2054 static int
2055draw_signcolumn(wp)
2056 win_T *wp;
2057{
2058 return (wp->w_buffer->b_signlist != NULL
2059# ifdef FEAT_NETBEANS_INTG
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002060 || netbeans_active()
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061# endif
2062 );
2063}
2064#endif
2065
2066/*
2067 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
2068 * as the filler character.
2069 */
2070 static void
2071win_draw_end(wp, c1, c2, row, endrow, hl)
2072 win_T *wp;
2073 int c1;
2074 int c2;
2075 int row;
2076 int endrow;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00002077 hlf_T hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078{
2079#if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
2080 int n = 0;
2081# define FDC_OFF n
2082#else
2083# define FDC_OFF 0
2084#endif
2085
2086#ifdef FEAT_RIGHTLEFT
2087 if (wp->w_p_rl)
2088 {
2089 /* No check for cmdline window: should never be right-left. */
2090# ifdef FEAT_FOLDING
2091 n = wp->w_p_fdc;
2092
2093 if (n > 0)
2094 {
2095 /* draw the fold column at the right */
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00002096 if (n > W_WIDTH(wp))
2097 n = W_WIDTH(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2099 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp),
2100 ' ', ' ', hl_attr(HLF_FC));
2101 }
2102# endif
2103# ifdef FEAT_SIGNS
2104 if (draw_signcolumn(wp))
2105 {
2106 int nn = n + 2;
2107
2108 /* draw the sign column left of the fold column */
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00002109 if (nn > W_WIDTH(wp))
2110 nn = W_WIDTH(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2112 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n,
2113 ' ', ' ', hl_attr(HLF_SC));
2114 n = nn;
2115 }
2116# endif
2117 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2118 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF,
2119 c2, c2, hl_attr(hl));
2120 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2121 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF,
2122 c1, c2, hl_attr(hl));
2123 }
2124 else
2125#endif
2126 {
2127#ifdef FEAT_CMDWIN
2128 if (cmdwin_type != 0 && wp == curwin)
2129 {
2130 /* draw the cmdline character in the leftmost column */
2131 n = 1;
2132 if (n > wp->w_width)
2133 n = wp->w_width;
2134 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2135 W_WINCOL(wp), (int)W_WINCOL(wp) + n,
2136 cmdwin_type, ' ', hl_attr(HLF_AT));
2137 }
2138#endif
2139#ifdef FEAT_FOLDING
2140 if (wp->w_p_fdc > 0)
2141 {
2142 int nn = n + wp->w_p_fdc;
2143
2144 /* draw the fold column at the left */
2145 if (nn > W_WIDTH(wp))
2146 nn = W_WIDTH(wp);
2147 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2148 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn,
2149 ' ', ' ', hl_attr(HLF_FC));
2150 n = nn;
2151 }
2152#endif
2153#ifdef FEAT_SIGNS
2154 if (draw_signcolumn(wp))
2155 {
2156 int nn = n + 2;
2157
2158 /* draw the sign column after the fold column */
2159 if (nn > W_WIDTH(wp))
2160 nn = W_WIDTH(wp);
2161 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2162 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn,
2163 ' ', ' ', hl_attr(HLF_SC));
2164 n = nn;
2165 }
2166#endif
2167 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
2168 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp),
2169 c1, c2, hl_attr(hl));
2170 }
2171 set_empty_rows(wp, row);
2172}
2173
Bram Moolenaar1a384422010-07-14 19:53:30 +02002174#ifdef FEAT_SYN_HL
2175static int advance_color_col __ARGS((int vcol, int **color_cols));
2176
2177/*
2178 * Advance **color_cols and return TRUE when there are columns to draw.
2179 */
2180 static int
2181advance_color_col(vcol, color_cols)
2182 int vcol;
2183 int **color_cols;
2184{
2185 while (**color_cols >= 0 && vcol > **color_cols)
2186 ++*color_cols;
2187 return (**color_cols >= 0);
2188}
2189#endif
2190
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191#ifdef FEAT_FOLDING
2192/*
2193 * Display one folded line.
2194 */
2195 static void
2196fold_line(wp, fold_count, foldinfo, lnum, row)
2197 win_T *wp;
2198 long fold_count;
2199 foldinfo_T *foldinfo;
2200 linenr_T lnum;
2201 int row;
2202{
2203 char_u buf[51];
2204 pos_T *top, *bot;
2205 linenr_T lnume = lnum + fold_count - 1;
2206 int len;
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002207 char_u *text;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 int fdc;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002209 int col;
2210 int txtcol;
2211 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002212 int ri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002213
2214 /* Build the fold line:
2215 * 1. Add the cmdwin_type for the command-line window
2216 * 2. Add the 'foldcolumn'
Bram Moolenaar64486672010-05-16 15:46:46 +02002217 * 3. Add the 'number' or 'relativenumber' column
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 * 4. Compose the text
2219 * 5. Add the text
2220 * 6. set highlighting for the Visual area an other text
2221 */
2222 col = 0;
2223
2224 /*
2225 * 1. Add the cmdwin_type for the command-line window
2226 * Ignores 'rightleft', this window is never right-left.
2227 */
2228#ifdef FEAT_CMDWIN
2229 if (cmdwin_type != 0 && wp == curwin)
2230 {
2231 ScreenLines[off] = cmdwin_type;
2232 ScreenAttrs[off] = hl_attr(HLF_AT);
2233#ifdef FEAT_MBYTE
2234 if (enc_utf8)
2235 ScreenLinesUC[off] = 0;
2236#endif
2237 ++col;
2238 }
2239#endif
2240
2241 /*
2242 * 2. Add the 'foldcolumn'
2243 */
2244 fdc = wp->w_p_fdc;
2245 if (fdc > W_WIDTH(wp) - col)
2246 fdc = W_WIDTH(wp) - col;
2247 if (fdc > 0)
2248 {
2249 fill_foldcolumn(buf, wp, TRUE, lnum);
2250#ifdef FEAT_RIGHTLEFT
2251 if (wp->w_p_rl)
2252 {
2253 int i;
2254
2255 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc,
2256 hl_attr(HLF_FC));
2257 /* reverse the fold column */
2258 for (i = 0; i < fdc; ++i)
2259 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i];
2260 }
2261 else
2262#endif
2263 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC));
2264 col += fdc;
2265 }
2266
2267#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002268# define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2269 for (ri = 0; ri < l; ++ri) \
2270 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2271 else \
2272 for (ri = 0; ri < l; ++ri) \
2273 ScreenAttrs[off + (p) + ri] = v
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274#else
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002275# define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2276 ScreenAttrs[off + (p) + ri] = v
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277#endif
2278
Bram Moolenaar64486672010-05-16 15:46:46 +02002279 /* Set all attributes of the 'number' or 'relativenumber' column and the
2280 * text */
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002281 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282
2283#ifdef FEAT_SIGNS
2284 /* If signs are being displayed, add two spaces. */
2285 if (draw_signcolumn(wp))
2286 {
2287 len = W_WIDTH(wp) - col;
2288 if (len > 0)
2289 {
2290 if (len > 2)
2291 len = 2;
2292# ifdef FEAT_RIGHTLEFT
2293 if (wp->w_p_rl)
2294 /* the line number isn't reversed */
2295 copy_text_attr(off + W_WIDTH(wp) - len - col,
2296 (char_u *)" ", len, hl_attr(HLF_FL));
2297 else
2298# endif
2299 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL));
2300 col += len;
2301 }
2302 }
2303#endif
2304
2305 /*
Bram Moolenaar64486672010-05-16 15:46:46 +02002306 * 3. Add the 'number' or 'relativenumber' column
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 */
Bram Moolenaar64486672010-05-16 15:46:46 +02002308 if (wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {
2310 len = W_WIDTH(wp) - col;
2311 if (len > 0)
2312 {
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002313 int w = number_width(wp);
Bram Moolenaar64486672010-05-16 15:46:46 +02002314 long num;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002315
2316 if (len > w + 1)
2317 len = w + 1;
Bram Moolenaar64486672010-05-16 15:46:46 +02002318
2319 if (wp->w_p_nu)
2320 /* 'number' */
2321 num = (long)lnum;
2322 else
2323 /* 'relativenumber', don't use negative numbers */
Bram Moolenaar7eb46522010-12-30 14:57:08 +01002324 num = labs((long)get_cursor_rel_lnum(wp, lnum));
Bram Moolenaar64486672010-05-16 15:46:46 +02002325
2326 sprintf((char *)buf, "%*ld ", w, num);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327#ifdef FEAT_RIGHTLEFT
2328 if (wp->w_p_rl)
2329 /* the line number isn't reversed */
2330 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len,
2331 hl_attr(HLF_FL));
2332 else
2333#endif
2334 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL));
2335 col += len;
2336 }
2337 }
2338
2339 /*
2340 * 4. Compose the folded-line string with 'foldtext', if set.
2341 */
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002342 text = get_foldtext(wp, lnum, lnume, foldinfo, buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343
2344 txtcol = col; /* remember where text starts */
2345
2346 /*
2347 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2348 * Right-left text is put in columns 0 - number-col, normal text is put
2349 * in columns number-col - window-width.
2350 */
2351#ifdef FEAT_MBYTE
2352 if (has_mbyte)
2353 {
2354 int cells;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002355 int u8c, u8cc[MAX_MCO];
2356 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 int idx;
2358 int c_len;
Bram Moolenaar009b2592004-10-24 19:18:58 +00002359 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360# ifdef FEAT_ARABIC
2361 int prev_c = 0; /* previous Arabic character */
2362 int prev_c1 = 0; /* first composing char for prev_c */
2363# endif
2364
2365# ifdef FEAT_RIGHTLEFT
2366 if (wp->w_p_rl)
2367 idx = off;
2368 else
2369# endif
2370 idx = off + col;
2371
2372 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2373 for (p = text; *p != NUL; )
2374 {
2375 cells = (*mb_ptr2cells)(p);
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00002376 c_len = (*mb_ptr2len)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 if (col + cells > W_WIDTH(wp)
2378# ifdef FEAT_RIGHTLEFT
2379 - (wp->w_p_rl ? col : 0)
2380# endif
2381 )
2382 break;
2383 ScreenLines[idx] = *p;
2384 if (enc_utf8)
2385 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002386 u8c = utfc_ptr2char(p, u8cc);
2387 if (*p < 0x80 && u8cc[0] == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {
2389 ScreenLinesUC[idx] = 0;
2390#ifdef FEAT_ARABIC
2391 prev_c = u8c;
2392#endif
2393 }
2394 else
2395 {
2396#ifdef FEAT_ARABIC
2397 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
2398 {
2399 /* Do Arabic shaping. */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002400 int pc, pc1, nc;
2401 int pcc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 int firstbyte = *p;
2403
2404 /* The idea of what is the previous and next
2405 * character depends on 'rightleft'. */
2406 if (wp->w_p_rl)
2407 {
2408 pc = prev_c;
2409 pc1 = prev_c1;
2410 nc = utf_ptr2char(p + c_len);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002411 prev_c1 = u8cc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 }
2413 else
2414 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002415 pc = utfc_ptr2char(p + c_len, pcc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 nc = prev_c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002417 pc1 = pcc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 }
2419 prev_c = u8c;
2420
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002421 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0],
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 pc, pc1, nc);
2423 ScreenLines[idx] = firstbyte;
2424 }
2425 else
2426 prev_c = u8c;
2427#endif
2428 /* Non-BMP character: display as ? or fullwidth ?. */
Bram Moolenaar11936362007-09-17 20:39:42 +00002429#ifdef UNICODE16
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 if (u8c >= 0x10000)
2431 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?';
2432 else
Bram Moolenaar11936362007-09-17 20:39:42 +00002433#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 ScreenLinesUC[idx] = u8c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002435 for (i = 0; i < Screen_mco; ++i)
2436 {
2437 ScreenLinesC[i][idx] = u8cc[i];
2438 if (u8cc[i] == 0)
2439 break;
2440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 }
2442 if (cells > 1)
2443 ScreenLines[idx + 1] = 0;
2444 }
Bram Moolenaar990bb662010-02-03 15:48:04 +01002445 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e)
2446 /* double-byte single width character */
2447 ScreenLines2[idx] = p[1];
2448 else if (cells > 1)
2449 /* double-width character */
2450 ScreenLines[idx + 1] = p[1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 col += cells;
2452 idx += cells;
2453 p += c_len;
2454 }
2455 }
2456 else
2457#endif
2458 {
2459 len = (int)STRLEN(text);
2460 if (len > W_WIDTH(wp) - col)
2461 len = W_WIDTH(wp) - col;
2462 if (len > 0)
2463 {
2464#ifdef FEAT_RIGHTLEFT
2465 if (wp->w_p_rl)
2466 STRNCPY(current_ScreenLine, text, len);
2467 else
2468#endif
2469 STRNCPY(current_ScreenLine + col, text, len);
2470 col += len;
2471 }
2472 }
2473
2474 /* Fill the rest of the line with the fold filler */
2475#ifdef FEAT_RIGHTLEFT
2476 if (wp->w_p_rl)
2477 col -= txtcol;
2478#endif
2479 while (col < W_WIDTH(wp)
2480#ifdef FEAT_RIGHTLEFT
2481 - (wp->w_p_rl ? txtcol : 0)
2482#endif
2483 )
2484 {
2485#ifdef FEAT_MBYTE
2486 if (enc_utf8)
2487 {
2488 if (fill_fold >= 0x80)
2489 {
2490 ScreenLinesUC[off + col] = fill_fold;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002491 ScreenLinesC[0][off + col] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 }
2493 else
2494 ScreenLinesUC[off + col] = 0;
2495 }
2496#endif
2497 ScreenLines[off + col++] = fill_fold;
2498 }
2499
2500 if (text != buf)
2501 vim_free(text);
2502
2503 /*
2504 * 6. set highlighting for the Visual area an other text.
2505 * If all folded lines are in the Visual area, highlight the line.
2506 */
2507#ifdef FEAT_VISUAL
2508 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
2509 {
2510 if (ltoreq(curwin->w_cursor, VIsual))
2511 {
2512 /* Visual is after curwin->w_cursor */
2513 top = &curwin->w_cursor;
2514 bot = &VIsual;
2515 }
2516 else
2517 {
2518 /* Visual is before curwin->w_cursor */
2519 top = &VIsual;
2520 bot = &curwin->w_cursor;
2521 }
2522 if (lnum >= top->lnum
2523 && lnume <= bot->lnum
2524 && (VIsual_mode != 'v'
2525 || ((lnum > top->lnum
2526 || (lnum == top->lnum
2527 && top->col == 0))
2528 && (lnume < bot->lnum
2529 || (lnume == bot->lnum
2530 && (bot->col - (*p_sel == 'e'))
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE)))))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {
2533 if (VIsual_mode == Ctrl_V)
2534 {
2535 /* Visual block mode: highlight the chars part of the block */
2536 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp))
2537 {
Bram Moolenaar6c167c62011-09-02 14:07:36 +02002538 if (wp->w_old_cursor_lcol != MAXCOL
2539 && wp->w_old_cursor_lcol + txtcol
2540 < (colnr_T)W_WIDTH(wp))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 len = wp->w_old_cursor_lcol;
2542 else
2543 len = W_WIDTH(wp) - txtcol;
2544 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V),
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002545 len - (int)wp->w_old_cursor_fcol);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 }
2547 }
2548 else
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002549 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 /* Set all attributes of the text */
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002551 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol);
2552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 }
2554 }
2555#endif
2556
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002557#ifdef FEAT_SYN_HL
2558 /* Show 'cursorcolumn' in the fold line. */
Bram Moolenaar85595c52008-10-02 16:04:05 +00002559 if (wp->w_p_cuc)
2560 {
2561 txtcol += wp->w_virtcol;
2562 if (wp->w_p_wrap)
2563 txtcol -= wp->w_skipcol;
2564 else
2565 txtcol -= wp->w_leftcol;
2566 if (txtcol >= 0 && txtcol < W_WIDTH(wp))
2567 ScreenAttrs[off + txtcol] = hl_combine_attr(
2568 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC));
2569 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571
2572 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp),
2573 (int)W_WIDTH(wp), FALSE);
2574
2575 /*
2576 * Update w_cline_height and w_cline_folded if the cursor line was
2577 * updated (saves a call to plines() later).
2578 */
2579 if (wp == curwin
2580 && lnum <= curwin->w_cursor.lnum
2581 && lnume >= curwin->w_cursor.lnum)
2582 {
2583 curwin->w_cline_row = row;
2584 curwin->w_cline_height = 1;
2585 curwin->w_cline_folded = TRUE;
2586 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2587 }
2588}
2589
2590/*
2591 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2592 */
2593 static void
2594copy_text_attr(off, buf, len, attr)
2595 int off;
2596 char_u *buf;
2597 int len;
2598 int attr;
2599{
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002600 int i;
2601
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 mch_memmove(ScreenLines + off, buf, (size_t)len);
2603# ifdef FEAT_MBYTE
2604 if (enc_utf8)
2605 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len);
2606# endif
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00002607 for (i = 0; i < len; ++i)
2608 ScreenAttrs[off + i] = attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609}
2610
2611/*
2612 * Fill the foldcolumn at "p" for window "wp".
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00002613 * Only to be called when 'foldcolumn' > 0.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 */
2615 static void
2616fill_foldcolumn(p, wp, closed, lnum)
2617 char_u *p;
2618 win_T *wp;
2619 int closed; /* TRUE of FALSE */
2620 linenr_T lnum; /* current line number */
2621{
2622 int i = 0;
2623 int level;
2624 int first_level;
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002625 int empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626
2627 /* Init to all spaces. */
2628 copy_spaces(p, (size_t)wp->w_p_fdc);
2629
2630 level = win_foldinfo.fi_level;
2631 if (level > 0)
2632 {
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002633 /* If there is only one column put more info in it. */
2634 empty = (wp->w_p_fdc == 1) ? 0 : 1;
2635
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 /* If the column is too narrow, we start at the lowest level that
2637 * fits and use numbers to indicated the depth. */
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002638 first_level = level - wp->w_p_fdc - closed + 1 + empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 if (first_level < 1)
2640 first_level = 1;
2641
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002642 for (i = 0; i + empty < wp->w_p_fdc; ++i)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {
2644 if (win_foldinfo.fi_lnum == lnum
2645 && first_level + i >= win_foldinfo.fi_low_level)
2646 p[i] = '-';
2647 else if (first_level == 1)
2648 p[i] = '|';
2649 else if (first_level + i <= 9)
2650 p[i] = '0' + first_level + i;
2651 else
2652 p[i] = '>';
2653 if (first_level + i == level)
2654 break;
2655 }
2656 }
2657 if (closed)
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00002658 p[i >= wp->w_p_fdc ? i - 1 : i] = '+';
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659}
2660#endif /* FEAT_FOLDING */
2661
2662/*
2663 * Display line "lnum" of window 'wp' on the screen.
2664 * Start at row "startrow", stop when "endrow" is reached.
2665 * wp->w_virtcol needs to be valid.
2666 *
2667 * Return the number of last row the line occupies.
2668 */
2669 static int
Bram Moolenaar4770d092006-01-12 23:22:24 +00002670win_line(wp, lnum, startrow, endrow, nochange)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 win_T *wp;
2672 linenr_T lnum;
2673 int startrow;
2674 int endrow;
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 int nochange UNUSED; /* not updating for changed text */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676{
2677 int col; /* visual column on screen */
2678 unsigned off; /* offset in ScreenLines/ScreenAttrs */
2679 int c = 0; /* init for GCC */
2680 long vcol = 0; /* virtual column (for tabs) */
2681 long vcol_prev = -1; /* "vcol" of previous character */
2682 char_u *line; /* current line */
2683 char_u *ptr; /* current position in "line" */
2684 int row; /* row in the window, excl w_winrow */
2685 int screen_row; /* row on the screen, incl w_winrow */
2686
2687 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */
2688 int n_extra = 0; /* number of extra chars */
Bram Moolenaara064ac82007-08-05 18:10:54 +00002689 char_u *p_extra = NULL; /* string of extra chars, plus NUL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 int c_extra = NUL; /* extra chars, all the same */
2691 int extra_attr = 0; /* attributes when n_extra != 0 */
2692 static char_u *at_end_str = (char_u *)""; /* used for p_extra when
2693 displaying lcs_eol at end-of-line */
2694 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */
2695 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */
2696
2697 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2698 int saved_n_extra = 0;
2699 char_u *saved_p_extra = NULL;
2700 int saved_c_extra = 0;
2701 int saved_char_attr = 0;
2702
2703 int n_attr = 0; /* chars with special attr */
2704 int saved_attr2 = 0; /* char_attr saved for n_attr */
2705 int n_attr3 = 0; /* chars with overruling special attr */
2706 int saved_attr3 = 0; /* char_attr saved for n_attr3 */
2707
2708 int n_skip = 0; /* nr of chars to skip for 'nowrap' */
2709
2710 int fromcol, tocol; /* start/end of inverting */
2711 int fromcol_prev = -2; /* start of inverting after cursor */
2712 int noinvcur = FALSE; /* don't invert the cursor */
2713#ifdef FEAT_VISUAL
2714 pos_T *top, *bot;
Bram Moolenaar54ef7112009-02-21 20:11:41 +00002715 int lnum_in_visual_area = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716#endif
2717 pos_T pos;
2718 long v;
2719
2720 int char_attr = 0; /* attributes for next character */
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00002721 int attr_pri = FALSE; /* char_attr has priority */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 int area_highlighting = FALSE; /* Visual or incsearch highlighting
2723 in this line */
2724 int attr = 0; /* attributes for area highlighting */
2725 int area_attr = 0; /* attributes desired by highlighting */
2726 int search_attr = 0; /* attributes desired by 'hlsearch' */
2727#ifdef FEAT_SYN_HL
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002728 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 int syntax_attr = 0; /* attributes desired by syntax */
2730 int has_syntax = FALSE; /* this buffer has syntax highl. */
2731 int save_did_emsg;
Bram Moolenaara443af82007-11-08 13:51:42 +00002732 int eol_hl_off = 0; /* 1 if highlighted char after EOL */
Bram Moolenaar1a384422010-07-14 19:53:30 +02002733 int draw_color_col = FALSE; /* highlight colorcolumn */
2734 int *color_cols = NULL; /* pointer to according columns array */
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002735#endif
2736#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002737 int has_spell = FALSE; /* this buffer has spell checking */
Bram Moolenaar30abd282005-06-22 22:35:10 +00002738# define SPWORDLEN 150
2739 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */
Bram Moolenaar3b506942005-06-23 22:36:45 +00002740 int nextlinecol = 0; /* column where nextline[] starts */
2741 int nextline_idx = 0; /* index in nextline[] where next line
Bram Moolenaar30abd282005-06-22 22:35:10 +00002742 starts */
Bram Moolenaar217ad922005-03-20 22:37:15 +00002743 int spell_attr = 0; /* attributes desired by spelling */
2744 int word_end = 0; /* last byte with same spell_attr */
Bram Moolenaard042c562005-06-30 22:04:15 +00002745 static linenr_T checked_lnum = 0; /* line number for "checked_col" */
2746 static int checked_col = 0; /* column in "checked_lnum" up to which
Bram Moolenaar30abd282005-06-22 22:35:10 +00002747 * there are no spell errors */
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002748 static int cap_col = -1; /* column to check for Cap word */
2749 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */
Bram Moolenaar30abd282005-06-22 22:35:10 +00002750 int cur_checked_col = 0; /* checked column for current line */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751#endif
2752 int extra_check; /* has syntax or linebreak */
2753#ifdef FEAT_MBYTE
2754 int multi_attr = 0; /* attributes desired by multibyte */
2755 int mb_l = 1; /* multi-byte byte length */
2756 int mb_c = 0; /* decoded multi-byte character */
2757 int mb_utf8 = FALSE; /* screen char is UTF-8 char */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00002758 int u8cc[MAX_MCO]; /* composing UTF-8 chars */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759#endif
2760#ifdef FEAT_DIFF
2761 int filler_lines; /* nr of filler lines to be drawn */
2762 int filler_todo; /* nr of filler lines still to do + 1 */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00002763 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 int change_start = MAXCOL; /* first col of changed area */
2765 int change_end = -1; /* last col of changed area */
2766#endif
2767 colnr_T trailcol = MAXCOL; /* start of trailing spaces */
2768#ifdef FEAT_LINEBREAK
2769 int need_showbreak = FALSE;
2770#endif
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00002771#if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2772 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773# define LINE_ATTR
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00002774 int line_attr = 0; /* attribute for the whole line */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#endif
2776#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002777 matchitem_T *cur; /* points to the match list */
2778 match_T *shl; /* points to search_hl or a match */
2779 int shl_flag; /* flag to indicate whether search_hl
2780 has been processed or not */
2781 int prevcol_hl_flag; /* flag to indicate whether prevcol
2782 equals startcol of search_hl or one
2783 of the matches */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784#endif
2785#ifdef FEAT_ARABIC
2786 int prev_c = 0; /* previous Arabic character */
2787 int prev_c1 = 0; /* first composing char for prev_c */
2788#endif
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00002789#if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00002790 int did_line_attr = 0;
2791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792
2793 /* draw_state: items that are drawn in sequence: */
2794#define WL_START 0 /* nothing done yet */
2795#ifdef FEAT_CMDWIN
2796# define WL_CMDLINE WL_START + 1 /* cmdline window column */
2797#else
2798# define WL_CMDLINE WL_START
2799#endif
2800#ifdef FEAT_FOLDING
2801# define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2802#else
2803# define WL_FOLD WL_CMDLINE
2804#endif
2805#ifdef FEAT_SIGNS
2806# define WL_SIGN WL_FOLD + 1 /* column for signs */
2807#else
2808# define WL_SIGN WL_FOLD /* column for signs */
2809#endif
2810#define WL_NR WL_SIGN + 1 /* line number */
2811#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2812# define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2813#else
2814# define WL_SBR WL_NR
2815#endif
2816#define WL_LINE WL_SBR + 1 /* text in the line */
2817 int draw_state = WL_START; /* what to draw next */
Bram Moolenaar9372a112005-12-06 19:59:18 +00002818#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 int feedback_col = 0;
2820 int feedback_old_attr = -1;
2821#endif
2822
Bram Moolenaar860cae12010-06-05 23:22:07 +02002823#ifdef FEAT_CONCEAL
2824 int syntax_flags = 0;
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02002825 int syntax_seqnr = 0;
Bram Moolenaar27c735b2010-07-22 22:16:29 +02002826 int prev_syntax_id = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02002827 int conceal_attr = hl_attr(HLF_CONCEAL);
Bram Moolenaar860cae12010-06-05 23:22:07 +02002828 int is_concealing = FALSE;
2829 int boguscols = 0; /* nonexistent columns added to force
2830 wrapping */
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +02002831 int vcol_off = 0; /* offset for concealed characters */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02002832 int did_wcol = FALSE;
Bram Moolenaarac550fd2010-07-18 13:55:02 +02002833# define VCOL_HLC (vcol - vcol_off)
2834#else
2835# define VCOL_HLC (vcol)
Bram Moolenaar860cae12010-06-05 23:22:07 +02002836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837
2838 if (startrow > endrow) /* past the end already! */
2839 return startrow;
2840
2841 row = startrow;
2842 screen_row = row + W_WINROW(wp);
2843
2844 /*
2845 * To speed up the loop below, set extra_check when there is linebreak,
2846 * trailing white space and/or syntax processing to be done.
2847 */
2848#ifdef FEAT_LINEBREAK
2849 extra_check = wp->w_p_lbr;
2850#else
2851 extra_check = 0;
2852#endif
2853#ifdef FEAT_SYN_HL
Bram Moolenaar860cae12010-06-05 23:22:07 +02002854 if (syntax_present(wp) && !wp->w_s->b_syn_error)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {
2856 /* Prepare for syntax highlighting in this line. When there is an
2857 * error, stop syntax highlighting. */
2858 save_did_emsg = did_emsg;
2859 did_emsg = FALSE;
2860 syntax_start(wp, lnum);
2861 if (did_emsg)
Bram Moolenaar860cae12010-06-05 23:22:07 +02002862 wp->w_s->b_syn_error = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 else
2864 {
2865 did_emsg = save_did_emsg;
2866 has_syntax = TRUE;
2867 extra_check = TRUE;
2868 }
2869 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02002870
2871 /* Check for columns to display for 'colorcolumn'. */
2872 color_cols = wp->w_p_cc_cols;
2873 if (color_cols != NULL)
Bram Moolenaarac550fd2010-07-18 13:55:02 +02002874 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002875#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00002876
Bram Moolenaar600dddc2006-03-12 22:05:10 +00002877#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00002878 if (wp->w_p_spell
Bram Moolenaar860cae12010-06-05 23:22:07 +02002879 && *wp->w_s->b_p_spl != NUL
2880 && wp->w_s->b_langp.ga_len > 0
2881 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
Bram Moolenaar217ad922005-03-20 22:37:15 +00002882 {
2883 /* Prepare for spell checking. */
2884 has_spell = TRUE;
2885 extra_check = TRUE;
Bram Moolenaar30abd282005-06-22 22:35:10 +00002886
2887 /* Get the start of the next line, so that words that wrap to the next
2888 * line are found too: "et<line-break>al.".
2889 * Trick: skip a few chars for C/shell/Vim comments */
2890 nextline[SPWORDLEN] = NUL;
2891 if (lnum < wp->w_buffer->b_ml.ml_line_count)
2892 {
2893 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
2894 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
2895 }
2896
2897 /* When a word wrapped from the previous line the start of the current
2898 * line is valid. */
2899 if (lnum == checked_lnum)
2900 cur_checked_col = checked_col;
2901 checked_lnum = 0;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002902
2903 /* When there was a sentence end in the previous line may require a
2904 * word starting with capital in this line. In line 1 always check
2905 * the first word. */
2906 if (lnum != capcol_lnum)
2907 cap_col = -1;
2908 if (lnum == 1)
2909 cap_col = 0;
2910 capcol_lnum = 0;
Bram Moolenaar217ad922005-03-20 22:37:15 +00002911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912#endif
2913
2914 /*
2915 * handle visual active in this window
2916 */
2917 fromcol = -10;
2918 tocol = MAXCOL;
2919#ifdef FEAT_VISUAL
2920 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
2921 {
2922 /* Visual is after curwin->w_cursor */
2923 if (ltoreq(curwin->w_cursor, VIsual))
2924 {
2925 top = &curwin->w_cursor;
2926 bot = &VIsual;
2927 }
2928 else /* Visual is before curwin->w_cursor */
2929 {
2930 top = &VIsual;
2931 bot = &curwin->w_cursor;
2932 }
Bram Moolenaar54ef7112009-02-21 20:11:41 +00002933 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 if (VIsual_mode == Ctrl_V) /* block mode */
2935 {
Bram Moolenaar54ef7112009-02-21 20:11:41 +00002936 if (lnum_in_visual_area)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {
2938 fromcol = wp->w_old_cursor_fcol;
2939 tocol = wp->w_old_cursor_lcol;
2940 }
2941 }
2942 else /* non-block mode */
2943 {
2944 if (lnum > top->lnum && lnum <= bot->lnum)
2945 fromcol = 0;
2946 else if (lnum == top->lnum)
2947 {
2948 if (VIsual_mode == 'V') /* linewise */
2949 fromcol = 0;
2950 else
2951 {
2952 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
2953 if (gchar_pos(top) == NUL)
2954 tocol = fromcol + 1;
2955 }
2956 }
2957 if (VIsual_mode != 'V' && lnum == bot->lnum)
2958 {
2959 if (*p_sel == 'e' && bot->col == 0
2960#ifdef FEAT_VIRTUALEDIT
2961 && bot->coladd == 0
2962#endif
2963 )
2964 {
2965 fromcol = -10;
2966 tocol = MAXCOL;
2967 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002968 else if (bot->col == MAXCOL)
2969 tocol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 else
2971 {
2972 pos = *bot;
2973 if (*p_sel == 'e')
2974 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
2975 else
2976 {
2977 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
2978 ++tocol;
2979 }
2980 }
2981 }
2982 }
2983
2984#ifndef MSDOS
2985 /* Check if the character under the cursor should not be inverted */
2986 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin
2987# ifdef FEAT_GUI
2988 && !gui.in_use
2989# endif
2990 )
2991 noinvcur = TRUE;
2992#endif
2993
2994 /* if inverting in this line set area_highlighting */
2995 if (fromcol >= 0)
2996 {
2997 area_highlighting = TRUE;
2998 attr = hl_attr(HLF_V);
2999#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
3000 if (clip_star.available && !clip_star.owned && clip_isautosel())
3001 attr = hl_attr(HLF_VNC);
3002#endif
3003 }
3004 }
3005
3006 /*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00003007 * handle 'incsearch' and ":s///c" highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 */
3009 else
3010#endif /* FEAT_VISUAL */
3011 if (highlight_match
3012 && wp == curwin
3013 && lnum >= curwin->w_cursor.lnum
3014 && lnum <= curwin->w_cursor.lnum + search_match_lines)
3015 {
3016 if (lnum == curwin->w_cursor.lnum)
3017 getvcol(curwin, &(curwin->w_cursor),
3018 (colnr_T *)&fromcol, NULL, NULL);
3019 else
3020 fromcol = 0;
3021 if (lnum == curwin->w_cursor.lnum + search_match_lines)
3022 {
3023 pos.lnum = lnum;
3024 pos.col = search_match_endcol;
3025 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
3026 }
3027 else
3028 tocol = MAXCOL;
Bram Moolenaarf3205d12009-03-18 18:09:03 +00003029 /* do at least one character; happens when past end of line */
3030 if (fromcol == tocol)
3031 tocol = fromcol + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 area_highlighting = TRUE;
3033 attr = hl_attr(HLF_I);
3034 }
3035
3036#ifdef FEAT_DIFF
3037 filler_lines = diff_check(wp, lnum);
3038 if (filler_lines < 0)
3039 {
3040 if (filler_lines == -1)
3041 {
3042 if (diff_find_change(wp, lnum, &change_start, &change_end))
3043 diff_hlf = HLF_ADD; /* added line */
3044 else if (change_start == 0)
3045 diff_hlf = HLF_TXD; /* changed text */
3046 else
3047 diff_hlf = HLF_CHD; /* changed line */
3048 }
3049 else
3050 diff_hlf = HLF_ADD; /* added line */
3051 filler_lines = 0;
3052 area_highlighting = TRUE;
3053 }
3054 if (lnum == wp->w_topline)
3055 filler_lines = wp->w_topfill;
3056 filler_todo = filler_lines;
3057#endif
3058
3059#ifdef LINE_ATTR
3060# ifdef FEAT_SIGNS
3061 /* If this line has a sign with line highlighting set line_attr. */
3062 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL);
3063 if (v != 0)
3064 line_attr = sign_get_attr((int)v, TRUE);
3065# endif
3066# if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
3067 /* Highlight the current line in the quickfix window. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003068 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 line_attr = hl_attr(HLF_L);
3070# endif
3071 if (line_attr != 0)
3072 area_highlighting = TRUE;
3073#endif
3074
3075 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3076 ptr = line;
3077
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003078#ifdef FEAT_SPELL
Bram Moolenaar30abd282005-06-22 22:35:10 +00003079 if (has_spell)
3080 {
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003081 /* For checking first word with a capital skip white space. */
3082 if (cap_col == 0)
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003083 cap_col = (int)(skipwhite(line) - line);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003084
Bram Moolenaar30abd282005-06-22 22:35:10 +00003085 /* To be able to spell-check over line boundaries copy the end of the
3086 * current line into nextline[]. Above the start of the next line was
3087 * copied to nextline[SPWORDLEN]. */
3088 if (nextline[SPWORDLEN] == NUL)
3089 {
3090 /* No next line or it is empty. */
3091 nextlinecol = MAXCOL;
3092 nextline_idx = 0;
3093 }
3094 else
3095 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003096 v = (long)STRLEN(line);
Bram Moolenaar30abd282005-06-22 22:35:10 +00003097 if (v < SPWORDLEN)
3098 {
3099 /* Short line, use it completely and append the start of the
3100 * next line. */
3101 nextlinecol = 0;
3102 mch_memmove(nextline, line, (size_t)v);
Bram Moolenaar446cb832008-06-24 21:56:24 +00003103 STRMOVE(nextline + v, nextline + SPWORDLEN);
Bram Moolenaar30abd282005-06-22 22:35:10 +00003104 nextline_idx = v + 1;
3105 }
3106 else
3107 {
3108 /* Long line, use only the last SPWORDLEN bytes. */
3109 nextlinecol = v - SPWORDLEN;
3110 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
3111 nextline_idx = SPWORDLEN + 1;
3112 }
3113 }
3114 }
3115#endif
3116
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 /* find start of trailing whitespace */
3118 if (wp->w_p_list && lcs_trail)
3119 {
3120 trailcol = (colnr_T)STRLEN(ptr);
3121 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1]))
3122 --trailcol;
3123 trailcol += (colnr_T) (ptr - line);
3124 extra_check = TRUE;
3125 }
3126
3127 /*
3128 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
3129 * first character to be displayed.
3130 */
3131 if (wp->w_p_wrap)
3132 v = wp->w_skipcol;
3133 else
3134 v = wp->w_leftcol;
3135 if (v > 0)
3136 {
3137#ifdef FEAT_MBYTE
3138 char_u *prev_ptr = ptr;
3139#endif
3140 while (vcol < v && *ptr != NUL)
3141 {
3142 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL);
3143 vcol += c;
3144#ifdef FEAT_MBYTE
3145 prev_ptr = ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00003147 mb_ptr_adv(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 }
3149
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003150#if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3151 /* When:
3152 * - 'cuc' is set, or
Bram Moolenaar1a384422010-07-14 19:53:30 +02003153 * - 'colorcolumn' is set, or
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003154 * - 'virtualedit' is set, or
3155 * - the visual mode is active,
3156 * the end of the line may be before the start of the displayed part.
3157 */
3158 if (vcol < v && (
3159# ifdef FEAT_SYN_HL
3160 wp->w_p_cuc
Bram Moolenaar1a384422010-07-14 19:53:30 +02003161 || draw_color_col
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003162# if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3163 ||
3164# endif
3165# endif
3166# ifdef FEAT_VIRTUALEDIT
3167 virtual_active()
3168# ifdef FEAT_VISUAL
3169 ||
3170# endif
3171# endif
3172# ifdef FEAT_VISUAL
3173 (VIsual_active && wp->w_buffer == curwin->w_buffer)
3174# endif
3175 ))
3176 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 vcol = v;
Bram Moolenaarbb6a7052009-11-03 16:36:44 +00003178 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179#endif
3180
3181 /* Handle a character that's not completely on the screen: Put ptr at
3182 * that character but skip the first few screen characters. */
3183 if (vcol > v)
3184 {
3185 vcol -= c;
3186#ifdef FEAT_MBYTE
3187 ptr = prev_ptr;
3188#else
3189 --ptr;
3190#endif
3191 n_skip = v - vcol;
3192 }
3193
3194 /*
3195 * Adjust for when the inverted text is before the screen,
3196 * and when the start of the inverted text is before the screen.
3197 */
3198 if (tocol <= vcol)
3199 fromcol = 0;
3200 else if (fromcol >= 0 && fromcol < vcol)
3201 fromcol = vcol;
3202
3203#ifdef FEAT_LINEBREAK
3204 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3205 if (wp->w_p_wrap)
3206 need_showbreak = TRUE;
3207#endif
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003208#ifdef FEAT_SPELL
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003209 /* When spell checking a word we need to figure out the start of the
3210 * word and if it's badly spelled or not. */
3211 if (has_spell)
3212 {
3213 int len;
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003214 colnr_T linecol = (colnr_T)(ptr - line);
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003215 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003216
3217 pos = wp->w_cursor;
3218 wp->w_cursor.lnum = lnum;
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003219 wp->w_cursor.col = linecol;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003220 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003221
3222 /* spell_move_to() may call ml_get() and make "line" invalid */
3223 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3224 ptr = line + linecol;
3225
Bram Moolenaar60a795a2005-09-16 21:55:43 +00003226 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003227 {
3228 /* no bad word found at line start, don't check until end of a
3229 * word */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003230 spell_hlf = HLF_COUNT;
Bram Moolenaar860cae12010-06-05 23:22:07 +02003231 word_end = (int)(spell_to_word_end(ptr, wp)
Bram Moolenaar4ef9e492008-02-13 20:49:04 +00003232 - line + 1);
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003233 }
3234 else
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003235 {
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003236 /* bad word found, use attributes until end of word */
3237 word_end = wp->w_cursor.col + len + 1;
3238
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003239 /* Turn index into actual attributes. */
3240 if (spell_hlf != HLF_COUNT)
3241 spell_attr = highlight_attr[spell_hlf];
3242 }
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003243 wp->w_cursor = pos;
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003244
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003245# ifdef FEAT_SYN_HL
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003246 /* Need to restart syntax highlighting for this line. */
3247 if (has_syntax)
3248 syntax_start(wp, lnum);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003249# endif
Bram Moolenaar81f1ecb2005-08-25 21:27:31 +00003250 }
3251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 }
3253
3254 /*
3255 * Correct highlighting for cursor that can't be disabled.
3256 * Avoids having to check this for each character.
3257 */
3258 if (fromcol >= 0)
3259 {
3260 if (noinvcur)
3261 {
3262 if ((colnr_T)fromcol == wp->w_virtcol)
3263 {
3264 /* highlighting starts at cursor, let it start just after the
3265 * cursor */
3266 fromcol_prev = fromcol;
3267 fromcol = -1;
3268 }
3269 else if ((colnr_T)fromcol < wp->w_virtcol)
3270 /* restart highlighting after the cursor */
3271 fromcol_prev = wp->w_virtcol;
3272 }
3273 if (fromcol >= tocol)
3274 fromcol = -1;
3275 }
3276
3277#ifdef FEAT_SEARCH_EXTRA
3278 /*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003279 * Handle highlighting the last used search pattern and matches.
3280 * Do this for both search_hl and the match list.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281 */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003282 cur = wp->w_match_head;
3283 shl_flag = FALSE;
3284 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003286 if (shl_flag == FALSE)
3287 {
3288 shl = &search_hl;
3289 shl_flag = TRUE;
3290 }
3291 else
3292 shl = &cur->hl;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003293 shl->startcol = MAXCOL;
3294 shl->endcol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 shl->attr_cur = 0;
3296 if (shl->rm.regprog != NULL)
3297 {
3298 v = (long)(ptr - line);
3299 next_search_hl(wp, shl, lnum, (colnr_T)v);
3300
3301 /* Need to get the line again, a multi-line regexp may have made it
3302 * invalid. */
3303 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3304 ptr = line + v;
3305
3306 if (shl->lnum != 0 && shl->lnum <= lnum)
3307 {
3308 if (shl->lnum == lnum)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003309 shl->startcol = shl->rm.startpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003311 shl->startcol = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312 if (lnum == shl->lnum + shl->rm.endpos[0].lnum
3313 - shl->rm.startpos[0].lnum)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003314 shl->endcol = shl->rm.endpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003316 shl->endcol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 /* Highlight one character for an empty match. */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003318 if (shl->startcol == shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 {
3320#ifdef FEAT_MBYTE
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003321 if (has_mbyte && line[shl->endcol] != NUL)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00003322 shl->endcol += (*mb_ptr2len)(line + shl->endcol);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323 else
3324#endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003325 ++shl->endcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003327 if ((long)shl->startcol < v) /* match at leftcol */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 {
3329 shl->attr_cur = shl->attr;
3330 search_attr = shl->attr;
3331 }
3332 area_highlighting = TRUE;
3333 }
3334 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003335 if (shl != &search_hl && cur != NULL)
3336 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 }
3338#endif
3339
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003340#ifdef FEAT_SYN_HL
Bram Moolenaare2f98b92006-03-29 21:18:24 +00003341 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3342 * active, because it's not clear what is selected then. */
3343 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003344 {
3345 line_attr = hl_attr(HLF_CUL);
3346 area_highlighting = TRUE;
3347 }
3348#endif
3349
Bram Moolenaar92d640f2005-09-05 22:11:52 +00003350 off = (unsigned)(current_ScreenLine - ScreenLines);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 col = 0;
3352#ifdef FEAT_RIGHTLEFT
3353 if (wp->w_p_rl)
3354 {
3355 /* Rightleft window: process the text in the normal direction, but put
3356 * it in current_ScreenLine[] from right to left. Start at the
3357 * rightmost column of the window. */
3358 col = W_WIDTH(wp) - 1;
3359 off += col;
3360 }
3361#endif
3362
3363 /*
3364 * Repeat for the whole displayed line.
3365 */
3366 for (;;)
3367 {
3368 /* Skip this quickly when working on the text. */
3369 if (draw_state != WL_LINE)
3370 {
3371#ifdef FEAT_CMDWIN
3372 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
3373 {
3374 draw_state = WL_CMDLINE;
3375 if (cmdwin_type != 0 && wp == curwin)
3376 {
3377 /* Draw the cmdline character. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 n_extra = 1;
Bram Moolenaara064ac82007-08-05 18:10:54 +00003379 c_extra = cmdwin_type;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 char_attr = hl_attr(HLF_AT);
3381 }
3382 }
3383#endif
3384
3385#ifdef FEAT_FOLDING
3386 if (draw_state == WL_FOLD - 1 && n_extra == 0)
3387 {
3388 draw_state = WL_FOLD;
3389 if (wp->w_p_fdc > 0)
3390 {
3391 /* Draw the 'foldcolumn'. */
3392 fill_foldcolumn(extra, wp, FALSE, lnum);
3393 n_extra = wp->w_p_fdc;
3394 p_extra = extra;
Bram Moolenaara064ac82007-08-05 18:10:54 +00003395 p_extra[n_extra] = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396 c_extra = NUL;
3397 char_attr = hl_attr(HLF_FC);
3398 }
3399 }
3400#endif
3401
3402#ifdef FEAT_SIGNS
3403 if (draw_state == WL_SIGN - 1 && n_extra == 0)
3404 {
3405 draw_state = WL_SIGN;
3406 /* Show the sign column when there are any signs in this
3407 * buffer or when using Netbeans. */
3408 if (draw_signcolumn(wp)
3409# ifdef FEAT_DIFF
3410 && filler_todo <= 0
3411# endif
3412 )
3413 {
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01003414 int text_sign;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415# ifdef FEAT_SIGN_ICONS
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01003416 int icon_sign;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417# endif
3418
3419 /* Draw two cells with the sign value or blank. */
3420 c_extra = ' ';
3421 char_attr = hl_attr(HLF_SC);
3422 n_extra = 2;
3423
3424 if (row == startrow)
3425 {
3426 text_sign = buf_getsigntype(wp->w_buffer, lnum,
3427 SIGN_TEXT);
3428# ifdef FEAT_SIGN_ICONS
3429 icon_sign = buf_getsigntype(wp->w_buffer, lnum,
3430 SIGN_ICON);
3431 if (gui.in_use && icon_sign != 0)
3432 {
3433 /* Use the image in this position. */
3434 c_extra = SIGN_BYTE;
3435# ifdef FEAT_NETBEANS_INTG
3436 if (buf_signcount(wp->w_buffer, lnum) > 1)
3437 c_extra = MULTISIGN_BYTE;
3438# endif
3439 char_attr = icon_sign;
3440 }
3441 else
3442# endif
3443 if (text_sign != 0)
3444 {
3445 p_extra = sign_get_text(text_sign);
3446 if (p_extra != NULL)
3447 {
3448 c_extra = NUL;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003449 n_extra = (int)STRLEN(p_extra);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 }
3451 char_attr = sign_get_attr(text_sign, FALSE);
3452 }
3453 }
3454 }
3455 }
3456#endif
3457
3458 if (draw_state == WL_NR - 1 && n_extra == 0)
3459 {
3460 draw_state = WL_NR;
Bram Moolenaar64486672010-05-16 15:46:46 +02003461 /* Display the absolute or relative line number. After the
3462 * first fill with blanks when the 'n' flag isn't in 'cpo' */
3463 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 && (row == startrow
3465#ifdef FEAT_DIFF
3466 + filler_lines
3467#endif
3468 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
3469 {
3470 /* Draw the line number (empty space after wrapping). */
3471 if (row == startrow
3472#ifdef FEAT_DIFF
3473 + filler_lines
3474#endif
3475 )
3476 {
Bram Moolenaar64486672010-05-16 15:46:46 +02003477 long num;
3478
3479 if (wp->w_p_nu)
3480 /* 'number' */
3481 num = (long)lnum;
3482 else
3483 /* 'relativenumber', don't use negative numbers */
Bram Moolenaar7eb46522010-12-30 14:57:08 +01003484 num = labs((long)get_cursor_rel_lnum(wp, lnum));
Bram Moolenaar64486672010-05-16 15:46:46 +02003485
Bram Moolenaar592e0a22004-07-03 16:05:59 +00003486 sprintf((char *)extra, "%*ld ",
Bram Moolenaar64486672010-05-16 15:46:46 +02003487 number_width(wp), num);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 if (wp->w_skipcol > 0)
3489 for (p_extra = extra; *p_extra == ' '; ++p_extra)
3490 *p_extra = '-';
3491#ifdef FEAT_RIGHTLEFT
3492 if (wp->w_p_rl) /* reverse line numbers */
3493 rl_mirror(extra);
3494#endif
3495 p_extra = extra;
3496 c_extra = NUL;
3497 }
3498 else
3499 c_extra = ' ';
Bram Moolenaar592e0a22004-07-03 16:05:59 +00003500 n_extra = number_width(wp) + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501 char_attr = hl_attr(HLF_N);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003502#ifdef FEAT_SYN_HL
3503 /* When 'cursorline' is set highlight the line number of
Bram Moolenaar06ca5132012-03-23 16:25:17 +01003504 * the current line differently.
3505 * TODO: Can we use CursorLine instead of CursorLineNr
3506 * when CursorLineNr isn't set? */
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003507 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
Bram Moolenaar06ca5132012-03-23 16:25:17 +01003508 char_attr = hl_attr(HLF_CLN);
Bram Moolenaar600dddc2006-03-12 22:05:10 +00003509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 }
3511 }
3512
3513#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3514 if (draw_state == WL_SBR - 1 && n_extra == 0)
3515 {
3516 draw_state = WL_SBR;
3517# ifdef FEAT_DIFF
3518 if (filler_todo > 0)
3519 {
3520 /* Draw "deleted" diff line(s). */
3521 if (char2cells(fill_diff) > 1)
3522 c_extra = '-';
3523 else
3524 c_extra = fill_diff;
3525# ifdef FEAT_RIGHTLEFT
3526 if (wp->w_p_rl)
3527 n_extra = col + 1;
3528 else
3529# endif
3530 n_extra = W_WIDTH(wp) - col;
3531 char_attr = hl_attr(HLF_DED);
3532 }
3533# endif
3534# ifdef FEAT_LINEBREAK
3535 if (*p_sbr != NUL && need_showbreak)
3536 {
3537 /* Draw 'showbreak' at the start of each broken line. */
3538 p_extra = p_sbr;
3539 c_extra = NUL;
3540 n_extra = (int)STRLEN(p_sbr);
3541 char_attr = hl_attr(HLF_AT);
3542 need_showbreak = FALSE;
3543 /* Correct end of highlighted area for 'showbreak',
3544 * required when 'linebreak' is also set. */
3545 if (tocol == vcol)
3546 tocol += n_extra;
3547 }
3548# endif
3549 }
3550#endif
3551
3552 if (draw_state == WL_LINE - 1 && n_extra == 0)
3553 {
3554 draw_state = WL_LINE;
3555 if (saved_n_extra)
3556 {
3557 /* Continue item from end of wrapped line. */
3558 n_extra = saved_n_extra;
3559 c_extra = saved_c_extra;
3560 p_extra = saved_p_extra;
3561 char_attr = saved_char_attr;
3562 }
3563 else
3564 char_attr = 0;
3565 }
3566 }
3567
3568 /* When still displaying '$' of change command, stop at cursor */
Bram Moolenaar76b9b362012-02-04 23:35:00 +01003569 if (dollar_vcol >= 0 && wp == curwin
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003570 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571#ifdef FEAT_DIFF
3572 && filler_todo <= 0
3573#endif
3574 )
3575 {
3576 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp),
3577 wp->w_p_rl);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003578 /* Pretend we have finished updating the window. Except when
3579 * 'cursorcolumn' is set. */
3580#ifdef FEAT_SYN_HL
3581 if (wp->w_p_cuc)
3582 row = wp->w_cline_row + wp->w_cline_height;
3583 else
3584#endif
3585 row = wp->w_height;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 break;
3587 }
3588
3589 if (draw_state == WL_LINE && area_highlighting)
3590 {
3591 /* handle Visual or match highlighting in this line */
3592 if (vcol == fromcol
3593#ifdef FEAT_MBYTE
3594 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
3595 && (*mb_ptr2cells)(ptr) > 1)
3596#endif
3597 || ((int)vcol_prev == fromcol_prev
Bram Moolenaarfa363cd2009-02-21 20:23:59 +00003598 && vcol_prev < vcol /* not at margin */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 && vcol < tocol))
3600 area_attr = attr; /* start highlighting */
3601 else if (area_attr != 0
3602 && (vcol == tocol
3603 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 area_attr = 0; /* stop highlighting */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605
3606#ifdef FEAT_SEARCH_EXTRA
3607 if (!n_extra)
3608 {
3609 /*
3610 * Check for start/end of search pattern match.
3611 * After end, check for start/end of next match.
3612 * When another match, have to check for start again.
3613 * Watch out for matching an empty string!
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003614 * Do this for 'search_hl' and the match list (ordered by
3615 * priority).
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003617 v = (long)(ptr - line);
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003618 cur = wp->w_match_head;
3619 shl_flag = FALSE;
3620 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003622 if (shl_flag == FALSE
3623 && ((cur != NULL
3624 && cur->priority > SEARCH_HL_PRIORITY)
3625 || cur == NULL))
3626 {
3627 shl = &search_hl;
3628 shl_flag = TRUE;
3629 }
3630 else
3631 shl = &cur->hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 while (shl->rm.regprog != NULL)
3633 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003634 if (shl->startcol != MAXCOL
3635 && v >= (long)shl->startcol
3636 && v < (long)shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637 {
3638 shl->attr_cur = shl->attr;
3639 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003640 else if (v == (long)shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 {
3642 shl->attr_cur = 0;
3643
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 next_search_hl(wp, shl, lnum, (colnr_T)v);
3645
3646 /* Need to get the line again, a multi-line regexp
3647 * may have made it invalid. */
3648 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3649 ptr = line + v;
3650
3651 if (shl->lnum == lnum)
3652 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003653 shl->startcol = shl->rm.startpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (shl->rm.endpos[0].lnum == 0)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003655 shl->endcol = shl->rm.endpos[0].col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003657 shl->endcol = MAXCOL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003659 if (shl->startcol == shl->endcol)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660 {
3661 /* highlight empty match, try again after
3662 * it */
3663#ifdef FEAT_MBYTE
3664 if (has_mbyte)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00003665 shl->endcol += (*mb_ptr2len)(line
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003666 + shl->endcol);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667 else
3668#endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003669 ++shl->endcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670 }
3671
3672 /* Loop to check if the match starts at the
3673 * current position */
3674 continue;
3675 }
3676 }
3677 break;
3678 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003679 if (shl != &search_hl && cur != NULL)
3680 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 }
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00003682
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003683 /* Use attributes from match with highest priority among
3684 * 'search_hl' and the match list. */
3685 search_attr = search_hl.attr_cur;
3686 cur = wp->w_match_head;
3687 shl_flag = FALSE;
3688 while (cur != NULL || shl_flag == FALSE)
3689 {
3690 if (shl_flag == FALSE
3691 && ((cur != NULL
3692 && cur->priority > SEARCH_HL_PRIORITY)
3693 || cur == NULL))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00003694 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003695 shl = &search_hl;
3696 shl_flag = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00003697 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003698 else
3699 shl = &cur->hl;
3700 if (shl->attr_cur != 0)
3701 search_attr = shl->attr_cur;
3702 if (shl != &search_hl && cur != NULL)
3703 cur = cur->next;
3704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 }
3706#endif
3707
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708#ifdef FEAT_DIFF
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00003709 if (diff_hlf != (hlf_T)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 {
Bram Moolenaar4b80a512007-06-19 15:44:58 +00003711 if (diff_hlf == HLF_CHD && ptr - line >= change_start
3712 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 diff_hlf = HLF_TXD; /* changed text */
Bram Moolenaar4b80a512007-06-19 15:44:58 +00003714 if (diff_hlf == HLF_TXD && ptr - line > change_end
3715 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 diff_hlf = HLF_CHD; /* changed line */
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00003717 line_attr = hl_attr(diff_hlf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 }
3719#endif
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00003720
3721 /* Decide which of the highlight attributes to use. */
3722 attr_pri = TRUE;
3723 if (area_attr != 0)
3724 char_attr = area_attr;
3725 else if (search_attr != 0)
3726 char_attr = search_attr;
3727#ifdef LINE_ATTR
3728 /* Use line_attr when not in the Visual or 'incsearch' area
3729 * (area_attr may be 0 when "noinvcur" is set). */
3730 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaarf837ef92009-03-11 16:47:21 +00003731 || vcol < fromcol || vcol_prev < fromcol_prev
3732 || vcol >= tocol))
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00003733 char_attr = line_attr;
3734#endif
3735 else
3736 {
3737 attr_pri = FALSE;
3738#ifdef FEAT_SYN_HL
3739 if (has_syntax)
3740 char_attr = syntax_attr;
3741 else
3742#endif
3743 char_attr = 0;
3744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745 }
3746
3747 /*
3748 * Get the next character to put on the screen.
3749 */
3750 /*
Bram Moolenaara064ac82007-08-05 18:10:54 +00003751 * The "p_extra" points to the extra stuff that is inserted to
3752 * represent special characters (non-printable stuff) and other
3753 * things. When all characters are the same, c_extra is used.
3754 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3755 * "p_extra[n_extra]".
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3757 */
3758 if (n_extra > 0)
3759 {
3760 if (c_extra != NUL)
3761 {
3762 c = c_extra;
3763#ifdef FEAT_MBYTE
3764 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */
3765 if (enc_utf8 && (*mb_char2len)(c) > 1)
3766 {
3767 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003768 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003769 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 }
3771 else
3772 mb_utf8 = FALSE;
3773#endif
3774 }
3775 else
3776 {
3777 c = *p_extra;
3778#ifdef FEAT_MBYTE
3779 if (has_mbyte)
3780 {
3781 mb_c = c;
3782 if (enc_utf8)
3783 {
3784 /* If the UTF-8 character is more than one byte:
3785 * Decode it into "mb_c". */
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00003786 mb_l = (*mb_ptr2len)(p_extra);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 mb_utf8 = FALSE;
3788 if (mb_l > n_extra)
3789 mb_l = 1;
3790 else if (mb_l > 1)
3791 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003792 mb_c = utfc_ptr2char(p_extra, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 mb_utf8 = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003794 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 }
3796 }
3797 else
3798 {
3799 /* if this is a DBCS character, put it in "mb_c" */
3800 mb_l = MB_BYTE2LEN(c);
3801 if (mb_l >= n_extra)
3802 mb_l = 1;
3803 else if (mb_l > 1)
3804 mb_c = (c << 8) + p_extra[1];
3805 }
Bram Moolenaar92d640f2005-09-05 22:11:52 +00003806 if (mb_l == 0) /* at the NUL at end-of-line */
3807 mb_l = 1;
3808
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 /* If a double-width char doesn't fit display a '>' in the
3810 * last column. */
Bram Moolenaar92d640f2005-09-05 22:11:52 +00003811 if ((
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812# ifdef FEAT_RIGHTLEFT
3813 wp->w_p_rl ? (col <= 0) :
3814# endif
Bram Moolenaar92d640f2005-09-05 22:11:52 +00003815 (col >= W_WIDTH(wp) - 1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 && (*mb_char2cells)(mb_c) == 2)
3817 {
3818 c = '>';
3819 mb_c = c;
3820 mb_l = 1;
3821 mb_utf8 = FALSE;
3822 multi_attr = hl_attr(HLF_AT);
3823 /* put the pointer back to output the double-width
3824 * character at the start of the next line. */
3825 ++n_extra;
3826 --p_extra;
3827 }
3828 else
3829 {
3830 n_extra -= mb_l - 1;
3831 p_extra += mb_l - 1;
3832 }
3833 }
3834#endif
3835 ++p_extra;
3836 }
3837 --n_extra;
3838 }
3839 else
3840 {
3841 /*
3842 * Get a character from the line itself.
3843 */
3844 c = *ptr;
3845#ifdef FEAT_MBYTE
3846 if (has_mbyte)
3847 {
3848 mb_c = c;
3849 if (enc_utf8)
3850 {
3851 /* If the UTF-8 character is more than one byte: Decode it
3852 * into "mb_c". */
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00003853 mb_l = (*mb_ptr2len)(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 mb_utf8 = FALSE;
3855 if (mb_l > 1)
3856 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003857 mb_c = utfc_ptr2char(ptr, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 /* Overlong encoded ASCII or ASCII with composing char
3859 * is displayed normally, except a NUL. */
3860 if (mb_c < 0x80)
3861 c = mb_c;
3862 mb_utf8 = TRUE;
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00003863
3864 /* At start of the line we can have a composing char.
3865 * Draw it as a space with a composing char. */
3866 if (utf_iscomposing(mb_c))
3867 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003868 int i;
3869
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003870 for (i = Screen_mco - 1; i > 0; --i)
3871 u8cc[i] = u8cc[i - 1];
3872 u8cc[0] = mb_c;
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00003873 mb_c = ' ';
3874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 }
3876
3877 if ((mb_l == 1 && c >= 0x80)
3878 || (mb_l >= 1 && mb_c == 0)
3879 || (mb_l > 1 && (!vim_isprintc(mb_c)
Bram Moolenaar11936362007-09-17 20:39:42 +00003880# ifdef UNICODE16
3881 || mb_c >= 0x10000
3882# endif
3883 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 {
3885 /*
3886 * Illegal UTF-8 byte: display as <xx>.
3887 * Non-BMP character : display as ? or fullwidth ?.
3888 */
Bram Moolenaar11936362007-09-17 20:39:42 +00003889# ifdef UNICODE16
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 if (mb_c < 0x10000)
Bram Moolenaar11936362007-09-17 20:39:42 +00003891# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 {
3893 transchar_hex(extra, mb_c);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003894# ifdef FEAT_RIGHTLEFT
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 if (wp->w_p_rl) /* reverse */
3896 rl_mirror(extra);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003897# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 }
Bram Moolenaar11936362007-09-17 20:39:42 +00003899# ifdef UNICODE16
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 else if (utf_char2cells(mb_c) != 2)
3901 STRCPY(extra, "?");
3902 else
3903 /* 0xff1f in UTF-8: full-width '?' */
3904 STRCPY(extra, "\357\274\237");
Bram Moolenaar11936362007-09-17 20:39:42 +00003905# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906
3907 p_extra = extra;
3908 c = *p_extra;
3909 mb_c = mb_ptr2char_adv(&p_extra);
3910 mb_utf8 = (c >= 0x80);
3911 n_extra = (int)STRLEN(p_extra);
3912 c_extra = NUL;
3913 if (area_attr == 0 && search_attr == 0)
3914 {
3915 n_attr = n_extra + 1;
3916 extra_attr = hl_attr(HLF_8);
3917 saved_attr2 = char_attr; /* save current attr */
3918 }
3919 }
3920 else if (mb_l == 0) /* at the NUL at end-of-line */
3921 mb_l = 1;
3922#ifdef FEAT_ARABIC
3923 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
3924 {
3925 /* Do Arabic shaping. */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003926 int pc, pc1, nc;
3927 int pcc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928
3929 /* The idea of what is the previous and next
3930 * character depends on 'rightleft'. */
3931 if (wp->w_p_rl)
3932 {
3933 pc = prev_c;
3934 pc1 = prev_c1;
3935 nc = utf_ptr2char(ptr + mb_l);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003936 prev_c1 = u8cc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 }
3938 else
3939 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003940 pc = utfc_ptr2char(ptr + mb_l, pcc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 nc = prev_c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003942 pc1 = pcc[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 }
3944 prev_c = mb_c;
3945
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003946 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 }
3948 else
3949 prev_c = mb_c;
3950#endif
3951 }
3952 else /* enc_dbcs */
3953 {
3954 mb_l = MB_BYTE2LEN(c);
3955 if (mb_l == 0) /* at the NUL at end-of-line */
3956 mb_l = 1;
3957 else if (mb_l > 1)
3958 {
3959 /* We assume a second byte below 32 is illegal.
3960 * Hopefully this is OK for all double-byte encodings!
3961 */
3962 if (ptr[1] >= 32)
3963 mb_c = (c << 8) + ptr[1];
3964 else
3965 {
3966 if (ptr[1] == NUL)
3967 {
3968 /* head byte at end of line */
3969 mb_l = 1;
3970 transchar_nonprint(extra, c);
3971 }
3972 else
3973 {
3974 /* illegal tail byte */
3975 mb_l = 2;
3976 STRCPY(extra, "XX");
3977 }
3978 p_extra = extra;
3979 n_extra = (int)STRLEN(extra) - 1;
3980 c_extra = NUL;
3981 c = *p_extra++;
3982 if (area_attr == 0 && search_attr == 0)
3983 {
3984 n_attr = n_extra + 1;
3985 extra_attr = hl_attr(HLF_8);
3986 saved_attr2 = char_attr; /* save current attr */
3987 }
3988 mb_c = c;
3989 }
3990 }
3991 }
3992 /* If a double-width char doesn't fit display a '>' in the
3993 * last column; the character is displayed at the start of the
3994 * next line. */
3995 if ((
3996# ifdef FEAT_RIGHTLEFT
3997 wp->w_p_rl ? (col <= 0) :
3998# endif
3999 (col >= W_WIDTH(wp) - 1))
4000 && (*mb_char2cells)(mb_c) == 2)
4001 {
4002 c = '>';
4003 mb_c = c;
4004 mb_utf8 = FALSE;
4005 mb_l = 1;
4006 multi_attr = hl_attr(HLF_AT);
4007 /* Put pointer back so that the character will be
4008 * displayed at the start of the next line. */
4009 --ptr;
4010 }
4011 else if (*ptr != NUL)
4012 ptr += mb_l - 1;
4013
4014 /* If a double-width char doesn't fit at the left side display
Bram Moolenaar7ba6ed32010-08-07 16:38:13 +02004015 * a '<' in the first column. Don't do this for unprintable
4016 * charactes. */
4017 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 n_extra = 1;
Bram Moolenaara064ac82007-08-05 18:10:54 +00004020 c_extra = '<';
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 c = ' ';
4022 if (area_attr == 0 && search_attr == 0)
4023 {
4024 n_attr = n_extra + 1;
4025 extra_attr = hl_attr(HLF_AT);
4026 saved_attr2 = char_attr; /* save current attr */
4027 }
4028 mb_c = c;
4029 mb_utf8 = FALSE;
4030 mb_l = 1;
4031 }
4032
4033 }
4034#endif
4035 ++ptr;
4036
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004037 /* 'list' : change char 160 to lcs_nbsp. */
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004038 if (wp->w_p_list && (c == 160
4039#ifdef FEAT_MBYTE
4040 || (mb_utf8 && mb_c == 160)
4041#endif
4042 ) && lcs_nbsp)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004043 {
4044 c = lcs_nbsp;
4045 if (area_attr == 0 && search_attr == 0)
4046 {
4047 n_attr = 1;
4048 extra_attr = hl_attr(HLF_8);
4049 saved_attr2 = char_attr; /* save current attr */
4050 }
4051#ifdef FEAT_MBYTE
4052 mb_c = c;
4053 if (enc_utf8 && (*mb_char2len)(c) > 1)
4054 {
4055 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004056 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004057 c = 0xc0;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004058 }
4059 else
4060 mb_utf8 = FALSE;
4061#endif
4062 }
4063
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 if (extra_check)
4065 {
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004066#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00004067 int can_spell = TRUE;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004068#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00004069
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004070#ifdef FEAT_SYN_HL
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 /* Get syntax attribute, unless still at the start of the line
4072 * (double-wide char that doesn't fit). */
Bram Moolenaar217ad922005-03-20 22:37:15 +00004073 v = (long)(ptr - line);
4074 if (has_syntax && v > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 {
4076 /* Get the syntax attribute for the character. If there
4077 * is an error, disable syntax highlighting. */
4078 save_did_emsg = did_emsg;
4079 did_emsg = FALSE;
4080
Bram Moolenaar217ad922005-03-20 22:37:15 +00004081 syntax_attr = get_syntax_attr((colnr_T)v - 1,
Bram Moolenaar860cae12010-06-05 23:22:07 +02004082# ifdef FEAT_SPELL
4083 has_spell ? &can_spell :
4084# endif
4085 NULL, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086
4087 if (did_emsg)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004088 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02004089 wp->w_s->b_syn_error = TRUE;
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004090 has_syntax = FALSE;
4091 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 else
4093 did_emsg = save_did_emsg;
4094
4095 /* Need to get the line again, a multi-line regexp may
4096 * have made it invalid. */
4097 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
4098 ptr = line + v;
4099
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004100 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 char_attr = syntax_attr;
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004102 else
Bram Moolenaarbc045ea2005-06-05 22:01:26 +00004103 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaarc095b282010-07-20 22:33:34 +02004104# ifdef FEAT_CONCEAL
4105 /* no concealing past the end of the line, it interferes
4106 * with line highlighting */
4107 if (c == NUL)
4108 syntax_flags = 0;
Bram Moolenaar27c735b2010-07-22 22:16:29 +02004109 else
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02004110 syntax_flags = get_syntax_info(&syntax_seqnr);
Bram Moolenaarc095b282010-07-20 22:33:34 +02004111# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004113#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00004114
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004115#ifdef FEAT_SPELL
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004116 /* Check spelling (unless at the end of the line).
Bram Moolenaarf3681cc2005-06-08 22:03:13 +00004117 * Only do this when there is no syntax highlighting, the
4118 * @Spell cluster is not used or the current syntax item
4119 * contains the @Spell cluster. */
Bram Moolenaar30abd282005-06-22 22:35:10 +00004120 if (has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar217ad922005-03-20 22:37:15 +00004121 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004122 spell_attr = 0;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004123# ifdef FEAT_SYN_HL
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004124 if (!attr_pri)
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004125 char_attr = syntax_attr;
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004126# endif
4127 if (c != 0 && (
4128# ifdef FEAT_SYN_HL
4129 !has_syntax ||
4130# endif
4131 can_spell))
Bram Moolenaar217ad922005-03-20 22:37:15 +00004132 {
Bram Moolenaar30abd282005-06-22 22:35:10 +00004133 char_u *prev_ptr, *p;
4134 int len;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004135 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaar217ad922005-03-20 22:37:15 +00004136# ifdef FEAT_MBYTE
Bram Moolenaare7566042005-06-17 22:00:15 +00004137 if (has_mbyte)
4138 {
4139 prev_ptr = ptr - mb_l;
4140 v -= mb_l - 1;
4141 }
4142 else
Bram Moolenaar217ad922005-03-20 22:37:15 +00004143# endif
Bram Moolenaare7566042005-06-17 22:00:15 +00004144 prev_ptr = ptr - 1;
Bram Moolenaar30abd282005-06-22 22:35:10 +00004145
4146 /* Use nextline[] if possible, it has the start of the
4147 * next line concatenated. */
4148 if ((prev_ptr - line) - nextlinecol >= 0)
4149 p = nextline + (prev_ptr - line) - nextlinecol;
4150 else
4151 p = prev_ptr;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004152 cap_col -= (int)(prev_ptr - line);
Bram Moolenaar4770d092006-01-12 23:22:24 +00004153 len = spell_check(wp, p, &spell_hlf, &cap_col,
4154 nochange);
Bram Moolenaar30abd282005-06-22 22:35:10 +00004155 word_end = v + len;
Bram Moolenaar217ad922005-03-20 22:37:15 +00004156
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004157 /* In Insert mode only highlight a word that
4158 * doesn't touch the cursor. */
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004159 if (spell_hlf != HLF_COUNT
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004160 && (State & INSERT) != 0
4161 && wp->w_cursor.lnum == lnum
4162 && wp->w_cursor.col >=
Bram Moolenaar217ad922005-03-20 22:37:15 +00004163 (colnr_T)(prev_ptr - line)
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004164 && wp->w_cursor.col < (colnr_T)word_end)
4165 {
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004166 spell_hlf = HLF_COUNT;
Bram Moolenaar75c50c42005-06-04 22:06:24 +00004167 spell_redraw_lnum = lnum;
Bram Moolenaar217ad922005-03-20 22:37:15 +00004168 }
Bram Moolenaar30abd282005-06-22 22:35:10 +00004169
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004170 if (spell_hlf == HLF_COUNT && p != prev_ptr
Bram Moolenaar30abd282005-06-22 22:35:10 +00004171 && (p - nextline) + len > nextline_idx)
4172 {
4173 /* Remember that the good word continues at the
4174 * start of the next line. */
4175 checked_lnum = lnum + 1;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004176 checked_col = (int)((p - nextline) + len - nextline_idx);
Bram Moolenaar30abd282005-06-22 22:35:10 +00004177 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004178
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004179 /* Turn index into actual attributes. */
4180 if (spell_hlf != HLF_COUNT)
4181 spell_attr = highlight_attr[spell_hlf];
4182
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004183 if (cap_col > 0)
4184 {
4185 if (p != prev_ptr
4186 && (p - nextline) + cap_col >= nextline_idx)
4187 {
4188 /* Remember that the word in the next line
4189 * must start with a capital. */
4190 capcol_lnum = lnum + 1;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004191 cap_col = (int)((p - nextline) + cap_col
4192 - nextline_idx);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004193 }
4194 else
4195 /* Compute the actual column. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004196 cap_col += (int)(prev_ptr - line);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004197 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00004198 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00004199 }
4200 if (spell_attr != 0)
Bram Moolenaar30abd282005-06-22 22:35:10 +00004201 {
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004202 if (!attr_pri)
Bram Moolenaar30abd282005-06-22 22:35:10 +00004203 char_attr = hl_combine_attr(char_attr, spell_attr);
4204 else
4205 char_attr = hl_combine_attr(spell_attr, char_attr);
4206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207#endif
4208#ifdef FEAT_LINEBREAK
4209 /*
Bram Moolenaar217ad922005-03-20 22:37:15 +00004210 * Found last space before word: check for line break.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211 */
4212 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004213 && !wp->w_p_list)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 {
4215 n_extra = win_lbr_chartabsize(wp, ptr - (
4216# ifdef FEAT_MBYTE
4217 has_mbyte ? mb_l :
4218# endif
4219 1), (colnr_T)vcol, NULL) - 1;
4220 c_extra = ' ';
4221 if (vim_iswhite(c))
4222 c = ' ';
4223 }
4224#endif
4225
4226 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
4227 {
4228 c = lcs_trail;
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004229 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230 {
4231 n_attr = 1;
4232 extra_attr = hl_attr(HLF_8);
4233 saved_attr2 = char_attr; /* save current attr */
4234 }
4235#ifdef FEAT_MBYTE
4236 mb_c = c;
4237 if (enc_utf8 && (*mb_char2len)(c) > 1)
4238 {
4239 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004240 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004241 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242 }
4243 else
4244 mb_utf8 = FALSE;
4245#endif
4246 }
4247 }
4248
4249 /*
4250 * Handling of non-printable characters.
4251 */
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004252 if (!(chartab[c & 0xff] & CT_PRINT_CHAR))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 {
4254 /*
4255 * when getting a character from the file, we may have to
4256 * turn it into something else on the way to putting it
4257 * into "ScreenLines".
4258 */
4259 if (c == TAB && (!wp->w_p_list || lcs_tab1))
4260 {
4261 /* tab amount depends on current column */
4262 n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar8a20b0f2011-08-10 14:32:39 +02004263 - VCOL_HLC % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264#ifdef FEAT_MBYTE
4265 mb_utf8 = FALSE; /* don't draw as UTF-8 */
4266#endif
4267 if (wp->w_p_list)
4268 {
4269 c = lcs_tab1;
4270 c_extra = lcs_tab2;
4271 n_attr = n_extra + 1;
4272 extra_attr = hl_attr(HLF_8);
4273 saved_attr2 = char_attr; /* save current attr */
4274#ifdef FEAT_MBYTE
4275 mb_c = c;
4276 if (enc_utf8 && (*mb_char2len)(c) > 1)
4277 {
4278 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004279 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004280 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281 }
4282#endif
4283 }
4284 else
4285 {
4286 c_extra = ' ';
4287 c = ' ';
4288 }
4289 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004290 else if (c == NUL
4291 && ((wp->w_p_list && lcs_eol > 0)
4292 || ((fromcol >= 0 || fromcol_prev >= 0)
4293 && tocol > vcol
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004294#ifdef FEAT_VISUAL
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004295 && VIsual_mode != Ctrl_V
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004296#endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004297 && (
4298# ifdef FEAT_RIGHTLEFT
4299 wp->w_p_rl ? (col >= 0) :
4300# endif
4301 (col < W_WIDTH(wp)))
4302 && !(noinvcur
Bram Moolenaarf3205d12009-03-18 18:09:03 +00004303 && lnum == wp->w_cursor.lnum
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004304 && (colnr_T)vcol == wp->w_virtcol)))
4305 && lcs_eol_one >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004307 /* Display a '$' after the line or highlight an extra
4308 * character if the line break is included. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309#if defined(FEAT_DIFF) || defined(LINE_ATTR)
4310 /* For a diff line the highlighting continues after the
4311 * "$". */
4312 if (
4313# ifdef FEAT_DIFF
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00004314 diff_hlf == (hlf_T)0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004315# ifdef LINE_ATTR
4316 &&
4317# endif
4318# endif
4319# ifdef LINE_ATTR
4320 line_attr == 0
4321# endif
4322 )
4323#endif
4324 {
4325#ifdef FEAT_VIRTUALEDIT
4326 /* In virtualedit, visual selections may extend
4327 * beyond end of line. */
4328 if (area_highlighting && virtual_active()
4329 && tocol != MAXCOL && vcol < tocol)
4330 n_extra = 0;
4331 else
4332#endif
4333 {
4334 p_extra = at_end_str;
4335 n_extra = 1;
4336 c_extra = NUL;
4337 }
4338 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004339 if (wp->w_p_list)
4340 c = lcs_eol;
4341 else
4342 c = ' ';
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 lcs_eol_one = -1;
4344 --ptr; /* put it back at the NUL */
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004345 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 {
4347 extra_attr = hl_attr(HLF_AT);
4348 n_attr = 1;
4349 }
4350#ifdef FEAT_MBYTE
4351 mb_c = c;
4352 if (enc_utf8 && (*mb_char2len)(c) > 1)
4353 {
4354 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004355 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004356 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 }
4358 else
4359 mb_utf8 = FALSE; /* don't draw as UTF-8 */
4360#endif
4361 }
4362 else if (c != NUL)
4363 {
4364 p_extra = transchar(c);
4365#ifdef FEAT_RIGHTLEFT
4366 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
4367 rl_mirror(p_extra); /* reverse "<12>" */
4368#endif
4369 n_extra = byte2cells(c) - 1;
4370 c_extra = NUL;
4371 c = *p_extra++;
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004372 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 {
4374 n_attr = n_extra + 1;
4375 extra_attr = hl_attr(HLF_8);
4376 saved_attr2 = char_attr; /* save current attr */
4377 }
4378#ifdef FEAT_MBYTE
4379 mb_utf8 = FALSE; /* don't draw as UTF-8 */
4380#endif
4381 }
4382#ifdef FEAT_VIRTUALEDIT
4383 else if (VIsual_active
4384 && (VIsual_mode == Ctrl_V
4385 || VIsual_mode == 'v')
4386 && virtual_active()
4387 && tocol != MAXCOL
4388 && vcol < tocol
4389 && (
4390# ifdef FEAT_RIGHTLEFT
4391 wp->w_p_rl ? (col >= 0) :
4392# endif
4393 (col < W_WIDTH(wp))))
4394 {
4395 c = ' ';
4396 --ptr; /* put it back at the NUL */
4397 }
4398#endif
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00004399#if defined(LINE_ATTR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004400 else if ((
4401# ifdef FEAT_DIFF
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00004402 diff_hlf != (hlf_T)0 ||
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 line_attr != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 ) && (
4406# ifdef FEAT_RIGHTLEFT
4407 wp->w_p_rl ? (col >= 0) :
4408# endif
Bram Moolenaar2a988a12010-08-13 15:24:39 +02004409 (col
4410# ifdef FEAT_CONCEAL
4411 - boguscols
4412# endif
4413 < W_WIDTH(wp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 {
4415 /* Highlight until the right side of the window */
4416 c = ' ';
4417 --ptr; /* put it back at the NUL */
Bram Moolenaar91170f82006-05-05 21:15:17 +00004418
4419 /* Remember we do the char for line highlighting. */
4420 ++did_line_attr;
4421
4422 /* don't do search HL for the rest of the line */
4423 if (line_attr != 0 && char_attr == search_attr && col > 0)
4424 char_attr = line_attr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425# ifdef FEAT_DIFF
4426 if (diff_hlf == HLF_TXD)
4427 {
4428 diff_hlf = HLF_CHD;
4429 if (attr == 0 || char_attr != attr)
4430 char_attr = hl_attr(diff_hlf);
4431 }
4432# endif
4433 }
4434#endif
4435 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02004436
4437#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004438 if ( wp->w_p_cole > 0
4439 && (wp != curwin || lnum != wp->w_cursor.lnum ||
4440 conceal_cursor_line(wp))
Bram Moolenaarf70e3d62010-07-24 13:15:07 +02004441 && (syntax_flags & HL_CONCEAL) != 0
Bram Moolenaare6dc5732010-07-24 23:52:26 +02004442 && !(lnum_in_visual_area
4443 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
Bram Moolenaar860cae12010-06-05 23:22:07 +02004444 {
4445 char_attr = conceal_attr;
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02004446 if (prev_syntax_id != syntax_seqnr
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004447 && (syn_get_sub_char() != NUL || wp->w_p_cole == 1)
4448 && wp->w_p_cole != 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02004449 {
Bram Moolenaar27c735b2010-07-22 22:16:29 +02004450 /* First time at this concealed item: display one
4451 * character. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02004452 if (syn_get_sub_char() != NUL)
4453 c = syn_get_sub_char();
4454 else if (lcs_conceal != NUL)
4455 c = lcs_conceal;
4456 else
4457 c = ' ';
4458
Bram Moolenaarffbbcb52010-07-24 17:29:03 +02004459 prev_syntax_id = syntax_seqnr;
Bram Moolenaar860cae12010-06-05 23:22:07 +02004460
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004461 if (n_extra > 0)
4462 vcol_off += n_extra;
Bram Moolenaar860cae12010-06-05 23:22:07 +02004463 vcol += n_extra;
4464 if (wp->w_p_wrap && n_extra > 0)
4465 {
4466# ifdef FEAT_RIGHTLEFT
4467 if (wp->w_p_rl)
4468 {
4469 col -= n_extra;
4470 boguscols -= n_extra;
4471 }
4472 else
4473# endif
4474 {
4475 boguscols += n_extra;
4476 col += n_extra;
4477 }
4478 }
4479 n_extra = 0;
4480 n_attr = 0;
4481 }
4482 else if (n_skip == 0)
4483 {
4484 is_concealing = TRUE;
4485 n_skip = 1;
4486 }
4487# ifdef FEAT_MBYTE
4488 mb_c = c;
4489 if (enc_utf8 && (*mb_char2len)(c) > 1)
4490 {
4491 mb_utf8 = TRUE;
4492 u8cc[0] = 0;
4493 c = 0xc0;
4494 }
4495 else
4496 mb_utf8 = FALSE; /* don't draw as UTF-8 */
4497# endif
4498 }
4499 else
4500 {
Bram Moolenaar27c735b2010-07-22 22:16:29 +02004501 prev_syntax_id = 0;
Bram Moolenaarc400cb92010-07-19 19:52:13 +02004502 is_concealing = FALSE;
Bram Moolenaar860cae12010-06-05 23:22:07 +02004503 }
4504#endif /* FEAT_CONCEAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004505 }
4506
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004507#ifdef FEAT_CONCEAL
4508 /* In the cursor line and we may be concealing characters: correct
4509 * the cursor column when we reach its position. */
Bram Moolenaarf691b842010-07-24 13:31:09 +02004510 if (!did_wcol && draw_state == WL_LINE
4511 && wp == curwin && lnum == wp->w_cursor.lnum
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004512 && conceal_cursor_line(wp)
4513 && (int)wp->w_virtcol <= vcol + n_skip)
4514 {
4515 wp->w_wcol = col - boguscols;
Bram Moolenaar72ada0f2010-07-24 17:39:52 +02004516 wp->w_wrow = row;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004517 did_wcol = TRUE;
4518 }
4519#endif
4520
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 /* Don't override visual selection highlighting. */
4522 if (n_attr > 0
4523 && draw_state == WL_LINE
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004524 && !attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004525 char_attr = extra_attr;
4526
Bram Moolenaar81695252004-12-29 20:58:21 +00004527#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004528 /* XIM don't send preedit_start and preedit_end, but they send
4529 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4530 * im_is_preediting() here. */
4531 if (xic != NULL
Bram Moolenaarf3205d12009-03-18 18:09:03 +00004532 && lnum == wp->w_cursor.lnum
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 && (State & INSERT)
4534 && !p_imdisable
4535 && im_is_preediting()
4536 && draw_state == WL_LINE)
4537 {
4538 colnr_T tcol;
4539
4540 if (preedit_end_col == MAXCOL)
Bram Moolenaarf3205d12009-03-18 18:09:03 +00004541 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004542 else
4543 tcol = preedit_end_col;
4544 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
4545 {
4546 if (feedback_old_attr < 0)
4547 {
4548 feedback_col = 0;
4549 feedback_old_attr = char_attr;
4550 }
4551 char_attr = im_get_feedback_attr(feedback_col);
4552 if (char_attr < 0)
4553 char_attr = feedback_old_attr;
4554 feedback_col++;
4555 }
4556 else if (feedback_old_attr >= 0)
4557 {
4558 char_attr = feedback_old_attr;
4559 feedback_old_attr = -1;
4560 feedback_col = 0;
4561 }
4562 }
4563#endif
4564 /*
4565 * Handle the case where we are in column 0 but not on the first
4566 * character of the line and the user wants us to show us a
4567 * special character (via 'listchars' option "precedes:<char>".
4568 */
4569 if (lcs_prec_todo != NUL
4570 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0)
4571#ifdef FEAT_DIFF
4572 && filler_todo <= 0
4573#endif
4574 && draw_state > WL_NR
4575 && c != NUL)
4576 {
4577 c = lcs_prec;
4578 lcs_prec_todo = NUL;
4579#ifdef FEAT_MBYTE
4580 mb_c = c;
4581 if (enc_utf8 && (*mb_char2len)(c) > 1)
4582 {
4583 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004584 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004585 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 }
4587 else
4588 mb_utf8 = FALSE; /* don't draw as UTF-8 */
4589#endif
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00004590 if (!attr_pri)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 {
4592 saved_attr3 = char_attr; /* save current attr */
4593 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */
4594 n_attr3 = 1;
4595 }
4596 }
4597
4598 /*
Bram Moolenaar91170f82006-05-05 21:15:17 +00004599 * At end of the text line or just after the last character.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 */
Bram Moolenaar91170f82006-05-05 21:15:17 +00004601 if (c == NUL
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00004602#if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00004603 || did_line_attr == 1
4604#endif
4605 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004606 {
Bram Moolenaar91170f82006-05-05 21:15:17 +00004607#ifdef FEAT_SEARCH_EXTRA
4608 long prevcol = (long)(ptr - line) - (c == NUL);
Bram Moolenaara443af82007-11-08 13:51:42 +00004609
4610 /* we're not really at that column when skipping some text */
Bram Moolenaar33741a02007-11-08 20:24:19 +00004611 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
Bram Moolenaara443af82007-11-08 13:51:42 +00004612 ++prevcol;
Bram Moolenaar91170f82006-05-05 21:15:17 +00004613#endif
4614
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004615 /* Invert at least one char, used for Visual and empty line or
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616 * highlight match at end of line. If it's beyond the last
4617 * char on the screen, just overwrite that one (tricky!) Not
4618 * needed when a '$' was displayed for 'list'. */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004619#ifdef FEAT_SEARCH_EXTRA
4620 prevcol_hl_flag = FALSE;
4621 if (prevcol == (long)search_hl.startcol)
4622 prevcol_hl_flag = TRUE;
4623 else
4624 {
4625 cur = wp->w_match_head;
4626 while (cur != NULL)
4627 {
4628 if (prevcol == (long)cur->hl.startcol)
4629 {
4630 prevcol_hl_flag = TRUE;
4631 break;
4632 }
4633 cur = cur->next;
4634 }
4635 }
4636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 if (lcs_eol == lcs_eol_one
Bram Moolenaarf3205d12009-03-18 18:09:03 +00004638 && ((area_attr != 0 && vcol == fromcol
4639#ifdef FEAT_VISUAL
4640 && (VIsual_mode != Ctrl_V
4641 || lnum == VIsual.lnum
4642 || lnum == curwin->w_cursor.lnum)
4643#endif
4644 && c == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645#ifdef FEAT_SEARCH_EXTRA
4646 /* highlight 'hlsearch' match at end of line */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004647 || (prevcol_hl_flag == TRUE
Bram Moolenaar6c60ea22006-07-11 20:36:45 +00004648# if defined(LINE_ATTR)
Bram Moolenaar91170f82006-05-05 21:15:17 +00004649 && did_line_attr <= 1
4650# endif
4651 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652#endif
4653 ))
4654 {
4655 int n = 0;
4656
4657#ifdef FEAT_RIGHTLEFT
4658 if (wp->w_p_rl)
4659 {
4660 if (col < 0)
4661 n = 1;
4662 }
4663 else
4664#endif
4665 {
4666 if (col >= W_WIDTH(wp))
4667 n = -1;
4668 }
4669 if (n != 0)
4670 {
4671 /* At the window boundary, highlight the last character
4672 * instead (better than nothing). */
4673 off += n;
4674 col += n;
4675 }
4676 else
4677 {
4678 /* Add a blank character to highlight. */
4679 ScreenLines[off] = ' ';
4680#ifdef FEAT_MBYTE
4681 if (enc_utf8)
4682 ScreenLinesUC[off] = 0;
4683#endif
4684 }
4685#ifdef FEAT_SEARCH_EXTRA
4686 if (area_attr == 0)
4687 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004688 /* Use attributes from match with highest priority among
4689 * 'search_hl' and the match list. */
4690 char_attr = search_hl.attr;
4691 cur = wp->w_match_head;
4692 shl_flag = FALSE;
4693 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004694 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004695 if (shl_flag == FALSE
4696 && ((cur != NULL
4697 && cur->priority > SEARCH_HL_PRIORITY)
4698 || cur == NULL))
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004699 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004700 shl = &search_hl;
4701 shl_flag = TRUE;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004702 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004703 else
4704 shl = &cur->hl;
4705 if ((ptr - line) - 1 == (long)shl->startcol)
4706 char_attr = shl->attr;
4707 if (shl != &search_hl && cur != NULL)
4708 cur = cur->next;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00004709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 }
4711#endif
4712 ScreenAttrs[off] = char_attr;
4713#ifdef FEAT_RIGHTLEFT
4714 if (wp->w_p_rl)
Bram Moolenaara443af82007-11-08 13:51:42 +00004715 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 --col;
Bram Moolenaara443af82007-11-08 13:51:42 +00004717 --off;
4718 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 else
4720#endif
Bram Moolenaara443af82007-11-08 13:51:42 +00004721 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 ++col;
Bram Moolenaara443af82007-11-08 13:51:42 +00004723 ++off;
4724 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004725 ++vcol;
Bram Moolenaara443af82007-11-08 13:51:42 +00004726#ifdef FEAT_SYN_HL
4727 eol_hl_off = 1;
4728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 }
Bram Moolenaar91170f82006-05-05 21:15:17 +00004730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004731
Bram Moolenaar91170f82006-05-05 21:15:17 +00004732 /*
4733 * At end of the text line.
4734 */
4735 if (c == NUL)
4736 {
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004737#ifdef FEAT_SYN_HL
Bram Moolenaarf3205d12009-03-18 18:09:03 +00004738 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol
4739 && lnum == wp->w_cursor.lnum)
Bram Moolenaara443af82007-11-08 13:51:42 +00004740 {
4741 /* highlight last char after line */
4742 --col;
4743 --off;
4744 --vcol;
4745 }
4746
Bram Moolenaar1a384422010-07-14 19:53:30 +02004747 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00004748 if (wp->w_p_wrap)
4749 v = wp->w_skipcol;
4750 else
4751 v = wp->w_leftcol;
Bram Moolenaar1a384422010-07-14 19:53:30 +02004752
Bram Moolenaar8dff8182006-04-06 20:18:50 +00004753 /* check if line ends before left margin */
4754 if (vcol < v + col - win_col_off(wp))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00004755 vcol = v + col - win_col_off(wp);
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004756#ifdef FEAT_CONCEAL
4757 /* Get rid of the boguscols now, we want to draw until the right
4758 * edge for 'cursorcolumn'. */
4759 col -= boguscols;
4760 boguscols = 0;
4761#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02004762
4763 if (draw_color_col)
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004764 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar1a384422010-07-14 19:53:30 +02004765
4766 if (((wp->w_p_cuc
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004767 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
4768 && (int)wp->w_virtcol <
4769 W_WIDTH(wp) * (row - startrow + 1) + v
Bram Moolenaar1a384422010-07-14 19:53:30 +02004770 && lnum != wp->w_cursor.lnum)
4771 || draw_color_col)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004772# ifdef FEAT_RIGHTLEFT
4773 && !wp->w_p_rl
4774# endif
4775 )
4776 {
Bram Moolenaar1a384422010-07-14 19:53:30 +02004777 int rightmost_vcol = 0;
4778 int i;
4779
4780 if (wp->w_p_cuc)
4781 rightmost_vcol = wp->w_virtcol;
4782 if (draw_color_col)
4783 /* determine rightmost colorcolumn to possibly draw */
4784 for (i = 0; color_cols[i] >= 0; ++i)
4785 if (rightmost_vcol < color_cols[i])
4786 rightmost_vcol = color_cols[i];
4787
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004788 while (col < W_WIDTH(wp))
4789 {
4790 ScreenLines[off] = ' ';
4791#ifdef FEAT_MBYTE
4792 if (enc_utf8)
4793 ScreenLinesUC[off] = 0;
4794#endif
4795 ++col;
Bram Moolenaar973bd472010-07-20 11:29:07 +02004796 if (draw_color_col)
4797 draw_color_col = advance_color_col(VCOL_HLC,
4798 &color_cols);
4799
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004800 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar1a384422010-07-14 19:53:30 +02004801 ScreenAttrs[off++] = hl_attr(HLF_CUC);
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004802 else if (draw_color_col && VCOL_HLC == *color_cols)
Bram Moolenaar1a384422010-07-14 19:53:30 +02004803 ScreenAttrs[off++] = hl_attr(HLF_MC);
4804 else
4805 ScreenAttrs[off++] = 0;
4806
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004807 if (VCOL_HLC >= rightmost_vcol)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004808 break;
Bram Moolenaar1a384422010-07-14 19:53:30 +02004809
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004810 ++vcol;
4811 }
4812 }
4813#endif
4814
Bram Moolenaar860cae12010-06-05 23:22:07 +02004815 SCREEN_LINE(screen_row, W_WINCOL(wp), col,
4816 (int)W_WIDTH(wp), wp->w_p_rl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004817 row++;
4818
4819 /*
4820 * Update w_cline_height and w_cline_folded if the cursor line was
4821 * updated (saves a call to plines() later).
4822 */
4823 if (wp == curwin && lnum == curwin->w_cursor.lnum)
4824 {
4825 curwin->w_cline_row = startrow;
4826 curwin->w_cline_height = row - startrow;
4827#ifdef FEAT_FOLDING
4828 curwin->w_cline_folded = FALSE;
4829#endif
4830 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
4831 }
4832
4833 break;
4834 }
4835
4836 /* line continues beyond line end */
4837 if (lcs_ext
4838 && !wp->w_p_wrap
4839#ifdef FEAT_DIFF
4840 && filler_todo <= 0
4841#endif
4842 && (
4843#ifdef FEAT_RIGHTLEFT
4844 wp->w_p_rl ? col == 0 :
4845#endif
4846 col == W_WIDTH(wp) - 1)
4847 && (*ptr != NUL
Bram Moolenaar5bbc21d2008-03-09 13:30:56 +00004848 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004849 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
4850 {
4851 c = lcs_ext;
4852 char_attr = hl_attr(HLF_AT);
4853#ifdef FEAT_MBYTE
4854 mb_c = c;
4855 if (enc_utf8 && (*mb_char2len)(c) > 1)
4856 {
4857 mb_utf8 = TRUE;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004858 u8cc[0] = 0;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004859 c = 0xc0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 }
4861 else
4862 mb_utf8 = FALSE;
4863#endif
4864 }
4865
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004866#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02004867 /* advance to the next 'colorcolumn' */
4868 if (draw_color_col)
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004869 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
Bram Moolenaar1a384422010-07-14 19:53:30 +02004870
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004871 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
Bram Moolenaar1a384422010-07-14 19:53:30 +02004872 * highlight the cursor position itself.
4873 * Also highlight the 'colorcolumn' if it is different than
4874 * 'cursorcolumn' */
4875 vcol_save_attr = -1;
4876 if (draw_state == WL_LINE && !lnum_in_visual_area)
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004877 {
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004878 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
Bram Moolenaar1a384422010-07-14 19:53:30 +02004879 && lnum != wp->w_cursor.lnum)
4880 {
4881 vcol_save_attr = char_attr;
4882 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC));
4883 }
Bram Moolenaard160c342010-07-18 23:30:34 +02004884 else if (draw_color_col && VCOL_HLC == *color_cols)
Bram Moolenaar1a384422010-07-14 19:53:30 +02004885 {
4886 vcol_save_attr = char_attr;
4887 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC));
4888 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004889 }
Bram Moolenaar600dddc2006-03-12 22:05:10 +00004890#endif
4891
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 /*
4893 * Store character to be displayed.
4894 * Skip characters that are left of the screen for 'nowrap'.
4895 */
4896 vcol_prev = vcol;
4897 if (draw_state < WL_LINE || n_skip <= 0)
4898 {
4899 /*
4900 * Store the character.
4901 */
4902#if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4903 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
4904 {
4905 /* A double-wide character is: put first halve in left cell. */
4906 --off;
4907 --col;
4908 }
4909#endif
4910 ScreenLines[off] = c;
4911#ifdef FEAT_MBYTE
4912 if (enc_dbcs == DBCS_JPNU)
Bram Moolenaar990bb662010-02-03 15:48:04 +01004913 {
4914 if ((mb_c & 0xff00) == 0x8e00)
4915 ScreenLines[off] = 0x8e;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 ScreenLines2[off] = mb_c & 0xff;
Bram Moolenaar990bb662010-02-03 15:48:04 +01004917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004918 else if (enc_utf8)
4919 {
4920 if (mb_utf8)
4921 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004922 int i;
4923
Bram Moolenaar071d4272004-06-13 20:20:40 +00004924 ScreenLinesUC[off] = mb_c;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004925 if ((c & 0xff) == 0)
4926 ScreenLines[off] = 0x80; /* avoid storing zero */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00004927 for (i = 0; i < Screen_mco; ++i)
4928 {
4929 ScreenLinesC[i][off] = u8cc[i];
4930 if (u8cc[i] == 0)
4931 break;
4932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004933 }
4934 else
4935 ScreenLinesUC[off] = 0;
4936 }
4937 if (multi_attr)
4938 {
4939 ScreenAttrs[off] = multi_attr;
4940 multi_attr = 0;
4941 }
4942 else
4943#endif
4944 ScreenAttrs[off] = char_attr;
4945
4946#ifdef FEAT_MBYTE
4947 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4948 {
4949 /* Need to fill two screen columns. */
4950 ++off;
4951 ++col;
4952 if (enc_utf8)
4953 /* UTF-8: Put a 0 in the second screen char. */
4954 ScreenLines[off] = 0;
4955 else
4956 /* DBCS: Put second byte in the second screen char. */
4957 ScreenLines[off] = mb_c & 0xff;
4958 ++vcol;
4959 /* When "tocol" is halfway a character, set it to the end of
4960 * the character, otherwise highlighting won't stop. */
4961 if (tocol == vcol)
4962 ++tocol;
4963#ifdef FEAT_RIGHTLEFT
4964 if (wp->w_p_rl)
4965 {
4966 /* now it's time to backup one cell */
4967 --off;
4968 --col;
4969 }
4970#endif
4971 }
4972#endif
4973#ifdef FEAT_RIGHTLEFT
4974 if (wp->w_p_rl)
4975 {
4976 --off;
4977 --col;
4978 }
4979 else
4980#endif
4981 {
4982 ++off;
4983 ++col;
4984 }
4985 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02004986#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02004987 else if (wp->w_p_cole > 0 && is_concealing)
Bram Moolenaar860cae12010-06-05 23:22:07 +02004988 {
4989 --n_skip;
Bram Moolenaarac550fd2010-07-18 13:55:02 +02004990 ++vcol_off;
4991 if (n_extra > 0)
4992 vcol_off += n_extra;
Bram Moolenaar860cae12010-06-05 23:22:07 +02004993 if (wp->w_p_wrap)
4994 {
4995 /*
4996 * Special voodoo required if 'wrap' is on.
4997 *
4998 * Advance the column indicator to force the line
4999 * drawing to wrap early. This will make the line
5000 * take up the same screen space when parts are concealed,
5001 * so that cursor line computations aren't messed up.
5002 *
5003 * To avoid the fictitious advance of 'col' causing
5004 * trailing junk to be written out of the screen line
5005 * we are building, 'boguscols' keeps track of the number
5006 * of bad columns we have advanced.
5007 */
5008 if (n_extra > 0)
5009 {
5010 vcol += n_extra;
5011# ifdef FEAT_RIGHTLEFT
5012 if (wp->w_p_rl)
5013 {
5014 col -= n_extra;
5015 boguscols -= n_extra;
5016 }
5017 else
5018# endif
5019 {
5020 col += n_extra;
5021 boguscols += n_extra;
5022 }
5023 n_extra = 0;
5024 n_attr = 0;
5025 }
5026
5027
5028# ifdef FEAT_MBYTE
5029 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
5030 {
5031 /* Need to fill two screen columns. */
5032# ifdef FEAT_RIGHTLEFT
5033 if (wp->w_p_rl)
5034 {
5035 --boguscols;
5036 --col;
5037 }
5038 else
5039# endif
5040 {
5041 ++boguscols;
5042 ++col;
5043 }
5044 }
5045# endif
5046
5047# ifdef FEAT_RIGHTLEFT
5048 if (wp->w_p_rl)
5049 {
5050 --boguscols;
5051 --col;
5052 }
5053 else
5054# endif
5055 {
5056 ++boguscols;
5057 ++col;
5058 }
5059 }
5060 else
5061 {
5062 if (n_extra > 0)
5063 {
5064 vcol += n_extra;
5065 n_extra = 0;
5066 n_attr = 0;
5067 }
5068 }
5069
5070 }
5071#endif /* FEAT_CONCEAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005072 else
5073 --n_skip;
5074
Bram Moolenaar64486672010-05-16 15:46:46 +02005075 /* Only advance the "vcol" when after the 'number' or 'relativenumber'
5076 * column. */
Bram Moolenaar1b636fa2009-03-18 15:28:08 +00005077 if (draw_state > WL_NR
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078#ifdef FEAT_DIFF
5079 && filler_todo <= 0
5080#endif
5081 )
5082 ++vcol;
5083
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005084#ifdef FEAT_SYN_HL
5085 if (vcol_save_attr >= 0)
5086 char_attr = vcol_save_attr;
5087#endif
5088
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 /* restore attributes after "predeces" in 'listchars' */
5090 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
5091 char_attr = saved_attr3;
5092
5093 /* restore attributes after last 'listchars' or 'number' char */
5094 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
5095 char_attr = saved_attr2;
5096
5097 /*
5098 * At end of screen line and there is more to come: Display the line
Bram Moolenaar367329b2007-08-30 11:53:22 +00005099 * so far. If there is no more to display it is caught above.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 */
5101 if ((
5102#ifdef FEAT_RIGHTLEFT
5103 wp->w_p_rl ? (col < 0) :
5104#endif
5105 (col >= W_WIDTH(wp)))
5106 && (*ptr != NUL
5107#ifdef FEAT_DIFF
5108 || filler_todo > 0
5109#endif
Bram Moolenaare9d4b582011-03-22 13:29:24 +01005110 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
5112 )
5113 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02005114#ifdef FEAT_CONCEAL
5115 SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols,
5116 (int)W_WIDTH(wp), wp->w_p_rl);
5117 boguscols = 0;
5118#else
5119 SCREEN_LINE(screen_row, W_WINCOL(wp), col,
5120 (int)W_WIDTH(wp), wp->w_p_rl);
5121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 ++row;
5123 ++screen_row;
5124
5125 /* When not wrapping and finished diff lines, or when displayed
5126 * '$' and highlighting until last column, break here. */
5127 if ((!wp->w_p_wrap
5128#ifdef FEAT_DIFF
5129 && filler_todo <= 0
5130#endif
5131 ) || lcs_eol_one == -1)
5132 break;
5133
5134 /* When the window is too narrow draw all "@" lines. */
5135 if (draw_state != WL_LINE
5136#ifdef FEAT_DIFF
5137 && filler_todo <= 0
5138#endif
5139 )
5140 {
5141 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT);
5142#ifdef FEAT_VERTSPLIT
5143 draw_vsep_win(wp, row);
5144#endif
5145 row = endrow;
5146 }
5147
5148 /* When line got too long for screen break here. */
5149 if (row == endrow)
5150 {
5151 ++row;
5152 break;
5153 }
5154
5155 if (screen_cur_row == screen_row - 1
5156#ifdef FEAT_DIFF
5157 && filler_todo <= 0
5158#endif
5159 && W_WIDTH(wp) == Columns)
5160 {
5161 /* Remember that the line wraps, used for modeless copy. */
5162 LineWraps[screen_row - 1] = TRUE;
5163
5164 /*
5165 * Special trick to make copy/paste of wrapped lines work with
5166 * xterm/screen: write an extra character beyond the end of
5167 * the line. This will work with all terminal types
5168 * (regardless of the xn,am settings).
5169 * Only do this on a fast tty.
5170 * Only do this if the cursor is on the current line
5171 * (something has been written in it).
5172 * Don't do this for the GUI.
5173 * Don't do this for double-width characters.
5174 * Don't do this for a window not at the right screen border.
5175 */
5176 if (p_tf
5177#ifdef FEAT_GUI
5178 && !gui.in_use
5179#endif
5180#ifdef FEAT_MBYTE
5181 && !(has_mbyte
Bram Moolenaar367329b2007-08-30 11:53:22 +00005182 && ((*mb_off2cells)(LineOffset[screen_row],
5183 LineOffset[screen_row] + screen_Columns)
5184 == 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 || (*mb_off2cells)(LineOffset[screen_row - 1]
Bram Moolenaar367329b2007-08-30 11:53:22 +00005186 + (int)Columns - 2,
5187 LineOffset[screen_row] + screen_Columns)
5188 == 2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189#endif
5190 )
5191 {
5192 /* First make sure we are at the end of the screen line,
5193 * then output the same character again to let the
5194 * terminal know about the wrap. If the terminal doesn't
5195 * auto-wrap, we overwrite the character. */
5196 if (screen_cur_col != W_WIDTH(wp))
5197 screen_char(LineOffset[screen_row - 1]
5198 + (unsigned)Columns - 1,
5199 screen_row - 1, (int)(Columns - 1));
5200
5201#ifdef FEAT_MBYTE
5202 /* When there is a multi-byte character, just output a
5203 * space to keep it simple. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005204 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
5205 screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 out_char(' ');
5207 else
5208#endif
5209 out_char(ScreenLines[LineOffset[screen_row - 1]
5210 + (Columns - 1)]);
5211 /* force a redraw of the first char on the next line */
5212 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
5213 screen_start(); /* don't know where cursor is now */
5214 }
5215 }
5216
5217 col = 0;
5218 off = (unsigned)(current_ScreenLine - ScreenLines);
5219#ifdef FEAT_RIGHTLEFT
5220 if (wp->w_p_rl)
5221 {
5222 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */
5223 off += col;
5224 }
5225#endif
5226
5227 /* reset the drawing state for the start of a wrapped line */
5228 draw_state = WL_START;
5229 saved_n_extra = n_extra;
5230 saved_p_extra = p_extra;
5231 saved_c_extra = c_extra;
5232 saved_char_attr = char_attr;
5233 n_extra = 0;
5234 lcs_prec_todo = lcs_prec;
5235#ifdef FEAT_LINEBREAK
5236# ifdef FEAT_DIFF
5237 if (filler_todo <= 0)
5238# endif
5239 need_showbreak = TRUE;
5240#endif
5241#ifdef FEAT_DIFF
5242 --filler_todo;
5243 /* When the filler lines are actually below the last line of the
5244 * file, don't draw the line itself, break here. */
5245 if (filler_todo == 0 && wp->w_botfill)
5246 break;
5247#endif
5248 }
5249
5250 } /* for every character in the line */
5251
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005252#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005253 /* After an empty line check first word for capital. */
5254 if (*skipwhite(line) == NUL)
5255 {
5256 capcol_lnum = lnum + 1;
5257 cap_col = 0;
5258 }
5259#endif
5260
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 return row;
5262}
5263
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005264#ifdef FEAT_MBYTE
5265static int comp_char_differs __ARGS((int, int));
5266
5267/*
5268 * Return if the composing characters at "off_from" and "off_to" differ.
Bram Moolenaar70c49c12010-03-23 15:36:35 +01005269 * Only to be used when ScreenLinesUC[off_from] != 0.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005270 */
5271 static int
5272comp_char_differs(off_from, off_to)
5273 int off_from;
5274 int off_to;
5275{
5276 int i;
5277
5278 for (i = 0; i < Screen_mco; ++i)
5279 {
5280 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to])
5281 return TRUE;
5282 if (ScreenLinesC[i][off_from] == 0)
5283 break;
5284 }
5285 return FALSE;
5286}
5287#endif
5288
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289/*
5290 * Check whether the given character needs redrawing:
5291 * - the (first byte of the) character is different
5292 * - the attributes are different
5293 * - the character is multi-byte and the next byte is different
Bram Moolenaar88f3d3a2008-06-21 12:14:30 +00005294 * - the character is two cells wide and the second cell differs.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295 */
5296 static int
5297char_needs_redraw(off_from, off_to, cols)
5298 int off_from;
5299 int off_to;
5300 int cols;
5301{
5302 if (cols > 0
5303 && ((ScreenLines[off_from] != ScreenLines[off_to]
5304 || ScreenAttrs[off_from] != ScreenAttrs[off_to])
5305
5306#ifdef FEAT_MBYTE
5307 || (enc_dbcs != 0
5308 && MB_BYTE2LEN(ScreenLines[off_from]) > 1
5309 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e
5310 ? ScreenLines2[off_from] != ScreenLines2[off_to]
5311 : (cols > 1 && ScreenLines[off_from + 1]
5312 != ScreenLines[off_to + 1])))
5313 || (enc_utf8
5314 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to]
5315 || (ScreenLinesUC[off_from] != 0
Bram Moolenaar88f3d3a2008-06-21 12:14:30 +00005316 && comp_char_differs(off_from, off_to))
5317 || (cols > 1 && ScreenLines[off_from + 1]
5318 != ScreenLines[off_to + 1])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319#endif
5320 ))
5321 return TRUE;
5322 return FALSE;
5323}
5324
5325/*
5326 * Move one "cooked" screen line to the screen, but only the characters that
5327 * have actually changed. Handle insert/delete character.
5328 * "coloff" gives the first column on the screen for this line.
5329 * "endcol" gives the columns where valid characters are.
5330 * "clear_width" is the width of the window. It's > 0 if the rest of the line
5331 * needs to be cleared, negative otherwise.
5332 * "rlflag" is TRUE in a rightleft window:
5333 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
5334 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
5335 */
5336 static void
5337screen_line(row, coloff, endcol, clear_width
5338#ifdef FEAT_RIGHTLEFT
5339 , rlflag
5340#endif
5341 )
5342 int row;
5343 int coloff;
5344 int endcol;
5345 int clear_width;
5346#ifdef FEAT_RIGHTLEFT
5347 int rlflag;
5348#endif
5349{
5350 unsigned off_from;
5351 unsigned off_to;
Bram Moolenaar367329b2007-08-30 11:53:22 +00005352#ifdef FEAT_MBYTE
5353 unsigned max_off_from;
5354 unsigned max_off_to;
5355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 int col = 0;
5357#if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
5358 int hl;
5359#endif
5360 int force = FALSE; /* force update rest of the line */
5361 int redraw_this /* bool: does character need redraw? */
5362#ifdef FEAT_GUI
5363 = TRUE /* For GUI when while-loop empty */
5364#endif
5365 ;
5366 int redraw_next; /* redraw_this for next character */
5367#ifdef FEAT_MBYTE
5368 int clear_next = FALSE;
5369 int char_cells; /* 1: normal char */
5370 /* 2: occupies two display cells */
5371# define CHAR_CELLS char_cells
5372#else
5373# define CHAR_CELLS 1
5374#endif
5375
Bram Moolenaar5ad15df2012-03-16 19:07:58 +01005376 /* Check for illegal row and col, just in case. */
5377 if (row >= Rows)
5378 row = Rows - 1;
5379 if (endcol > Columns)
5380 endcol = Columns;
5381
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382# ifdef FEAT_CLIPBOARD
5383 clip_may_clear_selection(row, row);
5384# endif
5385
5386 off_from = (unsigned)(current_ScreenLine - ScreenLines);
5387 off_to = LineOffset[row] + coloff;
Bram Moolenaar367329b2007-08-30 11:53:22 +00005388#ifdef FEAT_MBYTE
5389 max_off_from = off_from + screen_Columns;
5390 max_off_to = LineOffset[row] + screen_Columns;
5391#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392
5393#ifdef FEAT_RIGHTLEFT
5394 if (rlflag)
5395 {
5396 /* Clear rest first, because it's left of the text. */
5397 if (clear_width > 0)
5398 {
5399 while (col <= endcol && ScreenLines[off_to] == ' '
5400 && ScreenAttrs[off_to] == 0
5401# ifdef FEAT_MBYTE
5402 && (!enc_utf8 || ScreenLinesUC[off_to] == 0)
5403# endif
5404 )
5405 {
5406 ++off_to;
5407 ++col;
5408 }
5409 if (col <= endcol)
5410 screen_fill(row, row + 1, col + coloff,
5411 endcol + coloff + 1, ' ', ' ', 0);
5412 }
5413 col = endcol + 1;
5414 off_to = LineOffset[row] + col + coloff;
5415 off_from += col;
5416 endcol = (clear_width > 0 ? clear_width : -clear_width);
5417 }
5418#endif /* FEAT_RIGHTLEFT */
5419
5420 redraw_next = char_needs_redraw(off_from, off_to, endcol - col);
5421
5422 while (col < endcol)
5423 {
5424#ifdef FEAT_MBYTE
5425 if (has_mbyte && (col + 1 < endcol))
Bram Moolenaar367329b2007-08-30 11:53:22 +00005426 char_cells = (*mb_off2cells)(off_from, max_off_from);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427 else
5428 char_cells = 1;
5429#endif
5430
5431 redraw_this = redraw_next;
5432 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS,
5433 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS);
5434
5435#ifdef FEAT_GUI
5436 /* If the next character was bold, then redraw the current character to
5437 * remove any pixels that might have spilt over into us. This only
5438 * happens in the GUI.
5439 */
5440 if (redraw_next && gui.in_use)
5441 {
5442 hl = ScreenAttrs[off_to + CHAR_CELLS];
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005443 if (hl > HL_ALL)
5444 hl = syn_attr2attr(hl);
5445 if (hl & HL_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446 redraw_this = TRUE;
5447 }
5448#endif
5449
5450 if (redraw_this)
5451 {
5452 /*
5453 * Special handling when 'xs' termcap flag set (hpterm):
5454 * Attributes for characters are stored at the position where the
5455 * cursor is when writing the highlighting code. The
5456 * start-highlighting code must be written with the cursor on the
5457 * first highlighted character. The stop-highlighting code must
5458 * be written with the cursor just after the last highlighted
5459 * character.
5460 * Overwriting a character doesn't remove it's highlighting. Need
5461 * to clear the rest of the line, and force redrawing it
5462 * completely.
5463 */
5464 if ( p_wiv
5465 && !force
5466#ifdef FEAT_GUI
5467 && !gui.in_use
5468#endif
5469 && ScreenAttrs[off_to] != 0
5470 && ScreenAttrs[off_from] != ScreenAttrs[off_to])
5471 {
5472 /*
5473 * Need to remove highlighting attributes here.
5474 */
5475 windgoto(row, col + coloff);
5476 out_str(T_CE); /* clear rest of this screen line */
5477 screen_start(); /* don't know where cursor is now */
5478 force = TRUE; /* force redraw of rest of the line */
5479 redraw_next = TRUE; /* or else next char would miss out */
5480
5481 /*
5482 * If the previous character was highlighted, need to stop
5483 * highlighting at this character.
5484 */
5485 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0)
5486 {
5487 screen_attr = ScreenAttrs[off_to - 1];
5488 term_windgoto(row, col + coloff);
5489 screen_stop_highlight();
5490 }
5491 else
5492 screen_attr = 0; /* highlighting has stopped */
5493 }
5494#ifdef FEAT_MBYTE
5495 if (enc_dbcs != 0)
5496 {
5497 /* Check if overwriting a double-byte with a single-byte or
5498 * the other way around requires another character to be
5499 * redrawn. For UTF-8 this isn't needed, because comparing
5500 * ScreenLinesUC[] is sufficient. */
5501 if (char_cells == 1
5502 && col + 1 < endcol
Bram Moolenaar367329b2007-08-30 11:53:22 +00005503 && (*mb_off2cells)(off_to, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504 {
5505 /* Writing a single-cell character over a double-cell
5506 * character: need to redraw the next cell. */
5507 ScreenLines[off_to + 1] = 0;
5508 redraw_next = TRUE;
5509 }
5510 else if (char_cells == 2
5511 && col + 2 < endcol
Bram Moolenaar367329b2007-08-30 11:53:22 +00005512 && (*mb_off2cells)(off_to, max_off_to) == 1
5513 && (*mb_off2cells)(off_to + 1, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514 {
5515 /* Writing the second half of a double-cell character over
5516 * a double-cell character: need to redraw the second
5517 * cell. */
5518 ScreenLines[off_to + 2] = 0;
5519 redraw_next = TRUE;
5520 }
5521
5522 if (enc_dbcs == DBCS_JPNU)
5523 ScreenLines2[off_to] = ScreenLines2[off_from];
5524 }
5525 /* When writing a single-width character over a double-width
5526 * character and at the end of the redrawn text, need to clear out
5527 * the right halve of the old character.
5528 * Also required when writing the right halve of a double-width
5529 * char over the left halve of an existing one. */
5530 if (has_mbyte && col + char_cells == endcol
5531 && ((char_cells == 1
Bram Moolenaar367329b2007-08-30 11:53:22 +00005532 && (*mb_off2cells)(off_to, max_off_to) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 || (char_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00005534 && (*mb_off2cells)(off_to, max_off_to) == 1
5535 && (*mb_off2cells)(off_to + 1, max_off_to) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536 clear_next = TRUE;
5537#endif
5538
5539 ScreenLines[off_to] = ScreenLines[off_from];
5540#ifdef FEAT_MBYTE
5541 if (enc_utf8)
5542 {
5543 ScreenLinesUC[off_to] = ScreenLinesUC[off_from];
5544 if (ScreenLinesUC[off_from] != 0)
5545 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005546 int i;
5547
5548 for (i = 0; i < Screen_mco; ++i)
5549 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from];
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 }
5551 }
5552 if (char_cells == 2)
5553 ScreenLines[off_to + 1] = ScreenLines[off_from + 1];
5554#endif
5555
5556#if defined(FEAT_GUI) || defined(UNIX)
Bram Moolenaar2bea2912009-03-11 16:58:40 +00005557 /* The bold trick makes a single column of pixels appear in the
5558 * next character. When a bold character is removed, the next
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 * character should be redrawn too. This happens for our own GUI
5560 * and for some xterms. */
5561 if (
5562# ifdef FEAT_GUI
5563 gui.in_use
5564# endif
5565# if defined(FEAT_GUI) && defined(UNIX)
5566 ||
5567# endif
5568# ifdef UNIX
5569 term_is_xterm
5570# endif
5571 )
5572 {
5573 hl = ScreenAttrs[off_to];
Bram Moolenaar600dddc2006-03-12 22:05:10 +00005574 if (hl > HL_ALL)
5575 hl = syn_attr2attr(hl);
5576 if (hl & HL_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577 redraw_next = TRUE;
5578 }
5579#endif
5580 ScreenAttrs[off_to] = ScreenAttrs[off_from];
5581#ifdef FEAT_MBYTE
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005582 /* For simplicity set the attributes of second half of a
5583 * double-wide character equal to the first half. */
5584 if (char_cells == 2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from];
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005586
5587 if (enc_dbcs != 0 && char_cells == 2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588 screen_char_2(off_to, row, col + coloff);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 else
5590#endif
5591 screen_char(off_to, row, col + coloff);
5592 }
5593 else if ( p_wiv
5594#ifdef FEAT_GUI
5595 && !gui.in_use
5596#endif
5597 && col + coloff > 0)
5598 {
5599 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1])
5600 {
5601 /*
5602 * Don't output stop-highlight when moving the cursor, it will
5603 * stop the highlighting when it should continue.
5604 */
5605 screen_attr = 0;
5606 }
5607 else if (screen_attr != 0)
5608 screen_stop_highlight();
5609 }
5610
5611 off_to += CHAR_CELLS;
5612 off_from += CHAR_CELLS;
5613 col += CHAR_CELLS;
5614 }
5615
5616#ifdef FEAT_MBYTE
5617 if (clear_next)
5618 {
5619 /* Clear the second half of a double-wide character of which the left
5620 * half was overwritten with a single-wide character. */
5621 ScreenLines[off_to] = ' ';
5622 if (enc_utf8)
5623 ScreenLinesUC[off_to] = 0;
5624 screen_char(off_to, row, col + coloff);
5625 }
5626#endif
5627
5628 if (clear_width > 0
5629#ifdef FEAT_RIGHTLEFT
5630 && !rlflag
5631#endif
5632 )
5633 {
5634#ifdef FEAT_GUI
5635 int startCol = col;
5636#endif
5637
5638 /* blank out the rest of the line */
5639 while (col < clear_width && ScreenLines[off_to] == ' '
5640 && ScreenAttrs[off_to] == 0
5641#ifdef FEAT_MBYTE
5642 && (!enc_utf8 || ScreenLinesUC[off_to] == 0)
5643#endif
5644 )
5645 {
5646 ++off_to;
5647 ++col;
5648 }
5649 if (col < clear_width)
5650 {
5651#ifdef FEAT_GUI
5652 /*
5653 * In the GUI, clearing the rest of the line may leave pixels
5654 * behind if the first character cleared was bold. Some bold
5655 * fonts spill over the left. In this case we redraw the previous
5656 * character too. If we didn't skip any blanks above, then we
5657 * only redraw if the character wasn't already redrawn anyway.
5658 */
Bram Moolenaar9c697322006-10-09 20:11:17 +00005659 if (gui.in_use && (col > startCol || !redraw_this))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660 {
5661 hl = ScreenAttrs[off_to];
5662 if (hl > HL_ALL || (hl & HL_BOLD))
Bram Moolenaar9c697322006-10-09 20:11:17 +00005663 {
5664 int prev_cells = 1;
5665# ifdef FEAT_MBYTE
5666 if (enc_utf8)
5667 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5668 * that its width is 2. */
5669 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1;
5670 else if (enc_dbcs != 0)
5671 {
5672 /* find previous character by counting from first
5673 * column and get its width. */
5674 unsigned off = LineOffset[row];
Bram Moolenaar367329b2007-08-30 11:53:22 +00005675 unsigned max_off = LineOffset[row] + screen_Columns;
Bram Moolenaar9c697322006-10-09 20:11:17 +00005676
5677 while (off < off_to)
5678 {
Bram Moolenaar367329b2007-08-30 11:53:22 +00005679 prev_cells = (*mb_off2cells)(off, max_off);
Bram Moolenaar9c697322006-10-09 20:11:17 +00005680 off += prev_cells;
5681 }
5682 }
5683
5684 if (enc_dbcs != 0 && prev_cells > 1)
5685 screen_char_2(off_to - prev_cells, row,
5686 col + coloff - prev_cells);
5687 else
5688# endif
5689 screen_char(off_to - prev_cells, row,
5690 col + coloff - prev_cells);
5691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692 }
5693#endif
5694 screen_fill(row, row + 1, col + coloff, clear_width + coloff,
5695 ' ', ' ', 0);
5696#ifdef FEAT_VERTSPLIT
5697 off_to += clear_width - col;
5698 col = clear_width;
5699#endif
5700 }
5701 }
5702
5703 if (clear_width > 0)
5704 {
5705#ifdef FEAT_VERTSPLIT
5706 /* For a window that's left of another, draw the separator char. */
5707 if (col + coloff < Columns)
5708 {
5709 int c;
5710
5711 c = fillchar_vsep(&hl);
5712 if (ScreenLines[off_to] != c
5713# ifdef FEAT_MBYTE
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005714 || (enc_utf8 && (int)ScreenLinesUC[off_to]
5715 != (c >= 0x80 ? c : 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716# endif
5717 || ScreenAttrs[off_to] != hl)
5718 {
5719 ScreenLines[off_to] = c;
5720 ScreenAttrs[off_to] = hl;
5721# ifdef FEAT_MBYTE
5722 if (enc_utf8)
5723 {
5724 if (c >= 0x80)
5725 {
5726 ScreenLinesUC[off_to] = c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005727 ScreenLinesC[0][off_to] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 }
5729 else
5730 ScreenLinesUC[off_to] = 0;
5731 }
5732# endif
5733 screen_char(off_to, row, col + coloff);
5734 }
5735 }
5736 else
5737#endif
5738 LineWraps[row] = FALSE;
5739 }
5740}
5741
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005742#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743/*
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005744 * Mirror text "str" for right-left displaying.
5745 * Only works for single-byte characters (e.g., numbers).
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746 */
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005747 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748rl_mirror(str)
5749 char_u *str;
5750{
5751 char_u *p1, *p2;
5752 int t;
5753
5754 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2)
5755 {
5756 t = *p1;
5757 *p1 = *p2;
5758 *p2 = t;
5759 }
5760}
5761#endif
5762
5763#if defined(FEAT_WINDOWS) || defined(PROTO)
5764/*
5765 * mark all status lines for redraw; used after first :cd
5766 */
5767 void
5768status_redraw_all()
5769{
5770 win_T *wp;
5771
5772 for (wp = firstwin; wp; wp = wp->w_next)
5773 if (wp->w_status_height)
5774 {
5775 wp->w_redr_status = TRUE;
5776 redraw_later(VALID);
5777 }
5778}
5779
5780/*
5781 * mark all status lines of the current buffer for redraw
5782 */
5783 void
5784status_redraw_curbuf()
5785{
5786 win_T *wp;
5787
5788 for (wp = firstwin; wp; wp = wp->w_next)
5789 if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
5790 {
5791 wp->w_redr_status = TRUE;
5792 redraw_later(VALID);
5793 }
5794}
5795
5796/*
5797 * Redraw all status lines that need to be redrawn.
5798 */
5799 void
5800redraw_statuslines()
5801{
5802 win_T *wp;
5803
5804 for (wp = firstwin; wp; wp = wp->w_next)
5805 if (wp->w_redr_status)
5806 win_redr_status(wp);
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00005807 if (redraw_tabline)
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00005808 draw_tabline();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809}
5810#endif
5811
5812#if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5813/*
5814 * Redraw all status lines at the bottom of frame "frp".
5815 */
5816 void
5817win_redraw_last_status(frp)
5818 frame_T *frp;
5819{
5820 if (frp->fr_layout == FR_LEAF)
5821 frp->fr_win->w_redr_status = TRUE;
5822 else if (frp->fr_layout == FR_ROW)
5823 {
5824 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next)
5825 win_redraw_last_status(frp);
5826 }
5827 else /* frp->fr_layout == FR_COL */
5828 {
5829 frp = frp->fr_child;
5830 while (frp->fr_next != NULL)
5831 frp = frp->fr_next;
5832 win_redraw_last_status(frp);
5833 }
5834}
5835#endif
5836
5837#ifdef FEAT_VERTSPLIT
5838/*
5839 * Draw the verticap separator right of window "wp" starting with line "row".
5840 */
5841 static void
5842draw_vsep_win(wp, row)
5843 win_T *wp;
5844 int row;
5845{
5846 int hl;
5847 int c;
5848
5849 if (wp->w_vsep_width)
5850 {
5851 /* draw the vertical separator right of this window */
5852 c = fillchar_vsep(&hl);
5853 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
5854 W_ENDCOL(wp), W_ENDCOL(wp) + 1,
5855 c, ' ', hl);
5856 }
5857}
5858#endif
5859
5860#ifdef FEAT_WILDMENU
5861static int status_match_len __ARGS((expand_T *xp, char_u *s));
Bram Moolenaar35c54e52005-05-20 21:25:31 +00005862static int skip_status_match_char __ARGS((expand_T *xp, char_u *s));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863
5864/*
Bram Moolenaar367329b2007-08-30 11:53:22 +00005865 * Get the length of an item as it will be shown in the status line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 */
5867 static int
5868status_match_len(xp, s)
5869 expand_T *xp;
5870 char_u *s;
5871{
5872 int len = 0;
5873
5874#ifdef FEAT_MENU
5875 int emenu = (xp->xp_context == EXPAND_MENUS
5876 || xp->xp_context == EXPAND_MENUNAMES);
5877
5878 /* Check for menu separators - replace with '|'. */
5879 if (emenu && menu_is_separator(s))
5880 return 1;
5881#endif
5882
5883 while (*s != NUL)
5884 {
Bram Moolenaar7693ec62008-07-24 18:29:37 +00005885 s += skip_status_match_char(xp, s);
Bram Moolenaar81695252004-12-29 20:58:21 +00005886 len += ptr2cells(s);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005887 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005888 }
5889
5890 return len;
5891}
5892
5893/*
Bram Moolenaar7693ec62008-07-24 18:29:37 +00005894 * Return the number of characters that should be skipped in a status match.
Bram Moolenaar35c54e52005-05-20 21:25:31 +00005895 * These are backslashes used for escaping. Do show backslashes in help tags.
5896 */
5897 static int
5898skip_status_match_char(xp, s)
5899 expand_T *xp;
5900 char_u *s;
5901{
Bram Moolenaar7693ec62008-07-24 18:29:37 +00005902 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP)
Bram Moolenaar35c54e52005-05-20 21:25:31 +00005903#ifdef FEAT_MENU
5904 || ((xp->xp_context == EXPAND_MENUS
5905 || xp->xp_context == EXPAND_MENUNAMES)
5906 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL)))
5907#endif
Bram Moolenaar7693ec62008-07-24 18:29:37 +00005908 )
5909 {
5910#ifndef BACKSLASH_IN_FILENAME
5911 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!')
5912 return 2;
5913#endif
5914 return 1;
5915 }
5916 return 0;
Bram Moolenaar35c54e52005-05-20 21:25:31 +00005917}
5918
5919/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 * Show wildchar matches in the status line.
5921 * Show at least the "match" item.
5922 * We start at item 'first_match' in the list and show all matches that fit.
5923 *
5924 * If inversion is possible we use it. Else '=' characters are used.
5925 */
5926 void
5927win_redr_status_matches(xp, num_matches, matches, match, showtail)
5928 expand_T *xp;
5929 int num_matches;
5930 char_u **matches; /* list of matches */
5931 int match;
5932 int showtail;
5933{
5934#define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5935 int row;
5936 char_u *buf;
5937 int len;
Bram Moolenaar367329b2007-08-30 11:53:22 +00005938 int clen; /* length in screen cells */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 int fillchar;
5940 int attr;
5941 int i;
5942 int highlight = TRUE;
5943 char_u *selstart = NULL;
5944 int selstart_col = 0;
5945 char_u *selend = NULL;
5946 static int first_match = 0;
5947 int add_left = FALSE;
5948 char_u *s;
5949#ifdef FEAT_MENU
5950 int emenu;
5951#endif
5952#if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5953 int l;
5954#endif
5955
5956 if (matches == NULL) /* interrupted completion? */
5957 return;
5958
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005959#ifdef FEAT_MBYTE
5960 if (has_mbyte)
5961 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1);
5962 else
5963#endif
5964 buf = alloc((unsigned)Columns + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 if (buf == NULL)
5966 return;
5967
5968 if (match == -1) /* don't show match but original text */
5969 {
5970 match = 0;
5971 highlight = FALSE;
5972 }
5973 /* count 1 for the ending ">" */
5974 clen = status_match_len(xp, L_MATCH(match)) + 3;
5975 if (match == 0)
5976 first_match = 0;
5977 else if (match < first_match)
5978 {
5979 /* jumping left, as far as we can go */
5980 first_match = match;
5981 add_left = TRUE;
5982 }
5983 else
5984 {
5985 /* check if match fits on the screen */
5986 for (i = first_match; i < match; ++i)
5987 clen += status_match_len(xp, L_MATCH(i)) + 2;
5988 if (first_match > 0)
5989 clen += 2;
5990 /* jumping right, put match at the left */
5991 if ((long)clen > Columns)
5992 {
5993 first_match = match;
5994 /* if showing the last match, we can add some on the left */
5995 clen = 2;
5996 for (i = match; i < num_matches; ++i)
5997 {
5998 clen += status_match_len(xp, L_MATCH(i)) + 2;
5999 if ((long)clen >= Columns)
6000 break;
6001 }
6002 if (i == num_matches)
6003 add_left = TRUE;
6004 }
6005 }
6006 if (add_left)
6007 while (first_match > 0)
6008 {
6009 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2;
6010 if ((long)clen >= Columns)
6011 break;
6012 --first_match;
6013 }
6014
6015 fillchar = fillchar_status(&attr, TRUE);
6016
6017 if (first_match == 0)
6018 {
6019 *buf = NUL;
6020 len = 0;
6021 }
6022 else
6023 {
6024 STRCPY(buf, "< ");
6025 len = 2;
6026 }
6027 clen = len;
6028
6029 i = first_match;
6030 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns)
6031 {
6032 if (i == match)
6033 {
6034 selstart = buf + len;
6035 selstart_col = clen;
6036 }
6037
6038 s = L_MATCH(i);
6039 /* Check for menu separators - replace with '|' */
6040#ifdef FEAT_MENU
6041 emenu = (xp->xp_context == EXPAND_MENUS
6042 || xp->xp_context == EXPAND_MENUNAMES);
6043 if (emenu && menu_is_separator(s))
6044 {
6045 STRCPY(buf + len, transchar('|'));
6046 l = (int)STRLEN(buf + len);
6047 len += l;
6048 clen += l;
6049 }
6050 else
6051#endif
6052 for ( ; *s != NUL; ++s)
6053 {
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006054 s += skip_status_match_char(xp, s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 clen += ptr2cells(s);
6056#ifdef FEAT_MBYTE
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006057 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 {
6059 STRNCPY(buf + len, s, l);
6060 s += l - 1;
6061 len += l;
6062 }
6063 else
6064#endif
6065 {
6066 STRCPY(buf + len, transchar_byte(*s));
6067 len += (int)STRLEN(buf + len);
6068 }
6069 }
6070 if (i == match)
6071 selend = buf + len;
6072
6073 *(buf + len++) = ' ';
6074 *(buf + len++) = ' ';
6075 clen += 2;
6076 if (++i == num_matches)
6077 break;
6078 }
6079
6080 if (i != num_matches)
6081 {
6082 *(buf + len++) = '>';
6083 ++clen;
6084 }
6085
6086 buf[len] = NUL;
6087
6088 row = cmdline_row - 1;
6089 if (row >= 0)
6090 {
6091 if (wild_menu_showing == 0)
6092 {
6093 if (msg_scrolled > 0)
6094 {
6095 /* Put the wildmenu just above the command line. If there is
6096 * no room, scroll the screen one line up. */
6097 if (cmdline_row == Rows - 1)
6098 {
6099 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL);
6100 ++msg_scrolled;
6101 }
6102 else
6103 {
6104 ++cmdline_row;
6105 ++row;
6106 }
6107 wild_menu_showing = WM_SCROLLED;
6108 }
6109 else
6110 {
6111 /* Create status line if needed by setting 'laststatus' to 2.
6112 * Set 'winminheight' to zero to avoid that the window is
6113 * resized. */
6114 if (lastwin->w_status_height == 0)
6115 {
6116 save_p_ls = p_ls;
6117 save_p_wmh = p_wmh;
6118 p_ls = 2;
6119 p_wmh = 0;
6120 last_status(FALSE);
6121 }
6122 wild_menu_showing = WM_SHOWN;
6123 }
6124 }
6125
6126 screen_puts(buf, row, 0, attr);
6127 if (selstart != NULL && highlight)
6128 {
6129 *selend = NUL;
6130 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM));
6131 }
6132
6133 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr);
6134 }
6135
6136#ifdef FEAT_VERTSPLIT
6137 win_redraw_last_status(topframe);
6138#else
6139 lastwin->w_redr_status = TRUE;
6140#endif
6141 vim_free(buf);
6142}
6143#endif
6144
6145#if defined(FEAT_WINDOWS) || defined(PROTO)
6146/*
6147 * Redraw the status line of window wp.
6148 *
6149 * If inversion is possible we use it. Else '=' characters are used.
6150 */
6151 void
6152win_redr_status(wp)
6153 win_T *wp;
6154{
6155 int row;
6156 char_u *p;
6157 int len;
6158 int fillchar;
6159 int attr;
6160 int this_ru_col;
Bram Moolenaaradb09c22009-06-16 15:22:12 +00006161 static int busy = FALSE;
6162
6163 /* It's possible to get here recursively when 'statusline' (indirectly)
6164 * invokes ":redrawstatus". Simply ignore the call then. */
6165 if (busy)
6166 return;
6167 busy = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168
6169 wp->w_redr_status = FALSE;
6170 if (wp->w_status_height == 0)
6171 {
6172 /* no status line, can only be last window */
6173 redraw_cmdline = TRUE;
6174 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006175 else if (!redrawing()
6176#ifdef FEAT_INS_EXPAND
6177 /* don't update status line when popup menu is visible and may be
6178 * drawn over it */
6179 || pum_visible()
6180#endif
6181 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00006182 {
6183 /* Don't redraw right now, do it later. */
6184 wp->w_redr_status = TRUE;
6185 }
6186#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006187 else if (*p_stl != NUL || *wp->w_p_stl != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 {
6189 /* redraw custom status line */
Bram Moolenaar362f3562009-11-03 16:20:34 +00006190 redraw_custom_statusline(wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191 }
6192#endif
6193 else
6194 {
6195 fillchar = fillchar_status(&attr, wp == curwin);
6196
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006197 get_trans_bufname(wp->w_buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198 p = NameBuff;
6199 len = (int)STRLEN(p);
6200
6201 if (wp->w_buffer->b_help
6202#ifdef FEAT_QUICKFIX
6203 || wp->w_p_pvw
6204#endif
6205 || bufIsChanged(wp->w_buffer)
6206 || wp->w_buffer->b_p_ro)
6207 *(p + len++) = ' ';
6208 if (wp->w_buffer->b_help)
6209 {
Bram Moolenaar899dddf2006-03-26 21:06:50 +00006210 STRCPY(p + len, _("[Help]"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006211 len += (int)STRLEN(p + len);
6212 }
6213#ifdef FEAT_QUICKFIX
6214 if (wp->w_p_pvw)
6215 {
6216 STRCPY(p + len, _("[Preview]"));
6217 len += (int)STRLEN(p + len);
6218 }
6219#endif
6220 if (bufIsChanged(wp->w_buffer))
6221 {
6222 STRCPY(p + len, "[+]");
6223 len += 3;
6224 }
6225 if (wp->w_buffer->b_p_ro)
6226 {
6227 STRCPY(p + len, "[RO]");
6228 len += 4;
6229 }
6230
6231#ifndef FEAT_VERTSPLIT
6232 this_ru_col = ru_col;
6233 if (this_ru_col < (Columns + 1) / 2)
6234 this_ru_col = (Columns + 1) / 2;
6235#else
6236 this_ru_col = ru_col - (Columns - W_WIDTH(wp));
6237 if (this_ru_col < (W_WIDTH(wp) + 1) / 2)
6238 this_ru_col = (W_WIDTH(wp) + 1) / 2;
6239 if (this_ru_col <= 1)
6240 {
6241 p = (char_u *)"<"; /* No room for file name! */
6242 len = 1;
6243 }
6244 else
6245#endif
6246#ifdef FEAT_MBYTE
6247 if (has_mbyte)
6248 {
6249 int clen = 0, i;
6250
6251 /* Count total number of display cells. */
Bram Moolenaar72597a52010-07-18 15:31:08 +02006252 clen = mb_string2cells(p, -1);
6253
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 /* Find first character that will fit.
6255 * Going from start to end is much faster for DBCS. */
6256 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006257 i += (*mb_ptr2len)(p + i))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 clen -= (*mb_ptr2cells)(p + i);
6259 len = clen;
6260 if (i > 0)
6261 {
6262 p = p + i - 1;
6263 *p = '<';
6264 ++len;
6265 }
6266
6267 }
6268 else
6269#endif
6270 if (len > this_ru_col - 1)
6271 {
6272 p += len - (this_ru_col - 1);
6273 *p = '<';
6274 len = this_ru_col - 1;
6275 }
6276
6277 row = W_WINROW(wp) + wp->w_height;
6278 screen_puts(p, row, W_WINCOL(wp), attr);
6279 screen_fill(row, row + 1, len + W_WINCOL(wp),
6280 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr);
6281
6282 if (get_keymap_str(wp, NameBuff, MAXPATHL)
6283 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1))
6284 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff)
6285 - 1 + W_WINCOL(wp)), attr);
6286
6287#ifdef FEAT_CMDL_INFO
6288 win_redr_ruler(wp, TRUE);
6289#endif
6290 }
6291
6292#ifdef FEAT_VERTSPLIT
6293 /*
6294 * May need to draw the character below the vertical separator.
6295 */
6296 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing())
6297 {
6298 if (stl_connected(wp))
6299 fillchar = fillchar_status(&attr, wp == curwin);
6300 else
6301 fillchar = fillchar_vsep(&attr);
6302 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp),
6303 attr);
6304 }
6305#endif
Bram Moolenaaradb09c22009-06-16 15:22:12 +00006306 busy = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307}
6308
Bram Moolenaar238a5642006-02-21 22:12:05 +00006309#ifdef FEAT_STL_OPT
6310/*
6311 * Redraw the status line according to 'statusline' and take care of any
6312 * errors encountered.
6313 */
6314 static void
Bram Moolenaar362f3562009-11-03 16:20:34 +00006315redraw_custom_statusline(wp)
Bram Moolenaar238a5642006-02-21 22:12:05 +00006316 win_T *wp;
6317{
Bram Moolenaar362f3562009-11-03 16:20:34 +00006318 static int entered = FALSE;
6319 int save_called_emsg = called_emsg;
6320
6321 /* When called recursively return. This can happen when the statusline
6322 * contains an expression that triggers a redraw. */
6323 if (entered)
6324 return;
6325 entered = TRUE;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006326
6327 called_emsg = FALSE;
6328 win_redr_custom(wp, FALSE);
6329 if (called_emsg)
Bram Moolenaar362f3562009-11-03 16:20:34 +00006330 {
6331 /* When there is an error disable the statusline, otherwise the
6332 * display is messed up with errors and a redraw triggers the problem
6333 * again and again. */
Bram Moolenaar238a5642006-02-21 22:12:05 +00006334 set_string_option_direct((char_u *)"statusline", -1,
6335 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006336 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
Bram Moolenaar362f3562009-11-03 16:20:34 +00006337 }
Bram Moolenaar238a5642006-02-21 22:12:05 +00006338 called_emsg |= save_called_emsg;
Bram Moolenaar362f3562009-11-03 16:20:34 +00006339 entered = FALSE;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006340}
6341#endif
6342
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343# ifdef FEAT_VERTSPLIT
6344/*
6345 * Return TRUE if the status line of window "wp" is connected to the status
6346 * line of the window right of it. If not, then it's a vertical separator.
6347 * Only call if (wp->w_vsep_width != 0).
6348 */
6349 int
6350stl_connected(wp)
6351 win_T *wp;
6352{
6353 frame_T *fr;
6354
6355 fr = wp->w_frame;
6356 while (fr->fr_parent != NULL)
6357 {
6358 if (fr->fr_parent->fr_layout == FR_COL)
6359 {
6360 if (fr->fr_next != NULL)
6361 break;
6362 }
6363 else
6364 {
6365 if (fr->fr_next != NULL)
6366 return TRUE;
6367 }
6368 fr = fr->fr_parent;
6369 }
6370 return FALSE;
6371}
6372# endif
6373
6374#endif /* FEAT_WINDOWS */
6375
6376#if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
6377/*
6378 * Get the value to show for the language mappings, active 'keymap'.
6379 */
6380 int
6381get_keymap_str(wp, buf, len)
6382 win_T *wp;
6383 char_u *buf; /* buffer for the result */
6384 int len; /* length of buffer */
6385{
6386 char_u *p;
6387
6388 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP)
6389 return FALSE;
6390
6391 {
6392#ifdef FEAT_EVAL
6393 buf_T *old_curbuf = curbuf;
6394 win_T *old_curwin = curwin;
6395 char_u *s;
6396
6397 curbuf = wp->w_buffer;
6398 curwin = wp;
6399 STRCPY(buf, "b:keymap_name"); /* must be writable */
6400 ++emsg_skip;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006401 s = p = eval_to_string(buf, NULL, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 --emsg_skip;
6403 curbuf = old_curbuf;
6404 curwin = old_curwin;
6405 if (p == NULL || *p == NUL)
6406#endif
6407 {
6408#ifdef FEAT_KEYMAP
6409 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED)
6410 p = wp->w_buffer->b_p_keymap;
6411 else
6412#endif
6413 p = (char_u *)"lang";
6414 }
6415 if ((int)(STRLEN(p) + 3) < len)
6416 sprintf((char *)buf, "<%s>", p);
6417 else
6418 buf[0] = NUL;
6419#ifdef FEAT_EVAL
6420 vim_free(s);
6421#endif
6422 }
6423 return buf[0] != NUL;
6424}
6425#endif
6426
6427#if defined(FEAT_STL_OPT) || defined(PROTO)
6428/*
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006429 * Redraw the status line or ruler of window "wp".
6430 * When "wp" is NULL redraw the tab pages line from 'tabline'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 */
6432 static void
Bram Moolenaar9372a112005-12-06 19:59:18 +00006433win_redr_custom(wp, draw_ruler)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006434 win_T *wp;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006435 int draw_ruler; /* TRUE or FALSE */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436{
6437 int attr;
6438 int curattr;
6439 int row;
6440 int col = 0;
6441 int maxwidth;
6442 int width;
6443 int n;
6444 int len;
6445 int fillchar;
6446 char_u buf[MAXPATHL];
Bram Moolenaar362f3562009-11-03 16:20:34 +00006447 char_u *stl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 char_u *p;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006449 struct stl_hlrec hltab[STL_MAX_ITEM];
6450 struct stl_hlrec tabtab[STL_MAX_ITEM];
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006451 int use_sandbox = FALSE;
Bram Moolenaar61452852011-02-01 18:01:11 +01006452 win_T *ewp;
6453 int p_crb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454
6455 /* setup environment for the task at hand */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006456 if (wp == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006457 {
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006458 /* Use 'tabline'. Always at the first line of the screen. */
Bram Moolenaar362f3562009-11-03 16:20:34 +00006459 stl = p_tal;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006460 row = 0;
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006461 fillchar = ' ';
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006462 attr = hl_attr(HLF_TPF);
6463 maxwidth = Columns;
6464# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006465 use_sandbox = was_set_insecurely((char_u *)"tabline", 0);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006466# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006468 else
6469 {
6470 row = W_WINROW(wp) + wp->w_height;
6471 fillchar = fillchar_status(&attr, wp == curwin);
6472 maxwidth = W_WIDTH(wp);
6473
6474 if (draw_ruler)
6475 {
Bram Moolenaar362f3562009-11-03 16:20:34 +00006476 stl = p_ruf;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006477 /* advance past any leading group spec - implicit in ru_col */
Bram Moolenaar362f3562009-11-03 16:20:34 +00006478 if (*stl == '%')
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006479 {
Bram Moolenaar362f3562009-11-03 16:20:34 +00006480 if (*++stl == '-')
6481 stl++;
6482 if (atoi((char *)stl))
6483 while (VIM_ISDIGIT(*stl))
6484 stl++;
6485 if (*stl++ != '(')
6486 stl = p_ruf;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006487 }
6488#ifdef FEAT_VERTSPLIT
6489 col = ru_col - (Columns - W_WIDTH(wp));
6490 if (col < (W_WIDTH(wp) + 1) / 2)
6491 col = (W_WIDTH(wp) + 1) / 2;
6492#else
6493 col = ru_col;
6494 if (col > (Columns + 1) / 2)
6495 col = (Columns + 1) / 2;
6496#endif
6497 maxwidth = W_WIDTH(wp) - col;
6498#ifdef FEAT_WINDOWS
6499 if (!wp->w_status_height)
6500#endif
6501 {
6502 row = Rows - 1;
6503 --maxwidth; /* writing in last column may cause scrolling */
6504 fillchar = ' ';
6505 attr = 0;
6506 }
6507
6508# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006509 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006510# endif
6511 }
6512 else
6513 {
6514 if (*wp->w_p_stl != NUL)
Bram Moolenaar362f3562009-11-03 16:20:34 +00006515 stl = wp->w_p_stl;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006516 else
Bram Moolenaar362f3562009-11-03 16:20:34 +00006517 stl = p_stl;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006518# ifdef FEAT_EVAL
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006519 use_sandbox = was_set_insecurely((char_u *)"statusline",
6520 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006521# endif
6522 }
6523
6524#ifdef FEAT_VERTSPLIT
6525 col += W_WINCOL(wp);
6526#endif
6527 }
6528
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 if (maxwidth <= 0)
6530 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531
Bram Moolenaar61452852011-02-01 18:01:11 +01006532 /* Temporarily reset 'cursorbind', we don't want a side effect from moving
6533 * the cursor away and back. */
6534 ewp = wp == NULL ? curwin : wp;
6535 p_crb_save = ewp->w_p_crb;
6536 ewp->w_p_crb = FALSE;
6537
Bram Moolenaar362f3562009-11-03 16:20:34 +00006538 /* Make a copy, because the statusline may include a function call that
6539 * might change the option value and free the memory. */
6540 stl = vim_strsave(stl);
Bram Moolenaar61452852011-02-01 18:01:11 +01006541 width = build_stl_str_hl(ewp, buf, sizeof(buf),
Bram Moolenaar362f3562009-11-03 16:20:34 +00006542 stl, use_sandbox,
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006543 fillchar, maxwidth, hltab, tabtab);
Bram Moolenaar362f3562009-11-03 16:20:34 +00006544 vim_free(stl);
Bram Moolenaar61452852011-02-01 18:01:11 +01006545 ewp->w_p_crb = p_crb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546
Bram Moolenaar7c5676b2010-12-08 19:56:58 +01006547 /* Make all characters printable. */
6548 p = transstr(buf);
6549 if (p != NULL)
6550 {
6551 vim_strncpy(buf, p, sizeof(buf) - 1);
6552 vim_free(p);
6553 }
6554
6555 /* fill up with "fillchar" */
6556 len = (int)STRLEN(buf);
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00006557 while (width < maxwidth && len < (int)sizeof(buf) - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558 {
6559#ifdef FEAT_MBYTE
6560 len += (*mb_char2bytes)(fillchar, buf + len);
6561#else
6562 buf[len++] = fillchar;
6563#endif
6564 ++width;
6565 }
6566 buf[len] = NUL;
6567
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006568 /*
6569 * Draw each snippet with the specified highlighting.
6570 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 curattr = attr;
6572 p = buf;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006573 for (n = 0; hltab[n].start != NULL; n++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 {
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006575 len = (int)(hltab[n].start - p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 screen_puts_len(p, len, row, col, curattr);
6577 col += vim_strnsize(p, len);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006578 p = hltab[n].start;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006580 if (hltab[n].userhl == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 curattr = attr;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006582 else if (hltab[n].userhl < 0)
6583 curattr = syn_id2attr(-hltab[n].userhl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006584#ifdef FEAT_WINDOWS
Bram Moolenaar238a5642006-02-21 22:12:05 +00006585 else if (wp != NULL && wp != curwin && wp->w_status_height != 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006586 curattr = highlight_stlnc[hltab[n].userhl - 1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587#endif
6588 else
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006589 curattr = highlight_user[hltab[n].userhl - 1];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 }
6591 screen_puts(p, row, col, curattr);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006592
6593 if (wp == NULL)
6594 {
6595 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6596 col = 0;
6597 len = 0;
6598 p = buf;
6599 fillchar = 0;
6600 for (n = 0; tabtab[n].start != NULL; n++)
6601 {
6602 len += vim_strnsize(p, (int)(tabtab[n].start - p));
6603 while (col < len)
6604 TabPageIdxs[col++] = fillchar;
6605 p = tabtab[n].start;
6606 fillchar = tabtab[n].userhl;
6607 }
6608 while (col < Columns)
6609 TabPageIdxs[col++] = fillchar;
6610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611}
6612
6613#endif /* FEAT_STL_OPT */
6614
6615/*
6616 * Output a single character directly to the screen and update ScreenLines.
6617 */
6618 void
6619screen_putchar(c, row, col, attr)
6620 int c;
6621 int row, col;
6622 int attr;
6623{
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 char_u buf[MB_MAXBYTES + 1];
6625
Bram Moolenaar9a920d82012-06-01 15:21:02 +02006626#ifdef FEAT_MBYTE
6627 if (has_mbyte)
6628 buf[(*mb_char2bytes)(c, buf)] = NUL;
6629 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006630#endif
Bram Moolenaar9a920d82012-06-01 15:21:02 +02006631 {
6632 buf[0] = c;
6633 buf[1] = NUL;
6634 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 screen_puts(buf, row, col, attr);
6636}
6637
6638/*
6639 * Get a single character directly from ScreenLines into "bytes[]".
6640 * Also return its attribute in *attrp;
6641 */
6642 void
6643screen_getbytes(row, col, bytes, attrp)
6644 int row, col;
6645 char_u *bytes;
6646 int *attrp;
6647{
6648 unsigned off;
6649
6650 /* safety check */
6651 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns)
6652 {
6653 off = LineOffset[row] + col;
6654 *attrp = ScreenAttrs[off];
6655 bytes[0] = ScreenLines[off];
6656 bytes[1] = NUL;
6657
6658#ifdef FEAT_MBYTE
6659 if (enc_utf8 && ScreenLinesUC[off] != 0)
6660 bytes[utfc_char2bytes(off, bytes)] = NUL;
6661 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
6662 {
6663 bytes[0] = ScreenLines[off];
6664 bytes[1] = ScreenLines2[off];
6665 bytes[2] = NUL;
6666 }
6667 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1)
6668 {
6669 bytes[1] = ScreenLines[off + 1];
6670 bytes[2] = NUL;
6671 }
6672#endif
6673 }
6674}
6675
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006676#ifdef FEAT_MBYTE
6677static int screen_comp_differs __ARGS((int, int*));
6678
6679/*
6680 * Return TRUE if composing characters for screen posn "off" differs from
6681 * composing characters in "u8cc".
Bram Moolenaar70c49c12010-03-23 15:36:35 +01006682 * Only to be used when ScreenLinesUC[off] != 0.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006683 */
6684 static int
6685screen_comp_differs(off, u8cc)
6686 int off;
6687 int *u8cc;
6688{
6689 int i;
6690
6691 for (i = 0; i < Screen_mco; ++i)
6692 {
6693 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i])
6694 return TRUE;
6695 if (u8cc[i] == 0)
6696 break;
6697 }
6698 return FALSE;
6699}
6700#endif
6701
Bram Moolenaar071d4272004-06-13 20:20:40 +00006702/*
6703 * Put string '*text' on the screen at position 'row' and 'col', with
6704 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6705 * Note: only outputs within one row, message is truncated at screen boundary!
6706 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6707 */
6708 void
6709screen_puts(text, row, col, attr)
6710 char_u *text;
6711 int row;
6712 int col;
6713 int attr;
6714{
6715 screen_puts_len(text, -1, row, col, attr);
6716}
6717
6718/*
6719 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6720 * a NUL.
6721 */
6722 void
6723screen_puts_len(text, len, row, col, attr)
6724 char_u *text;
6725 int len;
6726 int row;
6727 int col;
6728 int attr;
6729{
6730 unsigned off;
6731 char_u *ptr = text;
6732 int c;
6733#ifdef FEAT_MBYTE
Bram Moolenaar367329b2007-08-30 11:53:22 +00006734 unsigned max_off;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735 int mbyte_blen = 1;
6736 int mbyte_cells = 1;
6737 int u8c = 0;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006738 int u8cc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739 int clear_next_cell = FALSE;
6740# ifdef FEAT_ARABIC
6741 int prev_c = 0; /* previous Arabic character */
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006742 int pc, nc, nc1;
6743 int pcc[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006744# endif
6745#endif
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006746#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6747 int force_redraw_this;
6748 int force_redraw_next = FALSE;
6749#endif
6750 int need_redraw;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751
6752 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */
6753 return;
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006754 off = LineOffset[row] + col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755
Bram Moolenaarc236c162008-07-13 17:41:49 +00006756#ifdef FEAT_MBYTE
6757 /* When drawing over the right halve of a double-wide char clear out the
6758 * left halve. Only needed in a terminal. */
Bram Moolenaar7693ec62008-07-24 18:29:37 +00006759 if (has_mbyte && col > 0 && col < screen_Columns
Bram Moolenaarc236c162008-07-13 17:41:49 +00006760# ifdef FEAT_GUI
6761 && !gui.in_use
6762# endif
6763 && mb_fix_col(col, row) != col)
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006764 {
6765 ScreenLines[off - 1] = ' ';
6766 ScreenAttrs[off - 1] = 0;
6767 if (enc_utf8)
6768 {
6769 ScreenLinesUC[off - 1] = 0;
6770 ScreenLinesC[0][off - 1] = 0;
6771 }
6772 /* redraw the previous cell, make it empty */
6773 screen_char(off - 1, row, col - 1);
6774 /* force the cell at "col" to be redrawn */
6775 force_redraw_next = TRUE;
6776 }
Bram Moolenaarc236c162008-07-13 17:41:49 +00006777#endif
6778
Bram Moolenaar367329b2007-08-30 11:53:22 +00006779#ifdef FEAT_MBYTE
6780 max_off = LineOffset[row] + screen_Columns;
6781#endif
Bram Moolenaara064ac82007-08-05 18:10:54 +00006782 while (col < screen_Columns
6783 && (len < 0 || (int)(ptr - text) < len)
6784 && *ptr != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 {
6786 c = *ptr;
6787#ifdef FEAT_MBYTE
6788 /* check if this is the first byte of a multibyte */
6789 if (has_mbyte)
6790 {
6791 if (enc_utf8 && len > 0)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006792 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 else
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00006794 mbyte_blen = (*mb_ptr2len)(ptr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 if (enc_dbcs == DBCS_JPNU && c == 0x8e)
6796 mbyte_cells = 1;
6797 else if (enc_dbcs != 0)
6798 mbyte_cells = mbyte_blen;
6799 else /* enc_utf8 */
6800 {
6801 if (len >= 0)
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006802 u8c = utfc_ptr2char_len(ptr, u8cc,
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803 (int)((text + len) - ptr));
6804 else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006805 u8c = utfc_ptr2char(ptr, u8cc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006806 mbyte_cells = utf_char2cells(u8c);
Bram Moolenaar11936362007-09-17 20:39:42 +00006807# ifdef UNICODE16
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808 /* Non-BMP character: display as ? or fullwidth ?. */
6809 if (u8c >= 0x10000)
6810 {
6811 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?';
6812 if (attr == 0)
6813 attr = hl_attr(HLF_8);
6814 }
Bram Moolenaar11936362007-09-17 20:39:42 +00006815# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816# ifdef FEAT_ARABIC
6817 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
6818 {
6819 /* Do Arabic shaping. */
6820 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len)
6821 {
6822 /* Past end of string to be displayed. */
6823 nc = NUL;
6824 nc1 = NUL;
6825 }
6826 else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006827 {
Bram Moolenaar54620182009-11-11 16:07:20 +00006828 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc,
6829 (int)((text + len) - ptr - mbyte_blen));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006830 nc1 = pcc[0];
6831 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006832 pc = prev_c;
6833 prev_c = u8c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006834 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 }
6836 else
6837 prev_c = u8c;
6838# endif
Bram Moolenaare4ebd292010-01-19 17:40:46 +01006839 if (col + mbyte_cells > screen_Columns)
6840 {
6841 /* Only 1 cell left, but character requires 2 cells:
6842 * display a '>' in the last column to avoid wrapping. */
6843 c = '>';
6844 mbyte_cells = 1;
6845 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006846 }
6847 }
6848#endif
6849
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006850#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6851 force_redraw_this = force_redraw_next;
6852 force_redraw_next = FALSE;
6853#endif
6854
6855 need_redraw = ScreenLines[off] != c
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856#ifdef FEAT_MBYTE
6857 || (mbyte_cells == 2
6858 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0))
6859 || (enc_dbcs == DBCS_JPNU
6860 && c == 0x8e
6861 && ScreenLines2[off] != ptr[1])
6862 || (enc_utf8
Bram Moolenaar70c49c12010-03-23 15:36:35 +01006863 && (ScreenLinesUC[off] !=
6864 (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c)
6865 || (ScreenLinesUC[off] != 0
6866 && screen_comp_differs(off, u8cc))))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867#endif
6868 || ScreenAttrs[off] != attr
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006869 || exmode_active;
6870
6871 if (need_redraw
6872#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6873 || force_redraw_this
6874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 )
6876 {
6877#if defined(FEAT_GUI) || defined(UNIX)
6878 /* The bold trick makes a single row of pixels appear in the next
6879 * character. When a bold character is removed, the next
6880 * character should be redrawn too. This happens for our own GUI
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006881 * and for some xterms. */
6882 if (need_redraw && ScreenLines[off] != ' ' && (
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883# ifdef FEAT_GUI
6884 gui.in_use
6885# endif
6886# if defined(FEAT_GUI) && defined(UNIX)
6887 ||
6888# endif
6889# ifdef UNIX
6890 term_is_xterm
6891# endif
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006892 ))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 {
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006894 int n = ScreenAttrs[off];
Bram Moolenaar071d4272004-06-13 20:20:40 +00006895
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006896 if (n > HL_ALL)
6897 n = syn_attr2attr(n);
6898 if (n & HL_BOLD)
6899 force_redraw_next = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006900 }
6901#endif
6902#ifdef FEAT_MBYTE
6903 /* When at the end of the text and overwriting a two-cell
6904 * character with a one-cell character, need to clear the next
6905 * cell. Also when overwriting the left halve of a two-cell char
6906 * with the right halve of a two-cell char. Do this only once
6907 * (mb_off2cells() may return 2 on the right halve). */
6908 if (clear_next_cell)
6909 clear_next_cell = FALSE;
6910 else if (has_mbyte
6911 && (len < 0 ? ptr[mbyte_blen] == NUL
6912 : ptr + mbyte_blen >= text + len)
Bram Moolenaar367329b2007-08-30 11:53:22 +00006913 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914 || (mbyte_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00006915 && (*mb_off2cells)(off, max_off) == 1
6916 && (*mb_off2cells)(off + 1, max_off) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 clear_next_cell = TRUE;
6918
6919 /* Make sure we never leave a second byte of a double-byte behind,
6920 * it confuses mb_off2cells(). */
6921 if (enc_dbcs
Bram Moolenaar367329b2007-08-30 11:53:22 +00006922 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 || (mbyte_cells == 2
Bram Moolenaar367329b2007-08-30 11:53:22 +00006924 && (*mb_off2cells)(off, max_off) == 1
6925 && (*mb_off2cells)(off + 1, max_off) > 1)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006926 ScreenLines[off + mbyte_blen] = 0;
6927#endif
6928 ScreenLines[off] = c;
6929 ScreenAttrs[off] = attr;
6930#ifdef FEAT_MBYTE
6931 if (enc_utf8)
6932 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006933 if (c < 0x80 && u8cc[0] == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 ScreenLinesUC[off] = 0;
6935 else
6936 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006937 int i;
6938
Bram Moolenaar071d4272004-06-13 20:20:40 +00006939 ScreenLinesUC[off] = u8c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006940 for (i = 0; i < Screen_mco; ++i)
6941 {
6942 ScreenLinesC[i][off] = u8cc[i];
6943 if (u8cc[i] == 0)
6944 break;
6945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947 if (mbyte_cells == 2)
6948 {
6949 ScreenLines[off + 1] = 0;
6950 ScreenAttrs[off + 1] = attr;
6951 }
6952 screen_char(off, row, col);
6953 }
6954 else if (mbyte_cells == 2)
6955 {
6956 ScreenLines[off + 1] = ptr[1];
6957 ScreenAttrs[off + 1] = attr;
6958 screen_char_2(off, row, col);
6959 }
6960 else if (enc_dbcs == DBCS_JPNU && c == 0x8e)
6961 {
6962 ScreenLines2[off] = ptr[1];
6963 screen_char(off, row, col);
6964 }
6965 else
6966#endif
6967 screen_char(off, row, col);
6968 }
6969#ifdef FEAT_MBYTE
6970 if (has_mbyte)
6971 {
6972 off += mbyte_cells;
6973 col += mbyte_cells;
6974 ptr += mbyte_blen;
6975 if (clear_next_cell)
6976 ptr = (char_u *)" ";
6977 }
6978 else
6979#endif
6980 {
6981 ++off;
6982 ++col;
6983 ++ptr;
6984 }
6985 }
Bram Moolenaar2bea2912009-03-11 16:58:40 +00006986
6987#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6988 /* If we detected the next character needs to be redrawn, but the text
6989 * doesn't extend up to there, update the character here. */
6990 if (force_redraw_next && col < screen_Columns)
6991 {
6992# ifdef FEAT_MBYTE
6993 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1)
6994 screen_char_2(off, row, col);
6995 else
6996# endif
6997 screen_char(off, row, col);
6998 }
6999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000}
7001
7002#ifdef FEAT_SEARCH_EXTRA
7003/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007004 * Prepare for 'hlsearch' highlighting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005 */
7006 static void
7007start_search_hl()
7008{
7009 if (p_hls && !no_hlsearch)
7010 {
7011 last_pat_prog(&search_hl.rm);
7012 search_hl.attr = hl_attr(HLF_L);
Bram Moolenaar91a4e822008-01-19 14:59:58 +00007013# ifdef FEAT_RELTIME
7014 /* Set the time limit to 'redrawtime'. */
7015 profile_setlimit(p_rdt, &search_hl.tm);
7016# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 }
7018}
7019
7020/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007021 * Clean up for 'hlsearch' highlighting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 */
7023 static void
7024end_search_hl()
7025{
7026 if (search_hl.rm.regprog != NULL)
7027 {
7028 vim_free(search_hl.rm.regprog);
7029 search_hl.rm.regprog = NULL;
7030 }
7031}
7032
7033/*
Bram Moolenaar0af8ceb2010-07-05 22:22:57 +02007034 * Init for calling prepare_search_hl().
7035 */
7036 static void
7037init_search_hl(wp)
7038 win_T *wp;
7039{
7040 matchitem_T *cur;
7041
7042 /* Setup for match and 'hlsearch' highlighting. Disable any previous
7043 * match */
7044 cur = wp->w_match_head;
7045 while (cur != NULL)
7046 {
7047 cur->hl.rm = cur->match;
7048 if (cur->hlg_id == 0)
7049 cur->hl.attr = 0;
7050 else
7051 cur->hl.attr = syn_id2attr(cur->hlg_id);
7052 cur->hl.buf = wp->w_buffer;
7053 cur->hl.lnum = 0;
7054 cur->hl.first_lnum = 0;
7055# ifdef FEAT_RELTIME
7056 /* Set the time limit to 'redrawtime'. */
7057 profile_setlimit(p_rdt, &(cur->hl.tm));
7058# endif
7059 cur = cur->next;
7060 }
7061 search_hl.buf = wp->w_buffer;
7062 search_hl.lnum = 0;
7063 search_hl.first_lnum = 0;
7064 /* time limit is set at the toplevel, for all windows */
7065}
7066
7067/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068 * Advance to the match in window "wp" line "lnum" or past it.
7069 */
7070 static void
7071prepare_search_hl(wp, lnum)
7072 win_T *wp;
7073 linenr_T lnum;
7074{
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007075 matchitem_T *cur; /* points to the match list */
7076 match_T *shl; /* points to search_hl or a match */
7077 int shl_flag; /* flag to indicate whether search_hl
7078 has been processed or not */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 int n;
7080
7081 /*
7082 * When using a multi-line pattern, start searching at the top
7083 * of the window or just after a closed fold.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007084 * Do this both for search_hl and the match list.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 */
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007086 cur = wp->w_match_head;
7087 shl_flag = FALSE;
7088 while (cur != NULL || shl_flag == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007090 if (shl_flag == FALSE)
7091 {
7092 shl = &search_hl;
7093 shl_flag = TRUE;
7094 }
7095 else
7096 shl = &cur->hl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 if (shl->rm.regprog != NULL
7098 && shl->lnum == 0
7099 && re_multiline(shl->rm.regprog))
7100 {
7101 if (shl->first_lnum == 0)
7102 {
7103# ifdef FEAT_FOLDING
7104 for (shl->first_lnum = lnum;
7105 shl->first_lnum > wp->w_topline; --shl->first_lnum)
7106 if (hasFoldingWin(wp, shl->first_lnum - 1,
7107 NULL, NULL, TRUE, NULL))
7108 break;
7109# else
7110 shl->first_lnum = wp->w_topline;
7111# endif
7112 }
7113 n = 0;
7114 while (shl->first_lnum < lnum && shl->rm.regprog != NULL)
7115 {
7116 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n);
7117 if (shl->lnum != 0)
7118 {
7119 shl->first_lnum = shl->lnum
7120 + shl->rm.endpos[0].lnum
7121 - shl->rm.startpos[0].lnum;
7122 n = shl->rm.endpos[0].col;
7123 }
7124 else
7125 {
7126 ++shl->first_lnum;
7127 n = 0;
7128 }
7129 }
7130 }
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007131 if (shl != &search_hl && cur != NULL)
7132 cur = cur->next;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 }
7134}
7135
7136/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007137 * Search for a next 'hlsearch' or match.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 * Uses shl->buf.
7139 * Sets shl->lnum and shl->rm contents.
7140 * Note: Assumes a previous match is always before "lnum", unless
7141 * shl->lnum is zero.
7142 * Careful: Any pointers for buffer lines will become invalid.
7143 */
7144 static void
7145next_search_hl(win, shl, lnum, mincol)
7146 win_T *win;
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007147 match_T *shl; /* points to search_hl or a match */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 linenr_T lnum;
7149 colnr_T mincol; /* minimal column for a match */
7150{
7151 linenr_T l;
7152 colnr_T matchcol;
7153 long nmatched;
7154
7155 if (shl->lnum != 0)
7156 {
7157 /* Check for three situations:
7158 * 1. If the "lnum" is below a previous match, start a new search.
7159 * 2. If the previous match includes "mincol", use it.
7160 * 3. Continue after the previous match.
7161 */
7162 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
7163 if (lnum > l)
7164 shl->lnum = 0;
7165 else if (lnum < l || shl->rm.endpos[0].col > mincol)
7166 return;
7167 }
7168
7169 /*
7170 * Repeat searching for a match until one is found that includes "mincol"
7171 * or none is found in this line.
7172 */
7173 called_emsg = FALSE;
7174 for (;;)
7175 {
Bram Moolenaar91a4e822008-01-19 14:59:58 +00007176#ifdef FEAT_RELTIME
7177 /* Stop searching after passing the time limit. */
7178 if (profile_passed_limit(&(shl->tm)))
7179 {
7180 shl->lnum = 0; /* no match found in time */
7181 break;
7182 }
7183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 /* Three situations:
7185 * 1. No useful previous match: search from start of line.
7186 * 2. Not Vi compatible or empty match: continue at next character.
7187 * Break the loop if this is beyond the end of the line.
7188 * 3. Vi compatible searching: continue at end of previous match.
7189 */
7190 if (shl->lnum == 0)
7191 matchcol = 0;
7192 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL
7193 || (shl->rm.endpos[0].lnum == 0
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007194 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195 {
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007196 char_u *ml;
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007197
7198 matchcol = shl->rm.startpos[0].col;
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007199 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol;
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007200 if (*ml == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 {
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007202 ++matchcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 shl->lnum = 0;
7204 break;
7205 }
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007206#ifdef FEAT_MBYTE
7207 if (has_mbyte)
7208 matchcol += mb_ptr2len(ml);
7209 else
7210#endif
7211 ++matchcol;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 }
7213 else
7214 matchcol = shl->rm.endpos[0].col;
7215
7216 shl->lnum = lnum;
Bram Moolenaar91a4e822008-01-19 14:59:58 +00007217 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol,
7218#ifdef FEAT_RELTIME
7219 &(shl->tm)
7220#else
7221 NULL
7222#endif
7223 );
Bram Moolenaarc7040a52010-07-20 13:11:28 +02007224 if (called_emsg || got_int)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007225 {
7226 /* Error while handling regexp: stop using this regexp. */
Bram Moolenaar0ddf0a72007-05-01 20:04:53 +00007227 if (shl == &search_hl)
7228 {
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007229 /* don't free regprog in the match list, it's a copy */
Bram Moolenaar0ddf0a72007-05-01 20:04:53 +00007230 vim_free(shl->rm.regprog);
7231 no_hlsearch = TRUE;
7232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007233 shl->rm.regprog = NULL;
Bram Moolenaar0ddf0a72007-05-01 20:04:53 +00007234 shl->lnum = 0;
7235 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236 break;
7237 }
7238 if (nmatched == 0)
7239 {
7240 shl->lnum = 0; /* no match found */
7241 break;
7242 }
7243 if (shl->rm.startpos[0].lnum > 0
7244 || shl->rm.startpos[0].col >= mincol
7245 || nmatched > 1
7246 || shl->rm.endpos[0].col > mincol)
7247 {
7248 shl->lnum += shl->rm.startpos[0].lnum;
7249 break; /* useful match found */
7250 }
7251 }
7252}
7253#endif
7254
7255 static void
7256screen_start_highlight(attr)
7257 int attr;
7258{
7259 attrentry_T *aep = NULL;
7260
7261 screen_attr = attr;
7262 if (full_screen
7263#ifdef WIN3264
7264 && termcap_active
7265#endif
7266 )
7267 {
7268#ifdef FEAT_GUI
7269 if (gui.in_use)
7270 {
7271 char buf[20];
7272
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007273 /* The GUI handles this internally. */
7274 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 OUT_STR(buf);
7276 }
7277 else
7278#endif
7279 {
7280 if (attr > HL_ALL) /* special HL attr. */
7281 {
7282 if (t_colors > 1)
7283 aep = syn_cterm_attr2entry(attr);
7284 else
7285 aep = syn_term_attr2entry(attr);
7286 if (aep == NULL) /* did ":syntax clear" */
7287 attr = 0;
7288 else
7289 attr = aep->ae_attr;
7290 }
7291 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */
7292 out_str(T_MD);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007293 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color
7294 && cterm_normal_fg_bold)
7295 /* If the Normal FG color has BOLD attribute and the new HL
7296 * has a FG color defined, clear BOLD. */
7297 out_str(T_ME);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */
7299 out_str(T_SO);
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007300 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL)
7301 /* underline or undercurl */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 out_str(T_US);
7303 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */
7304 out_str(T_CZH);
7305 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */
7306 out_str(T_MR);
7307
7308 /*
7309 * Output the color or start string after bold etc., in case the
7310 * bold etc. override the color setting.
7311 */
7312 if (aep != NULL)
7313 {
7314 if (t_colors > 1)
7315 {
7316 if (aep->ae_u.cterm.fg_color)
7317 term_fg_color(aep->ae_u.cterm.fg_color - 1);
7318 if (aep->ae_u.cterm.bg_color)
7319 term_bg_color(aep->ae_u.cterm.bg_color - 1);
7320 }
7321 else
7322 {
7323 if (aep->ae_u.term.start != NULL)
7324 out_str(aep->ae_u.term.start);
7325 }
7326 }
7327 }
7328 }
7329}
7330
7331 void
7332screen_stop_highlight()
7333{
7334 int do_ME = FALSE; /* output T_ME code */
7335
7336 if (screen_attr != 0
7337#ifdef WIN3264
7338 && termcap_active
7339#endif
7340 )
7341 {
7342#ifdef FEAT_GUI
7343 if (gui.in_use)
7344 {
7345 char buf[20];
7346
7347 /* use internal GUI code */
7348 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr);
7349 OUT_STR(buf);
7350 }
7351 else
7352#endif
7353 {
7354 if (screen_attr > HL_ALL) /* special HL attr. */
7355 {
7356 attrentry_T *aep;
7357
7358 if (t_colors > 1)
7359 {
7360 /*
7361 * Assume that t_me restores the original colors!
7362 */
7363 aep = syn_cterm_attr2entry(screen_attr);
7364 if (aep != NULL && (aep->ae_u.cterm.fg_color
7365 || aep->ae_u.cterm.bg_color))
7366 do_ME = TRUE;
7367 }
7368 else
7369 {
7370 aep = syn_term_attr2entry(screen_attr);
7371 if (aep != NULL && aep->ae_u.term.stop != NULL)
7372 {
7373 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0)
7374 do_ME = TRUE;
7375 else
7376 out_str(aep->ae_u.term.stop);
7377 }
7378 }
7379 if (aep == NULL) /* did ":syntax clear" */
7380 screen_attr = 0;
7381 else
7382 screen_attr = aep->ae_attr;
7383 }
7384
7385 /*
7386 * Often all ending-codes are equal to T_ME. Avoid outputting the
7387 * same sequence several times.
7388 */
7389 if (screen_attr & HL_STANDOUT)
7390 {
7391 if (STRCMP(T_SE, T_ME) == 0)
7392 do_ME = TRUE;
7393 else
7394 out_str(T_SE);
7395 }
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007396 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007397 {
7398 if (STRCMP(T_UE, T_ME) == 0)
7399 do_ME = TRUE;
7400 else
7401 out_str(T_UE);
7402 }
7403 if (screen_attr & HL_ITALIC)
7404 {
7405 if (STRCMP(T_CZR, T_ME) == 0)
7406 do_ME = TRUE;
7407 else
7408 out_str(T_CZR);
7409 }
7410 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE)))
7411 out_str(T_ME);
7412
7413 if (t_colors > 1)
7414 {
7415 /* set Normal cterm colors */
7416 if (cterm_normal_fg_color != 0)
7417 term_fg_color(cterm_normal_fg_color - 1);
7418 if (cterm_normal_bg_color != 0)
7419 term_bg_color(cterm_normal_bg_color - 1);
7420 if (cterm_normal_fg_bold)
7421 out_str(T_MD);
7422 }
7423 }
7424 }
7425 screen_attr = 0;
7426}
7427
7428/*
7429 * Reset the colors for a cterm. Used when leaving Vim.
7430 * The machine specific code may override this again.
7431 */
7432 void
7433reset_cterm_colors()
7434{
7435 if (t_colors > 1)
7436 {
7437 /* set Normal cterm colors */
7438 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)
7439 {
7440 out_str(T_OP);
7441 screen_attr = -1;
7442 }
7443 if (cterm_normal_fg_bold)
7444 {
7445 out_str(T_ME);
7446 screen_attr = -1;
7447 }
7448 }
7449}
7450
7451/*
7452 * Put character ScreenLines["off"] on the screen at position "row" and "col",
7453 * using the attributes from ScreenAttrs["off"].
7454 */
7455 static void
7456screen_char(off, row, col)
7457 unsigned off;
7458 int row;
7459 int col;
7460{
7461 int attr;
7462
7463 /* Check for illegal values, just in case (could happen just after
7464 * resizing). */
7465 if (row >= screen_Rows || col >= screen_Columns)
7466 return;
7467
7468 /* Outputting the last character on the screen may scrollup the screen.
7469 * Don't to it! Mark the character invalid (update it when scrolled up) */
7470 if (row == screen_Rows - 1 && col == screen_Columns - 1
7471#ifdef FEAT_RIGHTLEFT
7472 /* account for first command-line character in rightleft mode */
7473 && !cmdmsg_rl
7474#endif
7475 )
7476 {
7477 ScreenAttrs[off] = (sattr_T)-1;
7478 return;
7479 }
7480
7481 /*
7482 * Stop highlighting first, so it's easier to move the cursor.
7483 */
7484#if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
7485 if (screen_char_attr != 0)
7486 attr = screen_char_attr;
7487 else
7488#endif
7489 attr = ScreenAttrs[off];
7490 if (screen_attr != attr)
7491 screen_stop_highlight();
7492
7493 windgoto(row, col);
7494
7495 if (screen_attr != attr)
7496 screen_start_highlight(attr);
7497
7498#ifdef FEAT_MBYTE
7499 if (enc_utf8 && ScreenLinesUC[off] != 0)
7500 {
7501 char_u buf[MB_MAXBYTES + 1];
7502
7503 /* Convert UTF-8 character to bytes and write it. */
7504
7505 buf[utfc_char2bytes(off, buf)] = NUL;
7506
7507 out_str(buf);
7508 if (utf_char2cells(ScreenLinesUC[off]) > 1)
7509 ++screen_cur_col;
7510 }
7511 else
7512#endif
7513 {
7514#ifdef FEAT_MBYTE
7515 out_flush_check();
7516#endif
7517 out_char(ScreenLines[off]);
7518#ifdef FEAT_MBYTE
7519 /* double-byte character in single-width cell */
7520 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
7521 out_char(ScreenLines2[off]);
7522#endif
7523 }
7524
7525 screen_cur_col++;
7526}
7527
7528#ifdef FEAT_MBYTE
7529
7530/*
7531 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
7532 * on the screen at position 'row' and 'col'.
7533 * The attributes of the first byte is used for all. This is required to
7534 * output the two bytes of a double-byte character with nothing in between.
7535 */
7536 static void
7537screen_char_2(off, row, col)
7538 unsigned off;
7539 int row;
7540 int col;
7541{
7542 /* Check for illegal values (could be wrong when screen was resized). */
7543 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns))
7544 return;
7545
7546 /* Outputting the last character on the screen may scrollup the screen.
7547 * Don't to it! Mark the character invalid (update it when scrolled up) */
7548 if (row == screen_Rows - 1 && col >= screen_Columns - 2)
7549 {
7550 ScreenAttrs[off] = (sattr_T)-1;
7551 return;
7552 }
7553
7554 /* Output the first byte normally (positions the cursor), then write the
7555 * second byte directly. */
7556 screen_char(off, row, col);
7557 out_char(ScreenLines[off + 1]);
7558 ++screen_cur_col;
7559}
7560#endif
7561
7562#if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
7563/*
7564 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
7565 * This uses the contents of ScreenLines[] and doesn't change it.
7566 */
7567 void
7568screen_draw_rectangle(row, col, height, width, invert)
7569 int row;
7570 int col;
7571 int height;
7572 int width;
7573 int invert;
7574{
7575 int r, c;
7576 int off;
Bram Moolenaar367329b2007-08-30 11:53:22 +00007577#ifdef FEAT_MBYTE
7578 int max_off;
7579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007581 /* Can't use ScreenLines unless initialized */
7582 if (ScreenLines == NULL)
7583 return;
7584
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 if (invert)
7586 screen_char_attr = HL_INVERSE;
7587 for (r = row; r < row + height; ++r)
7588 {
7589 off = LineOffset[r];
Bram Moolenaar367329b2007-08-30 11:53:22 +00007590#ifdef FEAT_MBYTE
7591 max_off = off + screen_Columns;
7592#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007593 for (c = col; c < col + width; ++c)
7594 {
7595#ifdef FEAT_MBYTE
Bram Moolenaar367329b2007-08-30 11:53:22 +00007596 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 {
7598 screen_char_2(off + c, r, c);
7599 ++c;
7600 }
7601 else
7602#endif
7603 {
7604 screen_char(off + c, r, c);
7605#ifdef FEAT_MBYTE
Bram Moolenaar367329b2007-08-30 11:53:22 +00007606 if (utf_off2cells(off + c, max_off) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007607 ++c;
7608#endif
7609 }
7610 }
7611 }
7612 screen_char_attr = 0;
7613}
7614#endif
7615
7616#ifdef FEAT_VERTSPLIT
7617/*
7618 * Redraw the characters for a vertically split window.
7619 */
7620 static void
7621redraw_block(row, end, wp)
7622 int row;
7623 int end;
7624 win_T *wp;
7625{
7626 int col;
7627 int width;
7628
7629# ifdef FEAT_CLIPBOARD
7630 clip_may_clear_selection(row, end - 1);
7631# endif
7632
7633 if (wp == NULL)
7634 {
7635 col = 0;
7636 width = Columns;
7637 }
7638 else
7639 {
7640 col = wp->w_wincol;
7641 width = wp->w_width;
7642 }
7643 screen_draw_rectangle(row, col, end - row, width, FALSE);
7644}
7645#endif
7646
7647/*
7648 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7649 * with character 'c1' in first column followed by 'c2' in the other columns.
7650 * Use attributes 'attr'.
7651 */
7652 void
7653screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr)
7654 int start_row, end_row;
7655 int start_col, end_col;
7656 int c1, c2;
7657 int attr;
7658{
7659 int row;
7660 int col;
7661 int off;
7662 int end_off;
7663 int did_delete;
7664 int c;
7665 int norm_term;
7666#if defined(FEAT_GUI) || defined(UNIX)
7667 int force_next = FALSE;
7668#endif
7669
7670 if (end_row > screen_Rows) /* safety check */
7671 end_row = screen_Rows;
7672 if (end_col > screen_Columns) /* safety check */
7673 end_col = screen_Columns;
7674 if (ScreenLines == NULL
7675 || start_row >= end_row
7676 || start_col >= end_col) /* nothing to do */
7677 return;
7678
7679 /* it's a "normal" terminal when not in a GUI or cterm */
7680 norm_term = (
7681#ifdef FEAT_GUI
7682 !gui.in_use &&
7683#endif
7684 t_colors <= 1);
7685 for (row = start_row; row < end_row; ++row)
7686 {
Bram Moolenaarc236c162008-07-13 17:41:49 +00007687#ifdef FEAT_MBYTE
7688 if (has_mbyte
7689# ifdef FEAT_GUI
7690 && !gui.in_use
7691# endif
7692 )
7693 {
7694 /* When drawing over the right halve of a double-wide char clear
7695 * out the left halve. When drawing over the left halve of a
7696 * double wide-char clear out the right halve. Only needed in a
7697 * terminal. */
Bram Moolenaar7693ec62008-07-24 18:29:37 +00007698 if (start_col > 0 && mb_fix_col(start_col, row) != start_col)
Bram Moolenaard91ffe92008-07-14 17:51:11 +00007699 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0);
Bram Moolenaara1aed622008-07-18 15:14:43 +00007700 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col)
Bram Moolenaard91ffe92008-07-14 17:51:11 +00007701 screen_puts_len((char_u *)" ", 1, row, end_col, 0);
Bram Moolenaarc236c162008-07-13 17:41:49 +00007702 }
7703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 /*
7705 * Try to use delete-line termcap code, when no attributes or in a
7706 * "normal" terminal, where a bold/italic space is just a
7707 * space.
7708 */
7709 did_delete = FALSE;
7710 if (c2 == ' '
7711 && end_col == Columns
7712 && can_clear(T_CE)
7713 && (attr == 0
7714 || (norm_term
7715 && attr <= HL_ALL
7716 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0))))
7717 {
7718 /*
7719 * check if we really need to clear something
7720 */
7721 col = start_col;
7722 if (c1 != ' ') /* don't clear first char */
7723 ++col;
7724
7725 off = LineOffset[row] + col;
7726 end_off = LineOffset[row] + end_col;
7727
7728 /* skip blanks (used often, keep it fast!) */
7729#ifdef FEAT_MBYTE
7730 if (enc_utf8)
7731 while (off < end_off && ScreenLines[off] == ' '
7732 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0)
7733 ++off;
7734 else
7735#endif
7736 while (off < end_off && ScreenLines[off] == ' '
7737 && ScreenAttrs[off] == 0)
7738 ++off;
7739 if (off < end_off) /* something to be cleared */
7740 {
7741 col = off - LineOffset[row];
7742 screen_stop_highlight();
7743 term_windgoto(row, col);/* clear rest of this screen line */
7744 out_str(T_CE);
7745 screen_start(); /* don't know where cursor is now */
7746 col = end_col - col;
7747 while (col--) /* clear chars in ScreenLines */
7748 {
7749 ScreenLines[off] = ' ';
7750#ifdef FEAT_MBYTE
7751 if (enc_utf8)
7752 ScreenLinesUC[off] = 0;
7753#endif
7754 ScreenAttrs[off] = 0;
7755 ++off;
7756 }
7757 }
7758 did_delete = TRUE; /* the chars are cleared now */
7759 }
7760
7761 off = LineOffset[row] + start_col;
7762 c = c1;
7763 for (col = start_col; col < end_col; ++col)
7764 {
7765 if (ScreenLines[off] != c
7766#ifdef FEAT_MBYTE
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007767 || (enc_utf8 && (int)ScreenLinesUC[off]
7768 != (c >= 0x80 ? c : 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769#endif
7770 || ScreenAttrs[off] != attr
7771#if defined(FEAT_GUI) || defined(UNIX)
7772 || force_next
7773#endif
7774 )
7775 {
7776#if defined(FEAT_GUI) || defined(UNIX)
7777 /* The bold trick may make a single row of pixels appear in
7778 * the next character. When a bold character is removed, the
7779 * next character should be redrawn too. This happens for our
7780 * own GUI and for some xterms. */
7781 if (
7782# ifdef FEAT_GUI
7783 gui.in_use
7784# endif
7785# if defined(FEAT_GUI) && defined(UNIX)
7786 ||
7787# endif
7788# ifdef UNIX
7789 term_is_xterm
7790# endif
7791 )
7792 {
7793 if (ScreenLines[off] != ' '
7794 && (ScreenAttrs[off] > HL_ALL
7795 || ScreenAttrs[off] & HL_BOLD))
7796 force_next = TRUE;
7797 else
7798 force_next = FALSE;
7799 }
7800#endif
7801 ScreenLines[off] = c;
7802#ifdef FEAT_MBYTE
7803 if (enc_utf8)
7804 {
7805 if (c >= 0x80)
7806 {
7807 ScreenLinesUC[off] = c;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007808 ScreenLinesC[0][off] = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809 }
7810 else
7811 ScreenLinesUC[off] = 0;
7812 }
7813#endif
7814 ScreenAttrs[off] = attr;
7815 if (!did_delete || c != ' ')
7816 screen_char(off, row, col);
7817 }
7818 ++off;
7819 if (col == start_col)
7820 {
7821 if (did_delete)
7822 break;
7823 c = c2;
7824 }
7825 }
7826 if (end_col == Columns)
7827 LineWraps[row] = FALSE;
7828 if (row == Rows - 1) /* overwritten the command line */
7829 {
7830 redraw_cmdline = TRUE;
7831 if (c1 == ' ' && c2 == ' ')
7832 clear_cmdline = FALSE; /* command line has been cleared */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007833 if (start_col == 0)
7834 mode_displayed = FALSE; /* mode cleared or overwritten */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835 }
7836 }
7837}
7838
7839/*
7840 * Check if there should be a delay. Used before clearing or redrawing the
7841 * screen or the command line.
7842 */
7843 void
7844check_for_delay(check_msg_scroll)
7845 int check_msg_scroll;
7846{
7847 if ((emsg_on_display || (check_msg_scroll && msg_scroll))
7848 && !did_wait_return
7849 && emsg_silent == 0)
7850 {
7851 out_flush();
7852 ui_delay(1000L, TRUE);
7853 emsg_on_display = FALSE;
7854 if (check_msg_scroll)
7855 msg_scroll = FALSE;
7856 }
7857}
7858
7859/*
7860 * screen_valid - allocate screen buffers if size changed
Bram Moolenaar70b2a562012-01-10 22:26:17 +01007861 * If "doclear" is TRUE: clear screen if it has been resized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862 * Returns TRUE if there is a valid screen to write to.
7863 * Returns FALSE when starting up and screen not initialized yet.
7864 */
7865 int
Bram Moolenaar70b2a562012-01-10 22:26:17 +01007866screen_valid(doclear)
7867 int doclear;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868{
Bram Moolenaar70b2a562012-01-10 22:26:17 +01007869 screenalloc(doclear); /* allocate screen buffers if size changed */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 return (ScreenLines != NULL);
7871}
7872
7873/*
7874 * Resize the shell to Rows and Columns.
7875 * Allocate ScreenLines[] and associated items.
7876 *
7877 * There may be some time between setting Rows and Columns and (re)allocating
7878 * ScreenLines[]. This happens when starting up and when (manually) changing
7879 * the shell size. Always use screen_Rows and screen_Columns to access items
7880 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7881 * final size of the shell is needed.
7882 */
7883 void
Bram Moolenaar70b2a562012-01-10 22:26:17 +01007884screenalloc(doclear)
7885 int doclear;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886{
7887 int new_row, old_row;
7888#ifdef FEAT_GUI
7889 int old_Rows;
7890#endif
7891 win_T *wp;
7892 int outofmem = FALSE;
7893 int len;
7894 schar_T *new_ScreenLines;
7895#ifdef FEAT_MBYTE
7896 u8char_T *new_ScreenLinesUC = NULL;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007897 u8char_T *new_ScreenLinesC[MAX_MCO];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 schar_T *new_ScreenLines2 = NULL;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007899 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900#endif
7901 sattr_T *new_ScreenAttrs;
7902 unsigned *new_LineOffset;
7903 char_u *new_LineWraps;
Bram Moolenaarf740b292006-02-16 22:11:02 +00007904#ifdef FEAT_WINDOWS
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007905 short *new_TabPageIdxs;
Bram Moolenaarf740b292006-02-16 22:11:02 +00007906 tabpage_T *tp;
7907#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 static int entered = FALSE; /* avoid recursiveness */
Bram Moolenaar89d40322006-08-29 15:30:07 +00007909 static int done_outofmem_msg = FALSE; /* did outofmem message */
Bram Moolenaar87e817c2009-02-22 20:13:39 +00007910#ifdef FEAT_AUTOCMD
7911 int retry_count = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912
Bram Moolenaar87e817c2009-02-22 20:13:39 +00007913retry:
7914#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 /*
7916 * Allocation of the screen buffers is done only when the size changes and
7917 * when Rows and Columns have been set and we have started doing full
7918 * screen stuff.
7919 */
7920 if ((ScreenLines != NULL
7921 && Rows == screen_Rows
7922 && Columns == screen_Columns
7923#ifdef FEAT_MBYTE
7924 && enc_utf8 == (ScreenLinesUC != NULL)
7925 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL)
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007926 && p_mco == Screen_mco
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927#endif
7928 )
7929 || Rows == 0
7930 || Columns == 0
7931 || (!full_screen && ScreenLines == NULL))
7932 return;
7933
7934 /*
7935 * It's possible that we produce an out-of-memory message below, which
7936 * will cause this function to be called again. To break the loop, just
7937 * return here.
7938 */
7939 if (entered)
7940 return;
7941 entered = TRUE;
7942
Bram Moolenaara3f2ecd2006-07-11 21:01:01 +00007943 /*
7944 * Note that the window sizes are updated before reallocating the arrays,
7945 * thus we must not redraw here!
7946 */
7947 ++RedrawingDisabled;
7948
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 win_new_shellsize(); /* fit the windows in the new sized shell */
7950
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951 comp_col(); /* recompute columns for shown command and ruler */
7952
7953 /*
7954 * We're changing the size of the screen.
7955 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7956 * - Move lines from the old arrays into the new arrays, clear extra
7957 * lines (unless the screen is going to be cleared).
7958 * - Free the old arrays.
7959 *
7960 * If anything fails, make ScreenLines NULL, so we don't do anything!
7961 * Continuing with the old ScreenLines may result in a crash, because the
7962 * size is wrong.
7963 */
Bram Moolenaarf740b292006-02-16 22:11:02 +00007964 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 win_free_lsize(wp);
Bram Moolenaar5e9b4542009-07-29 14:24:36 +00007966#ifdef FEAT_AUTOCMD
7967 if (aucmd_win != NULL)
7968 win_free_lsize(aucmd_win);
7969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970
7971 new_ScreenLines = (schar_T *)lalloc((long_u)(
7972 (Rows + 1) * Columns * sizeof(schar_T)), FALSE);
7973#ifdef FEAT_MBYTE
Bram Moolenaar216b7102010-03-23 13:56:59 +01007974 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 if (enc_utf8)
7976 {
7977 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)(
7978 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007979 for (i = 0; i < p_mco; ++i)
Bram Moolenaar70c49c12010-03-23 15:36:35 +01007980 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)(
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE);
7982 }
7983 if (enc_dbcs == DBCS_JPNU)
7984 new_ScreenLines2 = (schar_T *)lalloc((long_u)(
7985 (Rows + 1) * Columns * sizeof(schar_T)), FALSE);
7986#endif
7987 new_ScreenAttrs = (sattr_T *)lalloc((long_u)(
7988 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE);
7989 new_LineOffset = (unsigned *)lalloc((long_u)(
7990 Rows * sizeof(unsigned)), FALSE);
7991 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE);
Bram Moolenaarf740b292006-02-16 22:11:02 +00007992#ifdef FEAT_WINDOWS
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007993 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE);
Bram Moolenaarf740b292006-02-16 22:11:02 +00007994#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007996 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 {
7998 if (win_alloc_lines(wp) == FAIL)
7999 {
8000 outofmem = TRUE;
8001#ifdef FEAT_WINDOWS
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00008002 goto give_up;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003#endif
8004 }
8005 }
Bram Moolenaar746ebd32009-06-16 14:01:43 +00008006#ifdef FEAT_AUTOCMD
Bram Moolenaar5e9b4542009-07-29 14:24:36 +00008007 if (aucmd_win != NULL && aucmd_win->w_lines == NULL
8008 && win_alloc_lines(aucmd_win) == FAIL)
Bram Moolenaar746ebd32009-06-16 14:01:43 +00008009 outofmem = TRUE;
8010#endif
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00008011#ifdef FEAT_WINDOWS
8012give_up:
8013#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008015#ifdef FEAT_MBYTE
8016 for (i = 0; i < p_mco; ++i)
8017 if (new_ScreenLinesC[i] == NULL)
8018 break;
8019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020 if (new_ScreenLines == NULL
8021#ifdef FEAT_MBYTE
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008022 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL)
8024#endif
8025 || new_ScreenAttrs == NULL
8026 || new_LineOffset == NULL
8027 || new_LineWraps == NULL
Bram Moolenaarf740b292006-02-16 22:11:02 +00008028#ifdef FEAT_WINDOWS
8029 || new_TabPageIdxs == NULL
8030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 || outofmem)
8032 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00008033 if (ScreenLines != NULL || !done_outofmem_msg)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008034 {
8035 /* guess the size */
8036 do_outofmem_msg((long_u)((Rows + 1) * Columns));
8037
8038 /* Remember we did this to avoid getting outofmem messages over
8039 * and over again. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00008040 done_outofmem_msg = TRUE;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008041 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 vim_free(new_ScreenLines);
8043 new_ScreenLines = NULL;
8044#ifdef FEAT_MBYTE
8045 vim_free(new_ScreenLinesUC);
8046 new_ScreenLinesUC = NULL;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008047 for (i = 0; i < p_mco; ++i)
8048 {
8049 vim_free(new_ScreenLinesC[i]);
8050 new_ScreenLinesC[i] = NULL;
8051 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008052 vim_free(new_ScreenLines2);
8053 new_ScreenLines2 = NULL;
8054#endif
8055 vim_free(new_ScreenAttrs);
8056 new_ScreenAttrs = NULL;
8057 vim_free(new_LineOffset);
8058 new_LineOffset = NULL;
8059 vim_free(new_LineWraps);
8060 new_LineWraps = NULL;
Bram Moolenaarf740b292006-02-16 22:11:02 +00008061#ifdef FEAT_WINDOWS
8062 vim_free(new_TabPageIdxs);
8063 new_TabPageIdxs = NULL;
8064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065 }
8066 else
8067 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00008068 done_outofmem_msg = FALSE;
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008069
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 for (new_row = 0; new_row < Rows; ++new_row)
8071 {
8072 new_LineOffset[new_row] = new_row * Columns;
8073 new_LineWraps[new_row] = FALSE;
8074
8075 /*
8076 * If the screen is not going to be cleared, copy as much as
8077 * possible from the old screen to the new one and clear the rest
8078 * (used when resizing the window at the "--more--" prompt or when
8079 * executing an external command, for the GUI).
8080 */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008081 if (!doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082 {
8083 (void)vim_memset(new_ScreenLines + new_row * Columns,
8084 ' ', (size_t)Columns * sizeof(schar_T));
8085#ifdef FEAT_MBYTE
8086 if (enc_utf8)
8087 {
8088 (void)vim_memset(new_ScreenLinesUC + new_row * Columns,
8089 0, (size_t)Columns * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008090 for (i = 0; i < p_mco; ++i)
8091 (void)vim_memset(new_ScreenLinesC[i]
8092 + new_row * Columns,
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 0, (size_t)Columns * sizeof(u8char_T));
8094 }
8095 if (enc_dbcs == DBCS_JPNU)
8096 (void)vim_memset(new_ScreenLines2 + new_row * Columns,
8097 0, (size_t)Columns * sizeof(schar_T));
8098#endif
8099 (void)vim_memset(new_ScreenAttrs + new_row * Columns,
8100 0, (size_t)Columns * sizeof(sattr_T));
8101 old_row = new_row + (screen_Rows - Rows);
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008102 if (old_row >= 0 && ScreenLines != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103 {
8104 if (screen_Columns < Columns)
8105 len = screen_Columns;
8106 else
8107 len = Columns;
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00008108#ifdef FEAT_MBYTE
Bram Moolenaarf4d11452005-12-02 00:46:37 +00008109 /* When switching to utf-8 don't copy characters, they
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008110 * may be invalid now. Also when p_mco changes. */
8111 if (!(enc_utf8 && ScreenLinesUC == NULL)
8112 && p_mco == Screen_mco)
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00008113#endif
8114 mch_memmove(new_ScreenLines + new_LineOffset[new_row],
8115 ScreenLines + LineOffset[old_row],
8116 (size_t)len * sizeof(schar_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117#ifdef FEAT_MBYTE
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008118 if (enc_utf8 && ScreenLinesUC != NULL
8119 && p_mco == Screen_mco)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120 {
8121 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row],
8122 ScreenLinesUC + LineOffset[old_row],
8123 (size_t)len * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008124 for (i = 0; i < p_mco; ++i)
8125 mch_memmove(new_ScreenLinesC[i]
8126 + new_LineOffset[new_row],
8127 ScreenLinesC[i] + LineOffset[old_row],
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 (size_t)len * sizeof(u8char_T));
8129 }
8130 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL)
8131 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row],
8132 ScreenLines2 + LineOffset[old_row],
8133 (size_t)len * sizeof(schar_T));
8134#endif
8135 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row],
8136 ScreenAttrs + LineOffset[old_row],
8137 (size_t)len * sizeof(sattr_T));
8138 }
8139 }
8140 }
8141 /* Use the last line of the screen for the current line. */
8142 current_ScreenLine = new_ScreenLines + Rows * Columns;
8143 }
8144
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008145 free_screenlines();
8146
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 ScreenLines = new_ScreenLines;
8148#ifdef FEAT_MBYTE
8149 ScreenLinesUC = new_ScreenLinesUC;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008150 for (i = 0; i < p_mco; ++i)
8151 ScreenLinesC[i] = new_ScreenLinesC[i];
8152 Screen_mco = p_mco;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 ScreenLines2 = new_ScreenLines2;
8154#endif
8155 ScreenAttrs = new_ScreenAttrs;
8156 LineOffset = new_LineOffset;
8157 LineWraps = new_LineWraps;
Bram Moolenaarf740b292006-02-16 22:11:02 +00008158#ifdef FEAT_WINDOWS
8159 TabPageIdxs = new_TabPageIdxs;
8160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161
8162 /* It's important that screen_Rows and screen_Columns reflect the actual
8163 * size of ScreenLines[]. Set them before calling anything. */
8164#ifdef FEAT_GUI
8165 old_Rows = screen_Rows;
8166#endif
8167 screen_Rows = Rows;
8168 screen_Columns = Columns;
8169
8170 must_redraw = CLEAR; /* need to clear the screen later */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008171 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 screenclear2();
8173
8174#ifdef FEAT_GUI
8175 else if (gui.in_use
8176 && !gui.starting
8177 && ScreenLines != NULL
8178 && old_Rows != Rows)
8179 {
8180 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0);
8181 /*
8182 * Adjust the position of the cursor, for when executing an external
8183 * command.
8184 */
8185 if (msg_row >= Rows) /* Rows got smaller */
8186 msg_row = Rows - 1; /* put cursor at last row */
8187 else if (Rows > old_Rows) /* Rows got bigger */
8188 msg_row += Rows - old_Rows; /* put cursor in same place */
8189 if (msg_col >= Columns) /* Columns got smaller */
8190 msg_col = Columns - 1; /* put cursor at last column */
8191 }
8192#endif
8193
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 entered = FALSE;
Bram Moolenaara3f2ecd2006-07-11 21:01:01 +00008195 --RedrawingDisabled;
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00008196
8197#ifdef FEAT_AUTOCMD
Bram Moolenaar87e817c2009-02-22 20:13:39 +00008198 /*
8199 * Do not apply autocommands more than 3 times to avoid an endless loop
8200 * in case applying autocommands always changes Rows or Columns.
8201 */
8202 if (starting == 0 && ++retry_count <= 3)
8203 {
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00008204 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
Bram Moolenaar87e817c2009-02-22 20:13:39 +00008205 /* In rare cases, autocommands may have altered Rows or Columns,
8206 * jump back to check if we need to allocate the screen again. */
8207 goto retry;
8208 }
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00008209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210}
8211
8212 void
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008213free_screenlines()
8214{
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008215#ifdef FEAT_MBYTE
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008216 int i;
8217
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008218 vim_free(ScreenLinesUC);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008219 for (i = 0; i < Screen_mco; ++i)
8220 vim_free(ScreenLinesC[i]);
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008221 vim_free(ScreenLines2);
8222#endif
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008223 vim_free(ScreenLines);
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008224 vim_free(ScreenAttrs);
8225 vim_free(LineOffset);
8226 vim_free(LineWraps);
Bram Moolenaarf740b292006-02-16 22:11:02 +00008227#ifdef FEAT_WINDOWS
8228 vim_free(TabPageIdxs);
8229#endif
Bram Moolenaar1ec484f2005-06-24 23:07:47 +00008230}
8231
8232 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233screenclear()
8234{
8235 check_for_delay(FALSE);
8236 screenalloc(FALSE); /* allocate screen buffers if size changed */
8237 screenclear2(); /* clear the screen */
8238}
8239
8240 static void
8241screenclear2()
8242{
8243 int i;
8244
8245 if (starting == NO_SCREEN || ScreenLines == NULL
8246#ifdef FEAT_GUI
8247 || (gui.in_use && gui.starting)
8248#endif
8249 )
8250 return;
8251
8252#ifdef FEAT_GUI
8253 if (!gui.in_use)
8254#endif
8255 screen_attr = -1; /* force setting the Normal colors */
8256 screen_stop_highlight(); /* don't want highlighting here */
8257
8258#ifdef FEAT_CLIPBOARD
8259 /* disable selection without redrawing it */
8260 clip_scroll_selection(9999);
8261#endif
8262
8263 /* blank out ScreenLines */
8264 for (i = 0; i < Rows; ++i)
8265 {
8266 lineclear(LineOffset[i], (int)Columns);
8267 LineWraps[i] = FALSE;
8268 }
8269
8270 if (can_clear(T_CL))
8271 {
8272 out_str(T_CL); /* clear the display */
8273 clear_cmdline = FALSE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008274 mode_displayed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 }
8276 else
8277 {
8278 /* can't clear the screen, mark all chars with invalid attributes */
8279 for (i = 0; i < Rows; ++i)
8280 lineinvalid(LineOffset[i], (int)Columns);
8281 clear_cmdline = TRUE;
8282 }
8283
8284 screen_cleared = TRUE; /* can use contents of ScreenLines now */
8285
8286 win_rest_invalid(firstwin);
8287 redraw_cmdline = TRUE;
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008288#ifdef FEAT_WINDOWS
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00008289 redraw_tabline = TRUE;
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008290#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 if (must_redraw == CLEAR) /* no need to clear again */
8292 must_redraw = NOT_VALID;
8293 compute_cmdrow();
8294 msg_row = cmdline_row; /* put cursor on last line for messages */
8295 msg_col = 0;
8296 screen_start(); /* don't know where cursor is now */
8297 msg_scrolled = 0; /* can't scroll back */
8298 msg_didany = FALSE;
8299 msg_didout = FALSE;
8300}
8301
8302/*
8303 * Clear one line in ScreenLines.
8304 */
8305 static void
8306lineclear(off, width)
8307 unsigned off;
8308 int width;
8309{
8310 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T));
8311#ifdef FEAT_MBYTE
8312 if (enc_utf8)
8313 (void)vim_memset(ScreenLinesUC + off, 0,
8314 (size_t)width * sizeof(u8char_T));
8315#endif
8316 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T));
8317}
8318
8319/*
8320 * Mark one line in ScreenLines invalid by setting the attributes to an
8321 * invalid value.
8322 */
8323 static void
8324lineinvalid(off, width)
8325 unsigned off;
8326 int width;
8327{
8328 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T));
8329}
8330
8331#ifdef FEAT_VERTSPLIT
8332/*
8333 * Copy part of a Screenline for vertically split window "wp".
8334 */
8335 static void
8336linecopy(to, from, wp)
8337 int to;
8338 int from;
8339 win_T *wp;
8340{
8341 unsigned off_to = LineOffset[to] + wp->w_wincol;
8342 unsigned off_from = LineOffset[from] + wp->w_wincol;
8343
8344 mch_memmove(ScreenLines + off_to, ScreenLines + off_from,
8345 wp->w_width * sizeof(schar_T));
8346# ifdef FEAT_MBYTE
8347 if (enc_utf8)
8348 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008349 int i;
8350
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from,
8352 wp->w_width * sizeof(u8char_T));
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008353 for (i = 0; i < p_mco; ++i)
8354 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from,
8355 wp->w_width * sizeof(u8char_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 }
8357 if (enc_dbcs == DBCS_JPNU)
8358 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from,
8359 wp->w_width * sizeof(schar_T));
8360# endif
8361 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from,
8362 wp->w_width * sizeof(sattr_T));
8363}
8364#endif
8365
8366/*
8367 * Return TRUE if clearing with term string "p" would work.
8368 * It can't work when the string is empty or it won't set the right background.
8369 */
8370 int
8371can_clear(p)
8372 char_u *p;
8373{
8374 return (*p != NUL && (t_colors <= 1
8375#ifdef FEAT_GUI
8376 || gui.in_use
8377#endif
8378 || cterm_normal_bg_color == 0 || *T_UT != NUL));
8379}
8380
8381/*
8382 * Reset cursor position. Use whenever cursor was moved because of outputting
8383 * something directly to the screen (shell commands) or a terminal control
8384 * code.
8385 */
8386 void
8387screen_start()
8388{
8389 screen_cur_row = screen_cur_col = 9999;
8390}
8391
8392/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 * Move the cursor to position "row","col" in the screen.
8394 * This tries to find the most efficient way to move, minimizing the number of
8395 * characters sent to the terminal.
8396 */
8397 void
8398windgoto(row, col)
8399 int row;
8400 int col;
8401{
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008402 sattr_T *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 int i;
8404 int plan;
8405 int cost;
8406 int wouldbe_col;
8407 int noinvcurs;
8408 char_u *bs;
8409 int goto_cost;
8410 int attr;
8411
Bram Moolenaar2c7a7632007-05-10 18:19:11 +00008412#define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413#define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
8414
8415#define PLAN_LE 1
8416#define PLAN_CR 2
8417#define PLAN_NL 3
8418#define PLAN_WRITE 4
8419 /* Can't use ScreenLines unless initialized */
8420 if (ScreenLines == NULL)
8421 return;
8422
8423 if (col != screen_cur_col || row != screen_cur_row)
8424 {
8425 /* Check for valid position. */
8426 if (row < 0) /* window without text lines? */
8427 row = 0;
8428 if (row >= screen_Rows)
8429 row = screen_Rows - 1;
8430 if (col >= screen_Columns)
8431 col = screen_Columns - 1;
8432
8433 /* check if no cursor movement is allowed in highlight mode */
8434 if (screen_attr && *T_MS == NUL)
8435 noinvcurs = HIGHL_COST;
8436 else
8437 noinvcurs = 0;
8438 goto_cost = GOTO_COST + noinvcurs;
8439
8440 /*
8441 * Plan how to do the positioning:
8442 * 1. Use CR to move it to column 0, same row.
8443 * 2. Use T_LE to move it a few columns to the left.
8444 * 3. Use NL to move a few lines down, column 0.
8445 * 4. Move a few columns to the right with T_ND or by writing chars.
8446 *
8447 * Don't do this if the cursor went beyond the last column, the cursor
8448 * position is unknown then (some terminals wrap, some don't )
8449 *
Bram Moolenaar2c7a7632007-05-10 18:19:11 +00008450 * First check if the highlighting attributes allow us to write
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 * characters to move the cursor to the right.
8452 */
8453 if (row >= screen_cur_row && screen_cur_col < Columns)
8454 {
8455 /*
8456 * If the cursor is in the same row, bigger col, we can use CR
8457 * or T_LE.
8458 */
8459 bs = NULL; /* init for GCC */
8460 attr = screen_attr;
8461 if (row == screen_cur_row && col < screen_cur_col)
8462 {
8463 /* "le" is preferred over "bc", because "bc" is obsolete */
8464 if (*T_LE)
8465 bs = T_LE; /* "cursor left" */
8466 else
8467 bs = T_BC; /* "backspace character (old) */
8468 if (*bs)
8469 cost = (screen_cur_col - col) * (int)STRLEN(bs);
8470 else
8471 cost = 999;
8472 if (col + 1 < cost) /* using CR is less characters */
8473 {
8474 plan = PLAN_CR;
8475 wouldbe_col = 0;
8476 cost = 1; /* CR is just one character */
8477 }
8478 else
8479 {
8480 plan = PLAN_LE;
8481 wouldbe_col = col;
8482 }
8483 if (noinvcurs) /* will stop highlighting */
8484 {
8485 cost += noinvcurs;
8486 attr = 0;
8487 }
8488 }
8489
8490 /*
8491 * If the cursor is above where we want to be, we can use CR LF.
8492 */
8493 else if (row > screen_cur_row)
8494 {
8495 plan = PLAN_NL;
8496 wouldbe_col = 0;
8497 cost = (row - screen_cur_row) * 2; /* CR LF */
8498 if (noinvcurs) /* will stop highlighting */
8499 {
8500 cost += noinvcurs;
8501 attr = 0;
8502 }
8503 }
8504
8505 /*
8506 * If the cursor is in the same row, smaller col, just use write.
8507 */
8508 else
8509 {
8510 plan = PLAN_WRITE;
8511 wouldbe_col = screen_cur_col;
8512 cost = 0;
8513 }
8514
8515 /*
8516 * Check if any characters that need to be written have the
8517 * correct attributes. Also avoid UTF-8 characters.
8518 */
8519 i = col - wouldbe_col;
8520 if (i > 0)
8521 cost += i;
8522 if (cost < goto_cost && i > 0)
8523 {
8524 /*
8525 * Check if the attributes are correct without additionally
8526 * stopping highlighting.
8527 */
8528 p = ScreenAttrs + LineOffset[row] + wouldbe_col;
8529 while (i && *p++ == attr)
8530 --i;
8531 if (i != 0)
8532 {
8533 /*
8534 * Try if it works when highlighting is stopped here.
8535 */
8536 if (*--p == 0)
8537 {
8538 cost += noinvcurs;
8539 while (i && *p++ == 0)
8540 --i;
8541 }
8542 if (i != 0)
8543 cost = 999; /* different attributes, don't do it */
8544 }
8545#ifdef FEAT_MBYTE
8546 if (enc_utf8)
8547 {
8548 /* Don't use an UTF-8 char for positioning, it's slow. */
8549 for (i = wouldbe_col; i < col; ++i)
8550 if (ScreenLinesUC[LineOffset[row] + i] != 0)
8551 {
8552 cost = 999;
8553 break;
8554 }
8555 }
8556#endif
8557 }
8558
8559 /*
8560 * We can do it without term_windgoto()!
8561 */
8562 if (cost < goto_cost)
8563 {
8564 if (plan == PLAN_LE)
8565 {
8566 if (noinvcurs)
8567 screen_stop_highlight();
8568 while (screen_cur_col > col)
8569 {
8570 out_str(bs);
8571 --screen_cur_col;
8572 }
8573 }
8574 else if (plan == PLAN_CR)
8575 {
8576 if (noinvcurs)
8577 screen_stop_highlight();
8578 out_char('\r');
8579 screen_cur_col = 0;
8580 }
8581 else if (plan == PLAN_NL)
8582 {
8583 if (noinvcurs)
8584 screen_stop_highlight();
8585 while (screen_cur_row < row)
8586 {
8587 out_char('\n');
8588 ++screen_cur_row;
8589 }
8590 screen_cur_col = 0;
8591 }
8592
8593 i = col - screen_cur_col;
8594 if (i > 0)
8595 {
8596 /*
8597 * Use cursor-right if it's one character only. Avoids
8598 * removing a line of pixels from the last bold char, when
8599 * using the bold trick in the GUI.
8600 */
8601 if (T_ND[0] != NUL && T_ND[1] == NUL)
8602 {
8603 while (i-- > 0)
8604 out_char(*T_ND);
8605 }
8606 else
8607 {
8608 int off;
8609
8610 off = LineOffset[row] + screen_cur_col;
8611 while (i-- > 0)
8612 {
8613 if (ScreenAttrs[off] != screen_attr)
8614 screen_stop_highlight();
8615#ifdef FEAT_MBYTE
8616 out_flush_check();
8617#endif
8618 out_char(ScreenLines[off]);
8619#ifdef FEAT_MBYTE
8620 if (enc_dbcs == DBCS_JPNU
8621 && ScreenLines[off] == 0x8e)
8622 out_char(ScreenLines2[off]);
8623#endif
8624 ++off;
8625 }
8626 }
8627 }
8628 }
8629 }
8630 else
8631 cost = 999;
8632
8633 if (cost >= goto_cost)
8634 {
8635 if (noinvcurs)
8636 screen_stop_highlight();
8637 if (row == screen_cur_row && (col > screen_cur_col) &&
8638 *T_CRI != NUL)
8639 term_cursor_right(col - screen_cur_col);
8640 else
8641 term_windgoto(row, col);
8642 }
8643 screen_cur_row = row;
8644 screen_cur_col = col;
8645 }
8646}
8647
8648/*
8649 * Set cursor to its position in the current window.
8650 */
8651 void
8652setcursor()
8653{
8654 if (redrawing())
8655 {
8656 validate_cursor();
8657 windgoto(W_WINROW(curwin) + curwin->w_wrow,
8658 W_WINCOL(curwin) + (
8659#ifdef FEAT_RIGHTLEFT
Bram Moolenaar561f9db2008-02-20 13:16:29 +00008660 /* With 'rightleft' set and the cursor on a double-wide
8661 * character, position it on the leftmost column. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - (
8663# ifdef FEAT_MBYTE
Bram Moolenaar561f9db2008-02-20 13:16:29 +00008664 (has_mbyte
8665 && (*mb_ptr2cells)(ml_get_cursor()) == 2
8666 && vim_isprintc(gchar_cursor())) ? 2 :
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667# endif
8668 1)) :
8669#endif
8670 curwin->w_wcol));
8671 }
8672}
8673
8674
8675/*
8676 * insert 'line_count' lines at 'row' in window 'wp'
8677 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8678 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8679 * scrolling.
8680 * Returns FAIL if the lines are not inserted, OK for success.
8681 */
8682 int
8683win_ins_lines(wp, row, line_count, invalid, mayclear)
8684 win_T *wp;
8685 int row;
8686 int line_count;
8687 int invalid;
8688 int mayclear;
8689{
8690 int did_delete;
8691 int nextrow;
8692 int lastrow;
8693 int retval;
8694
8695 if (invalid)
8696 wp->w_lines_valid = 0;
8697
8698 if (wp->w_height < 5)
8699 return FAIL;
8700
8701 if (line_count > wp->w_height - row)
8702 line_count = wp->w_height - row;
8703
8704 retval = win_do_lines(wp, row, line_count, mayclear, FALSE);
8705 if (retval != MAYBE)
8706 return retval;
8707
8708 /*
8709 * If there is a next window or a status line, we first try to delete the
8710 * lines at the bottom to avoid messing what is after the window.
8711 * If this fails and there are following windows, don't do anything to avoid
8712 * messing up those windows, better just redraw.
8713 */
8714 did_delete = FALSE;
8715#ifdef FEAT_WINDOWS
8716 if (wp->w_next != NULL || wp->w_status_height)
8717 {
8718 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count,
8719 line_count, (int)Rows, FALSE, NULL) == OK)
8720 did_delete = TRUE;
8721 else if (wp->w_next)
8722 return FAIL;
8723 }
8724#endif
8725 /*
8726 * if no lines deleted, blank the lines that will end up below the window
8727 */
8728 if (!did_delete)
8729 {
8730#ifdef FEAT_WINDOWS
8731 wp->w_redr_status = TRUE;
8732#endif
8733 redraw_cmdline = TRUE;
8734 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp);
8735 lastrow = nextrow + line_count;
8736 if (lastrow > Rows)
8737 lastrow = Rows;
8738 screen_fill(nextrow - line_count, lastrow - line_count,
8739 W_WINCOL(wp), (int)W_ENDCOL(wp),
8740 ' ', ' ', 0);
8741 }
8742
8743 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL)
8744 == FAIL)
8745 {
8746 /* deletion will have messed up other windows */
8747 if (did_delete)
8748 {
8749#ifdef FEAT_WINDOWS
8750 wp->w_redr_status = TRUE;
8751#endif
8752 win_rest_invalid(W_NEXT(wp));
8753 }
8754 return FAIL;
8755 }
8756
8757 return OK;
8758}
8759
8760/*
8761 * delete "line_count" window lines at "row" in window "wp"
8762 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8763 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8764 * scrolling
8765 * Return OK for success, FAIL if the lines are not deleted.
8766 */
8767 int
8768win_del_lines(wp, row, line_count, invalid, mayclear)
8769 win_T *wp;
8770 int row;
8771 int line_count;
8772 int invalid;
8773 int mayclear;
8774{
8775 int retval;
8776
8777 if (invalid)
8778 wp->w_lines_valid = 0;
8779
8780 if (line_count > wp->w_height - row)
8781 line_count = wp->w_height - row;
8782
8783 retval = win_do_lines(wp, row, line_count, mayclear, TRUE);
8784 if (retval != MAYBE)
8785 return retval;
8786
8787 if (screen_del_lines(0, W_WINROW(wp) + row, line_count,
8788 (int)Rows, FALSE, NULL) == FAIL)
8789 return FAIL;
8790
8791#ifdef FEAT_WINDOWS
8792 /*
8793 * If there are windows or status lines below, try to put them at the
8794 * correct place. If we can't do that, they have to be redrawn.
8795 */
8796 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1)
8797 {
8798 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count,
8799 line_count, (int)Rows, NULL) == FAIL)
8800 {
8801 wp->w_redr_status = TRUE;
8802 win_rest_invalid(wp->w_next);
8803 }
8804 }
8805 /*
8806 * If this is the last window and there is no status line, redraw the
8807 * command line later.
8808 */
8809 else
8810#endif
8811 redraw_cmdline = TRUE;
8812 return OK;
8813}
8814
8815/*
8816 * Common code for win_ins_lines() and win_del_lines().
8817 * Returns OK or FAIL when the work has been done.
8818 * Returns MAYBE when not finished yet.
8819 */
8820 static int
8821win_do_lines(wp, row, line_count, mayclear, del)
8822 win_T *wp;
8823 int row;
8824 int line_count;
8825 int mayclear;
8826 int del;
8827{
8828 int retval;
8829
8830 if (!redrawing() || line_count <= 0)
8831 return FAIL;
8832
8833 /* only a few lines left: redraw is faster */
8834 if (mayclear && Rows - line_count < 5
8835#ifdef FEAT_VERTSPLIT
8836 && wp->w_width == Columns
8837#endif
8838 )
8839 {
8840 screenclear(); /* will set wp->w_lines_valid to 0 */
8841 return FAIL;
8842 }
8843
8844 /*
8845 * Delete all remaining lines
8846 */
8847 if (row + line_count >= wp->w_height)
8848 {
8849 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
8850 W_WINCOL(wp), (int)W_ENDCOL(wp),
8851 ' ', ' ', 0);
8852 return OK;
8853 }
8854
8855 /*
8856 * when scrolling, the message on the command line should be cleared,
8857 * otherwise it will stay there forever.
8858 */
8859 clear_cmdline = TRUE;
8860
8861 /*
8862 * If the terminal can set a scroll region, use that.
8863 * Always do this in a vertically split window. This will redraw from
8864 * ScreenLines[] when t_CV isn't defined. That's faster than using
8865 * win_line().
8866 * Don't use a scroll region when we are going to redraw the text, writing
8867 * a character in the lower right corner of the scroll region causes a
8868 * scroll-up in the DJGPP version.
8869 */
8870 if (scroll_region
8871#ifdef FEAT_VERTSPLIT
8872 || W_WIDTH(wp) != Columns
8873#endif
8874 )
8875 {
8876#ifdef FEAT_VERTSPLIT
8877 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
8878#endif
8879 scroll_region_set(wp, row);
8880 if (del)
8881 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count,
8882 wp->w_height - row, FALSE, wp);
8883 else
8884 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count,
8885 wp->w_height - row, wp);
8886#ifdef FEAT_VERTSPLIT
8887 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
8888#endif
8889 scroll_region_reset();
8890 return retval;
8891 }
8892
8893#ifdef FEAT_WINDOWS
8894 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */
8895 return FAIL;
8896#endif
8897
8898 return MAYBE;
8899}
8900
8901/*
8902 * window 'wp' and everything after it is messed up, mark it for redraw
8903 */
8904 static void
8905win_rest_invalid(wp)
8906 win_T *wp;
8907{
8908#ifdef FEAT_WINDOWS
8909 while (wp != NULL)
8910#else
8911 if (wp != NULL)
8912#endif
8913 {
8914 redraw_win_later(wp, NOT_VALID);
8915#ifdef FEAT_WINDOWS
8916 wp->w_redr_status = TRUE;
8917 wp = wp->w_next;
8918#endif
8919 }
8920 redraw_cmdline = TRUE;
8921}
8922
8923/*
8924 * The rest of the routines in this file perform screen manipulations. The
8925 * given operation is performed physically on the screen. The corresponding
8926 * change is also made to the internal screen image. In this way, the editor
8927 * anticipates the effect of editing changes on the appearance of the screen.
8928 * That way, when we call screenupdate a complete redraw isn't usually
8929 * necessary. Another advantage is that we can keep adding code to anticipate
8930 * screen changes, and in the meantime, everything still works.
8931 */
8932
8933/*
8934 * types for inserting or deleting lines
8935 */
8936#define USE_T_CAL 1
8937#define USE_T_CDL 2
8938#define USE_T_AL 3
8939#define USE_T_CE 4
8940#define USE_T_DL 5
8941#define USE_T_SR 6
8942#define USE_NL 7
8943#define USE_T_CD 8
8944#define USE_REDRAW 9
8945
8946/*
8947 * insert lines on the screen and update ScreenLines[]
8948 * 'end' is the line after the scrolled part. Normally it is Rows.
8949 * When scrolling region used 'off' is the offset from the top for the region.
8950 * 'row' and 'end' are relative to the start of the region.
8951 *
8952 * return FAIL for failure, OK for success.
8953 */
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00008954 int
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955screen_ins_lines(off, row, line_count, end, wp)
8956 int off;
8957 int row;
8958 int line_count;
8959 int end;
8960 win_T *wp; /* NULL or window to use width from */
8961{
8962 int i;
8963 int j;
8964 unsigned temp;
8965 int cursor_row;
8966 int type;
8967 int result_empty;
8968 int can_ce = can_clear(T_CE);
8969
8970 /*
8971 * FAIL if
8972 * - there is no valid screen
8973 * - the screen has to be redrawn completely
8974 * - the line count is less than one
8975 * - the line count is more than 'ttyscroll'
8976 */
8977 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll)
8978 return FAIL;
8979
8980 /*
8981 * There are seven ways to insert lines:
8982 * 0. When in a vertically split window and t_CV isn't set, redraw the
8983 * characters from ScreenLines[].
8984 * 1. Use T_CD (clear to end of display) if it exists and the result of
8985 * the insert is just empty lines
8986 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8987 * present or line_count > 1. It looks better if we do all the inserts
8988 * at once.
8989 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8990 * insert is just empty lines and T_CE is not present or line_count >
8991 * 1.
8992 * 4. Use T_AL (insert line) if it exists.
8993 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8994 * just empty lines.
8995 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8996 * just empty lines.
8997 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8998 * the 'da' flag is not set or we have clear line capability.
8999 * 8. redraw the characters from ScreenLines[].
9000 *
9001 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
9002 * the scrollbar for the window. It does have insert line, use that if it
9003 * exists.
9004 */
9005 result_empty = (row + line_count >= end);
9006#ifdef FEAT_VERTSPLIT
9007 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
9008 type = USE_REDRAW;
9009 else
9010#endif
9011 if (can_clear(T_CD) && result_empty)
9012 type = USE_T_CD;
9013 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL))
9014 type = USE_T_CAL;
9015 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce))
9016 type = USE_T_CDL;
9017 else if (*T_AL != NUL)
9018 type = USE_T_AL;
9019 else if (can_ce && result_empty)
9020 type = USE_T_CE;
9021 else if (*T_DL != NUL && result_empty)
9022 type = USE_T_DL;
9023 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce))
9024 type = USE_T_SR;
9025 else
9026 return FAIL;
9027
9028 /*
9029 * For clearing the lines screen_del_lines() is used. This will also take
9030 * care of t_db if necessary.
9031 */
9032 if (type == USE_T_CD || type == USE_T_CDL ||
9033 type == USE_T_CE || type == USE_T_DL)
9034 return screen_del_lines(off, row, line_count, end, FALSE, wp);
9035
9036 /*
9037 * If text is retained below the screen, first clear or delete as many
9038 * lines at the bottom of the window as are about to be inserted so that
9039 * the deleted lines won't later surface during a screen_del_lines.
9040 */
9041 if (*T_DB)
9042 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp);
9043
9044#ifdef FEAT_CLIPBOARD
9045 /* Remove a modeless selection when inserting lines halfway the screen
9046 * or not the full width of the screen. */
9047 if (off + row > 0
9048# ifdef FEAT_VERTSPLIT
9049 || (wp != NULL && wp->w_width != Columns)
9050# endif
9051 )
9052 clip_clear_selection();
9053 else
9054 clip_scroll_selection(-line_count);
9055#endif
9056
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057#ifdef FEAT_GUI
9058 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
9059 * scrolling is actually carried out. */
9060 gui_dont_update_cursor();
9061#endif
9062
9063 if (*T_CCS != NUL) /* cursor relative to region */
9064 cursor_row = row;
9065 else
9066 cursor_row = row + off;
9067
9068 /*
9069 * Shift LineOffset[] line_count down to reflect the inserted lines.
9070 * Clear the inserted lines in ScreenLines[].
9071 */
9072 row += off;
9073 end += off;
9074 for (i = 0; i < line_count; ++i)
9075 {
9076#ifdef FEAT_VERTSPLIT
9077 if (wp != NULL && wp->w_width != Columns)
9078 {
9079 /* need to copy part of a line */
9080 j = end - 1 - i;
9081 while ((j -= line_count) >= row)
9082 linecopy(j + line_count, j, wp);
9083 j += line_count;
9084 if (can_clear((char_u *)" "))
9085 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width);
9086 else
9087 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
9088 LineWraps[j] = FALSE;
9089 }
9090 else
9091#endif
9092 {
9093 j = end - 1 - i;
9094 temp = LineOffset[j];
9095 while ((j -= line_count) >= row)
9096 {
9097 LineOffset[j + line_count] = LineOffset[j];
9098 LineWraps[j + line_count] = LineWraps[j];
9099 }
9100 LineOffset[j + line_count] = temp;
9101 LineWraps[j + line_count] = FALSE;
9102 if (can_clear((char_u *)" "))
9103 lineclear(temp, (int)Columns);
9104 else
9105 lineinvalid(temp, (int)Columns);
9106 }
9107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108
9109 screen_stop_highlight();
9110 windgoto(cursor_row, 0);
9111
9112#ifdef FEAT_VERTSPLIT
9113 /* redraw the characters */
9114 if (type == USE_REDRAW)
9115 redraw_block(row, end, wp);
9116 else
9117#endif
9118 if (type == USE_T_CAL)
9119 {
9120 term_append_lines(line_count);
9121 screen_start(); /* don't know where cursor is now */
9122 }
9123 else
9124 {
9125 for (i = 0; i < line_count; i++)
9126 {
9127 if (type == USE_T_AL)
9128 {
9129 if (i && cursor_row != 0)
9130 windgoto(cursor_row, 0);
9131 out_str(T_AL);
9132 }
9133 else /* type == USE_T_SR */
9134 out_str(T_SR);
9135 screen_start(); /* don't know where cursor is now */
9136 }
9137 }
9138
9139 /*
9140 * With scroll-reverse and 'da' flag set we need to clear the lines that
9141 * have been scrolled down into the region.
9142 */
9143 if (type == USE_T_SR && *T_DA)
9144 {
9145 for (i = 0; i < line_count; ++i)
9146 {
9147 windgoto(off + i, 0);
9148 out_str(T_CE);
9149 screen_start(); /* don't know where cursor is now */
9150 }
9151 }
9152
9153#ifdef FEAT_GUI
9154 gui_can_update_cursor();
9155 if (gui.in_use)
9156 out_flush(); /* always flush after a scroll */
9157#endif
9158 return OK;
9159}
9160
9161/*
9162 * delete lines on the screen and update ScreenLines[]
9163 * 'end' is the line after the scrolled part. Normally it is Rows.
9164 * When scrolling region used 'off' is the offset from the top for the region.
9165 * 'row' and 'end' are relative to the start of the region.
9166 *
9167 * Return OK for success, FAIL if the lines are not deleted.
9168 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 int
9170screen_del_lines(off, row, line_count, end, force, wp)
9171 int off;
9172 int row;
9173 int line_count;
9174 int end;
9175 int force; /* even when line_count > p_ttyscroll */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00009176 win_T *wp UNUSED; /* NULL or window to use width from */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177{
9178 int j;
9179 int i;
9180 unsigned temp;
9181 int cursor_row;
9182 int cursor_end;
9183 int result_empty; /* result is empty until end of region */
9184 int can_delete; /* deleting line codes can be used */
9185 int type;
9186
9187 /*
9188 * FAIL if
9189 * - there is no valid screen
9190 * - the screen has to be redrawn completely
9191 * - the line count is less than one
9192 * - the line count is more than 'ttyscroll'
9193 */
9194 if (!screen_valid(TRUE) || line_count <= 0 ||
9195 (!force && line_count > p_ttyscroll))
9196 return FAIL;
9197
9198 /*
9199 * Check if the rest of the current region will become empty.
9200 */
9201 result_empty = row + line_count >= end;
9202
9203 /*
9204 * We can delete lines only when 'db' flag not set or when 'ce' option
9205 * available.
9206 */
9207 can_delete = (*T_DB == NUL || can_clear(T_CE));
9208
9209 /*
9210 * There are six ways to delete lines:
9211 * 0. When in a vertically split window and t_CV isn't set, redraw the
9212 * characters from ScreenLines[].
9213 * 1. Use T_CD if it exists and the result is empty.
9214 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
9215 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
9216 * none of the other ways work.
9217 * 4. Use T_CE (erase line) if the result is empty.
9218 * 5. Use T_DL (delete line) if it exists.
9219 * 6. redraw the characters from ScreenLines[].
9220 */
9221#ifdef FEAT_VERTSPLIT
9222 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
9223 type = USE_REDRAW;
9224 else
9225#endif
9226 if (can_clear(T_CD) && result_empty)
9227 type = USE_T_CD;
9228#if defined(__BEOS__) && defined(BEOS_DR8)
9229 /*
9230 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
9231 * its internal termcap... this works okay for tests which test *T_DB !=
9232 * NUL. It has the disadvantage that the user cannot use any :set t_*
9233 * command to get T_DB (back) to empty_option, only :set term=... will do
9234 * the trick...
9235 * Anyway, this hack will hopefully go away with the next OS release.
9236 * (Olaf Seibert)
9237 */
9238 else if (row == 0 && T_DB == empty_option
9239 && (line_count == 1 || *T_CDL == NUL))
9240#else
9241 else if (row == 0 && (
9242#ifndef AMIGA
9243 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
9244 * up, so use delete-line command */
9245 line_count == 1 ||
9246#endif
9247 *T_CDL == NUL))
9248#endif
9249 type = USE_NL;
9250 else if (*T_CDL != NUL && line_count > 1 && can_delete)
9251 type = USE_T_CDL;
9252 else if (can_clear(T_CE) && result_empty
9253#ifdef FEAT_VERTSPLIT
9254 && (wp == NULL || wp->w_width == Columns)
9255#endif
9256 )
9257 type = USE_T_CE;
9258 else if (*T_DL != NUL && can_delete)
9259 type = USE_T_DL;
9260 else if (*T_CDL != NUL && can_delete)
9261 type = USE_T_CDL;
9262 else
9263 return FAIL;
9264
9265#ifdef FEAT_CLIPBOARD
9266 /* Remove a modeless selection when deleting lines halfway the screen or
9267 * not the full width of the screen. */
9268 if (off + row > 0
9269# ifdef FEAT_VERTSPLIT
9270 || (wp != NULL && wp->w_width != Columns)
9271# endif
9272 )
9273 clip_clear_selection();
9274 else
9275 clip_scroll_selection(line_count);
9276#endif
9277
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278#ifdef FEAT_GUI
9279 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
9280 * scrolling is actually carried out. */
9281 gui_dont_update_cursor();
9282#endif
9283
9284 if (*T_CCS != NUL) /* cursor relative to region */
9285 {
9286 cursor_row = row;
9287 cursor_end = end;
9288 }
9289 else
9290 {
9291 cursor_row = row + off;
9292 cursor_end = end + off;
9293 }
9294
9295 /*
9296 * Now shift LineOffset[] line_count up to reflect the deleted lines.
9297 * Clear the inserted lines in ScreenLines[].
9298 */
9299 row += off;
9300 end += off;
9301 for (i = 0; i < line_count; ++i)
9302 {
9303#ifdef FEAT_VERTSPLIT
9304 if (wp != NULL && wp->w_width != Columns)
9305 {
9306 /* need to copy part of a line */
9307 j = row + i;
9308 while ((j += line_count) <= end - 1)
9309 linecopy(j - line_count, j, wp);
9310 j -= line_count;
9311 if (can_clear((char_u *)" "))
9312 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width);
9313 else
9314 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
9315 LineWraps[j] = FALSE;
9316 }
9317 else
9318#endif
9319 {
9320 /* whole width, moving the line pointers is faster */
9321 j = row + i;
9322 temp = LineOffset[j];
9323 while ((j += line_count) <= end - 1)
9324 {
9325 LineOffset[j - line_count] = LineOffset[j];
9326 LineWraps[j - line_count] = LineWraps[j];
9327 }
9328 LineOffset[j - line_count] = temp;
9329 LineWraps[j - line_count] = FALSE;
9330 if (can_clear((char_u *)" "))
9331 lineclear(temp, (int)Columns);
9332 else
9333 lineinvalid(temp, (int)Columns);
9334 }
9335 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336
9337 screen_stop_highlight();
9338
9339#ifdef FEAT_VERTSPLIT
9340 /* redraw the characters */
9341 if (type == USE_REDRAW)
9342 redraw_block(row, end, wp);
9343 else
9344#endif
9345 if (type == USE_T_CD) /* delete the lines */
9346 {
9347 windgoto(cursor_row, 0);
9348 out_str(T_CD);
9349 screen_start(); /* don't know where cursor is now */
9350 }
9351 else if (type == USE_T_CDL)
9352 {
9353 windgoto(cursor_row, 0);
9354 term_delete_lines(line_count);
9355 screen_start(); /* don't know where cursor is now */
9356 }
9357 /*
9358 * Deleting lines at top of the screen or scroll region: Just scroll
9359 * the whole screen (scroll region) up by outputting newlines on the
9360 * last line.
9361 */
9362 else if (type == USE_NL)
9363 {
9364 windgoto(cursor_end - 1, 0);
9365 for (i = line_count; --i >= 0; )
9366 out_char('\n'); /* cursor will remain on same line */
9367 }
9368 else
9369 {
9370 for (i = line_count; --i >= 0; )
9371 {
9372 if (type == USE_T_DL)
9373 {
9374 windgoto(cursor_row, 0);
9375 out_str(T_DL); /* delete a line */
9376 }
9377 else /* type == USE_T_CE */
9378 {
9379 windgoto(cursor_row + i, 0);
9380 out_str(T_CE); /* erase a line */
9381 }
9382 screen_start(); /* don't know where cursor is now */
9383 }
9384 }
9385
9386 /*
9387 * If the 'db' flag is set, we need to clear the lines that have been
9388 * scrolled up at the bottom of the region.
9389 */
9390 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL))
9391 {
9392 for (i = line_count; i > 0; --i)
9393 {
9394 windgoto(cursor_end - i, 0);
9395 out_str(T_CE); /* erase a line */
9396 screen_start(); /* don't know where cursor is now */
9397 }
9398 }
9399
9400#ifdef FEAT_GUI
9401 gui_can_update_cursor();
9402 if (gui.in_use)
9403 out_flush(); /* always flush after a scroll */
9404#endif
9405
9406 return OK;
9407}
9408
9409/*
9410 * show the current mode and ruler
9411 *
9412 * If clear_cmdline is TRUE, clear the rest of the cmdline.
9413 * If clear_cmdline is FALSE there may be a message there that needs to be
9414 * cleared only if a mode is shown.
9415 * Return the length of the message (0 if no message).
9416 */
9417 int
9418showmode()
9419{
9420 int need_clear;
9421 int length = 0;
9422 int do_mode;
9423 int attr;
9424 int nwr_save;
9425#ifdef FEAT_INS_EXPAND
9426 int sub_attr;
9427#endif
9428
Bram Moolenaar7df351e2006-01-23 22:30:28 +00009429 do_mode = ((p_smd && msg_silent == 0)
9430 && ((State & INSERT)
9431 || restart_edit
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432#ifdef FEAT_VISUAL
9433 || VIsual_active
9434#endif
9435 ));
9436 if (do_mode || Recording)
9437 {
9438 /*
9439 * Don't show mode right now, when not redrawing or inside a mapping.
9440 * Call char_avail() only when we are going to show something, because
9441 * it takes a bit of time.
9442 */
9443 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0)
9444 {
9445 redraw_cmdline = TRUE; /* show mode later */
9446 return 0;
9447 }
9448
9449 nwr_save = need_wait_return;
9450
9451 /* wait a bit before overwriting an important message */
9452 check_for_delay(FALSE);
9453
9454 /* if the cmdline is more than one line high, erase top lines */
9455 need_clear = clear_cmdline;
9456 if (clear_cmdline && cmdline_row < Rows - 1)
9457 msg_clr_cmdline(); /* will reset clear_cmdline */
9458
9459 /* Position on the last line in the window, column 0 */
9460 msg_pos_mode();
9461 cursor_off();
9462 attr = hl_attr(HLF_CM); /* Highlight mode */
9463 if (do_mode)
9464 {
9465 MSG_PUTS_ATTR("--", attr);
9466#if defined(FEAT_XIM)
Bram Moolenaarc236c162008-07-13 17:41:49 +00009467 if (
Bram Moolenaar09092152010-08-08 16:38:42 +02009468# ifdef FEAT_GUI_GTK
Bram Moolenaarc236c162008-07-13 17:41:49 +00009469 preedit_get_status()
Bram Moolenaar09092152010-08-08 16:38:42 +02009470# else
Bram Moolenaarc236c162008-07-13 17:41:49 +00009471 im_get_status()
Bram Moolenaarc236c162008-07-13 17:41:49 +00009472# endif
Bram Moolenaar09092152010-08-08 16:38:42 +02009473 )
Bram Moolenaar0eda7ac2010-06-26 05:38:18 +02009474# ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 MSG_PUTS_ATTR(" IM", attr);
9476# else
9477 MSG_PUTS_ATTR(" XIM", attr);
9478# endif
9479#endif
9480#if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
9481 if (gui.in_use)
9482 {
9483 if (hangul_input_state_get())
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00009484 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 }
9486#endif
9487#ifdef FEAT_INS_EXPAND
9488 if (edit_submode != NULL) /* CTRL-X in Insert mode */
9489 {
9490 /* These messages can get long, avoid a wrap in a narrow
9491 * window. Prefer showing edit_submode_extra. */
9492 length = (Rows - msg_row) * Columns - 3;
9493 if (edit_submode_extra != NULL)
9494 length -= vim_strsize(edit_submode_extra);
9495 if (length > 0)
9496 {
9497 if (edit_submode_pre != NULL)
9498 length -= vim_strsize(edit_submode_pre);
9499 if (length - vim_strsize(edit_submode) > 0)
9500 {
9501 if (edit_submode_pre != NULL)
9502 msg_puts_attr(edit_submode_pre, attr);
9503 msg_puts_attr(edit_submode, attr);
9504 }
9505 if (edit_submode_extra != NULL)
9506 {
9507 MSG_PUTS_ATTR(" ", attr); /* add a space in between */
9508 if ((int)edit_submode_highl < (int)HLF_COUNT)
9509 sub_attr = hl_attr(edit_submode_highl);
9510 else
9511 sub_attr = attr;
9512 msg_puts_attr(edit_submode_extra, sub_attr);
9513 }
9514 }
9515 length = 0;
9516 }
9517 else
9518#endif
9519 {
9520#ifdef FEAT_VREPLACE
9521 if (State & VREPLACE_FLAG)
9522 MSG_PUTS_ATTR(_(" VREPLACE"), attr);
9523 else
9524#endif
9525 if (State & REPLACE_FLAG)
9526 MSG_PUTS_ATTR(_(" REPLACE"), attr);
9527 else if (State & INSERT)
9528 {
9529#ifdef FEAT_RIGHTLEFT
9530 if (p_ri)
9531 MSG_PUTS_ATTR(_(" REVERSE"), attr);
9532#endif
9533 MSG_PUTS_ATTR(_(" INSERT"), attr);
9534 }
9535 else if (restart_edit == 'I')
9536 MSG_PUTS_ATTR(_(" (insert)"), attr);
9537 else if (restart_edit == 'R')
9538 MSG_PUTS_ATTR(_(" (replace)"), attr);
9539 else if (restart_edit == 'V')
9540 MSG_PUTS_ATTR(_(" (vreplace)"), attr);
9541#ifdef FEAT_RIGHTLEFT
9542 if (p_hkmap)
9543 MSG_PUTS_ATTR(_(" Hebrew"), attr);
9544# ifdef FEAT_FKMAP
9545 if (p_fkmap)
9546 MSG_PUTS_ATTR(farsi_text_5, attr);
9547# endif
9548#endif
9549#ifdef FEAT_KEYMAP
9550 if (State & LANGMAP)
9551 {
9552# ifdef FEAT_ARABIC
9553 if (curwin->w_p_arab)
9554 MSG_PUTS_ATTR(_(" Arabic"), attr);
9555 else
9556# endif
9557 MSG_PUTS_ATTR(_(" (lang)"), attr);
9558 }
9559#endif
9560 if ((State & INSERT) && p_paste)
9561 MSG_PUTS_ATTR(_(" (paste)"), attr);
9562
9563#ifdef FEAT_VISUAL
9564 if (VIsual_active)
9565 {
9566 char *p;
9567
9568 /* Don't concatenate separate words to avoid translation
9569 * problems. */
9570 switch ((VIsual_select ? 4 : 0)
9571 + (VIsual_mode == Ctrl_V) * 2
9572 + (VIsual_mode == 'V'))
9573 {
9574 case 0: p = N_(" VISUAL"); break;
9575 case 1: p = N_(" VISUAL LINE"); break;
9576 case 2: p = N_(" VISUAL BLOCK"); break;
9577 case 4: p = N_(" SELECT"); break;
9578 case 5: p = N_(" SELECT LINE"); break;
9579 default: p = N_(" SELECT BLOCK"); break;
9580 }
9581 MSG_PUTS_ATTR(_(p), attr);
9582 }
9583#endif
9584 MSG_PUTS_ATTR(" --", attr);
9585 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00009586
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587 need_clear = TRUE;
9588 }
9589 if (Recording
9590#ifdef FEAT_INS_EXPAND
9591 && edit_submode == NULL /* otherwise it gets too long */
9592#endif
9593 )
9594 {
9595 MSG_PUTS_ATTR(_("recording"), attr);
9596 need_clear = TRUE;
9597 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00009598
9599 mode_displayed = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 if (need_clear || clear_cmdline)
9601 msg_clr_eos();
9602 msg_didout = FALSE; /* overwrite this message */
9603 length = msg_col;
9604 msg_col = 0;
9605 need_wait_return = nwr_save; /* never ask for hit-return for this */
9606 }
9607 else if (clear_cmdline && msg_silent == 0)
9608 /* Clear the whole command line. Will reset "clear_cmdline". */
9609 msg_clr_cmdline();
9610
9611#ifdef FEAT_CMDL_INFO
9612# ifdef FEAT_VISUAL
9613 /* In Visual mode the size of the selected area must be redrawn. */
9614 if (VIsual_active)
9615 clear_showcmd();
9616# endif
9617
9618 /* If the last window has no status line, the ruler is after the mode
9619 * message and must be redrawn */
9620 if (redrawing()
9621# ifdef FEAT_WINDOWS
9622 && lastwin->w_status_height == 0
9623# endif
9624 )
9625 win_redr_ruler(lastwin, TRUE);
9626#endif
9627 redraw_cmdline = FALSE;
9628 clear_cmdline = FALSE;
9629
9630 return length;
9631}
9632
9633/*
9634 * Position for a mode message.
9635 */
9636 static void
9637msg_pos_mode()
9638{
9639 msg_col = 0;
9640 msg_row = Rows - 1;
9641}
9642
9643/*
9644 * Delete mode message. Used when ESC is typed which is expected to end
9645 * Insert mode (but Insert mode didn't end yet!).
Bram Moolenaard12f5c12006-01-25 22:10:52 +00009646 * Caller should check "mode_displayed".
Bram Moolenaar071d4272004-06-13 20:20:40 +00009647 */
9648 void
9649unshowmode(force)
9650 int force;
9651{
9652 /*
Bram Moolenaare4ebd292010-01-19 17:40:46 +01009653 * Don't delete it right now, when not redrawing or inside a mapping.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 */
9655 if (!redrawing() || (!force && char_avail() && !KeyTyped))
9656 redraw_cmdline = TRUE; /* delete mode later */
9657 else
9658 {
9659 msg_pos_mode();
9660 if (Recording)
9661 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM));
9662 msg_clr_eos();
9663 }
9664}
9665
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009666#if defined(FEAT_WINDOWS)
9667/*
9668 * Draw the tab pages line at the top of the Vim window.
9669 */
9670 static void
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009671draw_tabline()
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009672{
9673 int tabcount = 0;
9674 tabpage_T *tp;
9675 int tabwidth;
9676 int col = 0;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00009677 int scol = 0;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009678 int attr;
9679 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00009680 win_T *cwp;
9681 int wincount;
9682 int modified;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009683 int c;
9684 int len;
9685 int attr_sel = hl_attr(HLF_TPS);
9686 int attr_nosel = hl_attr(HLF_TP);
9687 int attr_fill = hl_attr(HLF_TPF);
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00009688 char_u *p;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009689 int room;
9690 int use_sep_chars = (t_colors < 8
9691#ifdef FEAT_GUI
9692 && !gui.in_use
9693#endif
9694 );
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009695
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00009696 redraw_tabline = FALSE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009697
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009698#ifdef FEAT_GUI_TABLINE
Bram Moolenaardb552d602006-03-23 22:59:57 +00009699 /* Take care of a GUI tabline. */
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009700 if (gui_use_tabline())
9701 {
9702 gui_update_tabline();
9703 return;
9704 }
9705#endif
9706
9707 if (tabline_height() < 1)
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009708 return;
9709
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009710#if defined(FEAT_STL_OPT)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00009711
9712 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9713 for (scol = 0; scol < Columns; ++scol)
9714 TabPageIdxs[scol] = 0;
9715
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009716 /* Use the 'tabline' option if it's set. */
9717 if (*p_tal != NUL)
9718 {
Bram Moolenaar238a5642006-02-21 22:12:05 +00009719 int save_called_emsg = called_emsg;
9720
9721 /* Check for an error. If there is one we would loop in redrawing the
9722 * screen. Avoid that by making 'tabline' empty. */
9723 called_emsg = FALSE;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009724 win_redr_custom(NULL, FALSE);
Bram Moolenaar238a5642006-02-21 22:12:05 +00009725 if (called_emsg)
9726 set_string_option_direct((char_u *)"tabline", -1,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009727 (char_u *)"", OPT_FREE, SID_ERROR);
Bram Moolenaar238a5642006-02-21 22:12:05 +00009728 called_emsg |= save_called_emsg;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009729 }
Bram Moolenaar238a5642006-02-21 22:12:05 +00009730 else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009731#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009732 {
Bram Moolenaar238a5642006-02-21 22:12:05 +00009733 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
9734 ++tabcount;
Bram Moolenaarf740b292006-02-16 22:11:02 +00009735
Bram Moolenaar238a5642006-02-21 22:12:05 +00009736 tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
9737 if (tabwidth < 6)
9738 tabwidth = 6;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009739
Bram Moolenaar238a5642006-02-21 22:12:05 +00009740 attr = attr_nosel;
9741 tabcount = 0;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00009742 scol = 0;
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00009743 for (tp = first_tabpage; tp != NULL && col < Columns - 4;
9744 tp = tp->tp_next)
Bram Moolenaarf740b292006-02-16 22:11:02 +00009745 {
Bram Moolenaar238a5642006-02-21 22:12:05 +00009746 scol = col;
Bram Moolenaarf740b292006-02-16 22:11:02 +00009747
Bram Moolenaar238a5642006-02-21 22:12:05 +00009748 if (tp->tp_topframe == topframe)
9749 attr = attr_sel;
9750 if (use_sep_chars && col > 0)
9751 screen_putchar('|', 0, col++, attr);
9752
9753 if (tp->tp_topframe != topframe)
9754 attr = attr_nosel;
9755
9756 screen_putchar(' ', 0, col++, attr);
9757
9758 if (tp == curtab)
Bram Moolenaarf740b292006-02-16 22:11:02 +00009759 {
Bram Moolenaar238a5642006-02-21 22:12:05 +00009760 cwp = curwin;
9761 wp = firstwin;
9762 }
9763 else
9764 {
9765 cwp = tp->tp_curwin;
9766 wp = tp->tp_firstwin;
9767 }
9768
9769 modified = FALSE;
9770 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount)
9771 if (bufIsChanged(wp->w_buffer))
9772 modified = TRUE;
9773 if (modified || wincount > 1)
9774 {
9775 if (wincount > 1)
9776 {
9777 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009778 len = (int)STRLEN(NameBuff);
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00009779 if (col + len >= Columns - 3)
9780 break;
Bram Moolenaar238a5642006-02-21 22:12:05 +00009781 screen_puts_len(NameBuff, len, 0, col,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009782#if defined(FEAT_SYN_HL)
Bram Moolenaar238a5642006-02-21 22:12:05 +00009783 hl_combine_attr(attr, hl_attr(HLF_T))
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009784#else
Bram Moolenaar238a5642006-02-21 22:12:05 +00009785 attr
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009786#endif
Bram Moolenaar238a5642006-02-21 22:12:05 +00009787 );
9788 col += len;
9789 }
9790 if (modified)
9791 screen_puts_len((char_u *)"+", 1, 0, col++, attr);
9792 screen_putchar(' ', 0, col++, attr);
9793 }
9794
9795 room = scol - col + tabwidth - 1;
9796 if (room > 0)
9797 {
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009798 /* Get buffer name in NameBuff[] */
9799 get_trans_bufname(cwp->w_buffer);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00009800 shorten_dir(NameBuff);
Bram Moolenaar238a5642006-02-21 22:12:05 +00009801 len = vim_strsize(NameBuff);
9802 p = NameBuff;
9803#ifdef FEAT_MBYTE
9804 if (has_mbyte)
9805 while (len > room)
9806 {
9807 len -= ptr2cells(p);
9808 mb_ptr_adv(p);
9809 }
9810 else
9811#endif
9812 if (len > room)
9813 {
9814 p += len - room;
9815 len = room;
9816 }
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00009817 if (len > Columns - col - 1)
9818 len = Columns - col - 1;
Bram Moolenaar238a5642006-02-21 22:12:05 +00009819
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009820 screen_puts_len(p, (int)STRLEN(p), 0, col, attr);
Bram Moolenaarf740b292006-02-16 22:11:02 +00009821 col += len;
9822 }
Bram Moolenaarf740b292006-02-16 22:11:02 +00009823 screen_putchar(' ', 0, col++, attr);
Bram Moolenaar238a5642006-02-21 22:12:05 +00009824
9825 /* Store the tab page number in TabPageIdxs[], so that
9826 * jump_to_mouse() knows where each one is. */
9827 ++tabcount;
9828 while (scol < col)
9829 TabPageIdxs[scol++] = tabcount;
Bram Moolenaarf740b292006-02-16 22:11:02 +00009830 }
9831
Bram Moolenaar238a5642006-02-21 22:12:05 +00009832 if (use_sep_chars)
9833 c = '_';
9834 else
9835 c = ' ';
9836 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00009837
9838 /* Put an "X" for closing the current tab if there are several. */
9839 if (first_tabpage->tp_next != NULL)
9840 {
9841 screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
9842 TabPageIdxs[Columns - 1] = -999;
9843 }
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009844 }
Bram Moolenaarb21e5842006-04-16 18:30:08 +00009845
9846 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9847 * set. */
9848 redraw_tabline = FALSE;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009849}
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009850
9851/*
9852 * Get buffer name for "buf" into NameBuff[].
9853 * Takes care of special buffer names and translates special characters.
9854 */
9855 void
9856get_trans_bufname(buf)
9857 buf_T *buf;
9858{
9859 if (buf_spname(buf) != NULL)
9860 STRCPY(NameBuff, buf_spname(buf));
9861 else
9862 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
9863 trans_characters(NameBuff, MAXPATHL);
9864}
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009865#endif
9866
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867#if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9868/*
9869 * Get the character to use in a status line. Get its attributes in "*attr".
9870 */
9871 static int
9872fillchar_status(attr, is_curwin)
9873 int *attr;
9874 int is_curwin;
9875{
9876 int fill;
9877 if (is_curwin)
9878 {
9879 *attr = hl_attr(HLF_S);
9880 fill = fill_stl;
9881 }
9882 else
9883 {
9884 *attr = hl_attr(HLF_SNC);
9885 fill = fill_stlnc;
9886 }
9887 /* Use fill when there is highlighting, and highlighting of current
9888 * window differs, or the fillchars differ, or this is not the
9889 * current window */
9890 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC)
9891 || !is_curwin || firstwin == lastwin)
9892 || (fill_stl != fill_stlnc)))
9893 return fill;
9894 if (is_curwin)
9895 return '^';
9896 return '=';
9897}
9898#endif
9899
9900#ifdef FEAT_VERTSPLIT
9901/*
9902 * Get the character to use in a separator between vertically split windows.
9903 * Get its attributes in "*attr".
9904 */
9905 static int
9906fillchar_vsep(attr)
9907 int *attr;
9908{
9909 *attr = hl_attr(HLF_C);
9910 if (*attr == 0 && fill_vert == ' ')
9911 return '|';
9912 else
9913 return fill_vert;
9914}
9915#endif
9916
9917/*
9918 * Return TRUE if redrawing should currently be done.
9919 */
9920 int
9921redrawing()
9922{
9923 return (!RedrawingDisabled
9924 && !(p_lz && char_avail() && !KeyTyped && !do_redraw));
9925}
9926
9927/*
9928 * Return TRUE if printing messages should currently be done.
9929 */
9930 int
9931messaging()
9932{
9933 return (!(p_lz && char_avail() && !KeyTyped));
9934}
9935
9936/*
9937 * Show current status info in ruler and various other places
9938 * If always is FALSE, only show ruler if position has changed.
9939 */
9940 void
9941showruler(always)
9942 int always;
9943{
9944 if (!always && !redrawing())
9945 return;
Bram Moolenaar9372a112005-12-06 19:59:18 +00009946#ifdef FEAT_INS_EXPAND
9947 if (pum_visible())
9948 {
Bram Moolenaar71fe80d2006-01-22 23:25:56 +00009949# ifdef FEAT_WINDOWS
Bram Moolenaar9372a112005-12-06 19:59:18 +00009950 /* Don't redraw right now, do it later. */
9951 curwin->w_redr_status = TRUE;
Bram Moolenaar71fe80d2006-01-22 23:25:56 +00009952# endif
Bram Moolenaar9372a112005-12-06 19:59:18 +00009953 return;
9954 }
9955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956#if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009957 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height)
Bram Moolenaar238a5642006-02-21 22:12:05 +00009958 {
Bram Moolenaar362f3562009-11-03 16:20:34 +00009959 redraw_custom_statusline(curwin);
Bram Moolenaar238a5642006-02-21 22:12:05 +00009960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 else
9962#endif
9963#ifdef FEAT_CMDL_INFO
9964 win_redr_ruler(curwin, always);
9965#endif
9966
9967#ifdef FEAT_TITLE
9968 if (need_maketitle
9969# ifdef FEAT_STL_OPT
9970 || (p_icon && (stl_syntax & STL_IN_ICON))
9971 || (p_title && (stl_syntax & STL_IN_TITLE))
9972# endif
9973 )
9974 maketitle();
9975#endif
Bram Moolenaar497683b2008-05-28 17:02:46 +00009976#ifdef FEAT_WINDOWS
9977 /* Redraw the tab pages line if needed. */
9978 if (redraw_tabline)
9979 draw_tabline();
9980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981}
9982
9983#ifdef FEAT_CMDL_INFO
9984 static void
9985win_redr_ruler(wp, always)
9986 win_T *wp;
9987 int always;
9988{
Bram Moolenaar0ab2a882009-05-13 10:51:08 +00009989#define RULER_BUF_LEN 70
9990 char_u buffer[RULER_BUF_LEN];
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991 int row;
9992 int fillchar;
9993 int attr;
9994 int empty_line = FALSE;
9995 colnr_T virtcol;
9996 int i;
Bram Moolenaar0ab2a882009-05-13 10:51:08 +00009997 size_t len;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998 int o;
9999#ifdef FEAT_VERTSPLIT
10000 int this_ru_col;
10001 int off = 0;
10002 int width = Columns;
10003# define WITH_OFF(x) x
10004# define WITH_WIDTH(x) x
10005#else
10006# define WITH_OFF(x) 0
10007# define WITH_WIDTH(x) Columns
10008# define this_ru_col ru_col
10009#endif
10010
10011 /* If 'ruler' off or redrawing disabled, don't do anything */
10012 if (!p_ru)
10013 return;
10014
10015 /*
10016 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
10017 * after deleting lines, before cursor.lnum is corrected.
10018 */
10019 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
10020 return;
10021
10022#ifdef FEAT_INS_EXPAND
10023 /* Don't draw the ruler while doing insert-completion, it might overwrite
10024 * the (long) mode message. */
10025# ifdef FEAT_WINDOWS
10026 if (wp == lastwin && lastwin->w_status_height == 0)
10027# endif
10028 if (edit_submode != NULL)
10029 return;
Bram Moolenaar1c7715d2005-10-03 22:02:18 +000010030 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
10031 if (pum_visible())
10032 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033#endif
10034
10035#ifdef FEAT_STL_OPT
10036 if (*p_ruf)
10037 {
Bram Moolenaar238a5642006-02-21 22:12:05 +000010038 int save_called_emsg = called_emsg;
10039
10040 called_emsg = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041 win_redr_custom(wp, TRUE);
Bram Moolenaar238a5642006-02-21 22:12:05 +000010042 if (called_emsg)
10043 set_string_option_direct((char_u *)"rulerformat", -1,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010044 (char_u *)"", OPT_FREE, SID_ERROR);
Bram Moolenaar238a5642006-02-21 22:12:05 +000010045 called_emsg |= save_called_emsg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 return;
10047 }
10048#endif
10049
10050 /*
10051 * Check if not in Insert mode and the line is empty (will show "0-1").
10052 */
10053 if (!(State & INSERT)
10054 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
10055 empty_line = TRUE;
10056
10057 /*
10058 * Only draw the ruler when something changed.
10059 */
10060 validate_virtcol_win(wp);
10061 if ( redraw_cmdline
10062 || always
10063 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum
10064 || wp->w_cursor.col != wp->w_ru_cursor.col
10065 || wp->w_virtcol != wp->w_ru_virtcol
10066#ifdef FEAT_VIRTUALEDIT
10067 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd
10068#endif
10069 || wp->w_topline != wp->w_ru_topline
10070 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count
10071#ifdef FEAT_DIFF
10072 || wp->w_topfill != wp->w_ru_topfill
10073#endif
10074 || empty_line != wp->w_ru_empty)
10075 {
10076 cursor_off();
10077#ifdef FEAT_WINDOWS
10078 if (wp->w_status_height)
10079 {
10080 row = W_WINROW(wp) + wp->w_height;
10081 fillchar = fillchar_status(&attr, wp == curwin);
10082# ifdef FEAT_VERTSPLIT
10083 off = W_WINCOL(wp);
10084 width = W_WIDTH(wp);
10085# endif
10086 }
10087 else
10088#endif
10089 {
10090 row = Rows - 1;
10091 fillchar = ' ';
10092 attr = 0;
10093#ifdef FEAT_VERTSPLIT
10094 width = Columns;
10095 off = 0;
10096#endif
10097 }
10098
10099 /* In list mode virtcol needs to be recomputed */
10100 virtcol = wp->w_virtcol;
10101 if (wp->w_p_list && lcs_tab1 == NUL)
10102 {
10103 wp->w_p_list = FALSE;
10104 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
10105 wp->w_p_list = TRUE;
10106 }
10107
10108 /*
10109 * Some sprintfs return the length, some return a pointer.
10110 * To avoid portability problems we use strlen() here.
10111 */
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000010112 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,",
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
10114 ? 0L
10115 : (long)(wp->w_cursor.lnum));
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000010116 len = STRLEN(buffer);
10117 col_print(buffer + len, RULER_BUF_LEN - len,
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 empty_line ? 0 : (int)wp->w_cursor.col + 1,
10119 (int)virtcol + 1);
10120
10121 /*
10122 * Add a "50%" if there is room for it.
10123 * On the last line, don't print in the last column (scrolls the
10124 * screen up on some terminals).
10125 */
10126 i = (int)STRLEN(buffer);
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000010127 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128 o = i + vim_strsize(buffer + i + 1);
10129#ifdef FEAT_WINDOWS
10130 if (wp->w_status_height == 0) /* can't use last char of screen */
10131#endif
10132 ++o;
10133#ifdef FEAT_VERTSPLIT
10134 this_ru_col = ru_col - (Columns - width);
10135 if (this_ru_col < 0)
10136 this_ru_col = 0;
10137#endif
10138 /* Never use more than half the window/screen width, leave the other
10139 * half for the filename. */
10140 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2)
10141 this_ru_col = (WITH_WIDTH(width) + 1) / 2;
10142 if (this_ru_col + o < WITH_WIDTH(width))
10143 {
10144 while (this_ru_col + o < WITH_WIDTH(width))
10145 {
10146#ifdef FEAT_MBYTE
10147 if (has_mbyte)
10148 i += (*mb_char2bytes)(fillchar, buffer + i);
10149 else
10150#endif
10151 buffer[i++] = fillchar;
10152 ++o;
10153 }
Bram Moolenaar0ab2a882009-05-13 10:51:08 +000010154 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155 }
10156 /* Truncate at window boundary. */
10157#ifdef FEAT_MBYTE
10158 if (has_mbyte)
10159 {
10160 o = 0;
Bram Moolenaar0fa313a2005-08-10 21:07:57 +000010161 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162 {
10163 o += (*mb_ptr2cells)(buffer + i);
10164 if (this_ru_col + o > WITH_WIDTH(width))
10165 {
10166 buffer[i] = NUL;
10167 break;
10168 }
10169 }
10170 }
10171 else
10172#endif
10173 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width))
10174 buffer[WITH_WIDTH(width) - this_ru_col] = NUL;
10175
10176 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr);
10177 i = redraw_cmdline;
10178 screen_fill(row, row + 1,
10179 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer),
10180 (int)(WITH_OFF(off) + WITH_WIDTH(width)),
10181 fillchar, fillchar, attr);
10182 /* don't redraw the cmdline because of showing the ruler */
10183 redraw_cmdline = i;
10184 wp->w_ru_cursor = wp->w_cursor;
10185 wp->w_ru_virtcol = wp->w_virtcol;
10186 wp->w_ru_empty = empty_line;
10187 wp->w_ru_topline = wp->w_topline;
10188 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count;
10189#ifdef FEAT_DIFF
10190 wp->w_ru_topfill = wp->w_topfill;
10191#endif
10192 }
10193}
10194#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010195
10196#if defined(FEAT_LINEBREAK) || defined(PROTO)
10197/*
Bram Moolenaar64486672010-05-16 15:46:46 +020010198 * Return the width of the 'number' and 'relativenumber' column.
10199 * Caller may need to check if 'number' or 'relativenumber' is set.
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010200 * Otherwise it depends on 'numberwidth' and the line count.
10201 */
10202 int
10203number_width(wp)
10204 win_T *wp;
10205{
10206 int n;
10207 linenr_T lnum;
10208
Bram Moolenaar64486672010-05-16 15:46:46 +020010209 if (wp->w_p_nu)
10210 /* 'number' */
10211 lnum = wp->w_buffer->b_ml.ml_line_count;
10212 else
10213 /* 'relativenumber' */
10214 lnum = wp->w_height;
10215
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010216 if (lnum == wp->w_nrwidth_line_count)
10217 return wp->w_nrwidth_width;
10218 wp->w_nrwidth_line_count = lnum;
10219
10220 n = 0;
10221 do
10222 {
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000010223 lnum /= 10;
10224 ++n;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010225 } while (lnum > 0);
10226
10227 /* 'numberwidth' gives the minimal width plus one */
10228 if (n < wp->w_p_nuw - 1)
10229 n = wp->w_p_nuw - 1;
10230
10231 wp->w_nrwidth_width = n;
10232 return n;
10233}
10234#endif