1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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.
11 * screen.c: code for displaying on the screen
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
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[]
22 * LineWraps[row] Flag for each line whether it wraps to the next line.
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
28 * character without composing chars ScreenLinesUC[] will be 0. When the
29 * character occupies two display cells the next byte in ScreenLines[] is 0.
30 * ScreenLinesC[][] contain up to 'maxcombine' composing characters
31 * (drawn on top of the first character). They are 0 when not used.
32 * ScreenLines2[] is only used for euc-jp to store the second byte if the
33 * first byte is 0x8e (single-width character).
35 * The screen_*() functions write to the screen and handle updating
38 * update_screen() is the function that updates all windows and status lines.
39 * It is called form the main loop when must_redraw is non-zero. It may be
40 * called from other places when an immediate screen update is needed.
42 * The part of the buffer that is displayed in a window is set with:
43 * - w_topline (first buffer line in window)
44 * - w_topfill (filler line above the first line)
45 * - w_leftcol (leftmost window cell in window),
46 * - w_skipcol (skipped window cells of first line)
48 * Commands that only move the cursor around in a window, do not need to take
49 * action to update the display. The main loop will check if w_topline is
50 * valid and update it (scroll the window) when needed.
52 * Commands that scroll a window change w_topline and must call
53 * check_cursor() to move the cursor into the visible part of the window, and
54 * call redraw_later(VALID) to have the window displayed by update_screen()
57 * Commands that change text in the buffer must call changed_bytes() or
58 * changed_lines() to mark the area that changed and will require updating
59 * later. The main loop will call update_screen(), which will update each
60 * window that shows the changed buffer. This assumes text above the change
61 * can remain displayed as it is. Text after the change may need updating for
62 * scrolling, folding and syntax highlighting.
64 * Commands that change how a window is displayed (e.g., setting 'list') or
65 * invalidate the contents of a window in another way (e.g., change fold
66 * settings), must call redraw_later(NOT_VALID) to have the whole window
67 * redisplayed by update_screen() later.
69 * Commands that change how a buffer is displayed (e.g., setting 'tabstop')
70 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the
71 * buffer redisplayed by update_screen() later.
73 * Commands that change highlighting and possibly cause a scroll too must call
74 * redraw_later(SOME_VALID) to update the whole window but still use scrolling
75 * to avoid redrawing everything. But the length of displayed lines must not
76 * change, use NOT_VALID then.
78 * Commands that move the window position must call redraw_later(NOT_VALID).
79 * TODO: should minimize redrawing by scrolling when possible.
81 * Commands that change everything (e.g., resizing the screen) must call
82 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR).
84 * Things that are handled indirectly:
85 * - When messages scroll the screen up, msg_scrolled will be set and
86 * update_screen() called to redraw.
92 * The attributes that are actually active for writing to the screen.
94 static int screen_attr
= 0;
97 * Positioning the cursor is reduced by remembering the last position.
98 * Mostly used by windgoto() and screen_char().
100 static int screen_cur_row
, screen_cur_col
; /* last known cursor position */
102 #ifdef FEAT_SEARCH_EXTRA
103 static match_T search_hl
; /* used for 'hlsearch' highlight matching */
107 static foldinfo_T win_foldinfo
; /* info for 'foldcolumn' */
111 * Buffer for one screen line (characters and attributes).
113 static schar_T
*current_ScreenLine
;
115 static void win_update
__ARGS((win_T
*wp
));
116 static void win_draw_end
__ARGS((win_T
*wp
, int c1
, int c2
, int row
, int endrow
, hlf_T hl
));
118 static void fold_line
__ARGS((win_T
*wp
, long fold_count
, foldinfo_T
*foldinfo
, linenr_T lnum
, int row
));
119 static void fill_foldcolumn
__ARGS((char_u
*p
, win_T
*wp
, int closed
, linenr_T lnum
));
120 static void copy_text_attr
__ARGS((int off
, char_u
*buf
, int len
, int attr
));
122 static int win_line
__ARGS((win_T
*, linenr_T
, int, int, int nochange
));
123 static int char_needs_redraw
__ARGS((int off_from
, int off_to
, int cols
));
124 #ifdef FEAT_RIGHTLEFT
125 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
, int rlflag
));
126 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl))
128 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
));
129 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c))
131 #ifdef FEAT_VERTSPLIT
132 static void draw_vsep_win
__ARGS((win_T
*wp
, int row
));
135 static void redraw_custum_statusline
__ARGS((win_T
*wp
));
137 #ifdef FEAT_SEARCH_EXTRA
138 #define SEARCH_HL_PRIORITY 0
139 static void start_search_hl
__ARGS((void));
140 static void end_search_hl
__ARGS((void));
141 static void prepare_search_hl
__ARGS((win_T
*wp
, linenr_T lnum
));
142 static void next_search_hl
__ARGS((win_T
*win
, match_T
*shl
, linenr_T lnum
, colnr_T mincol
));
144 static void screen_start_highlight
__ARGS((int attr
));
145 static void screen_char
__ARGS((unsigned off
, int row
, int col
));
147 static void screen_char_2
__ARGS((unsigned off
, int row
, int col
));
149 static void screenclear2
__ARGS((void));
150 static void lineclear
__ARGS((unsigned off
, int width
));
151 static void lineinvalid
__ARGS((unsigned off
, int width
));
152 #ifdef FEAT_VERTSPLIT
153 static void linecopy
__ARGS((int to
, int from
, win_T
*wp
));
154 static void redraw_block
__ARGS((int row
, int end
, win_T
*wp
));
156 static int win_do_lines
__ARGS((win_T
*wp
, int row
, int line_count
, int mayclear
, int del
));
157 static void win_rest_invalid
__ARGS((win_T
*wp
));
158 static void msg_pos_mode
__ARGS((void));
159 #if defined(FEAT_WINDOWS)
160 static void draw_tabline
__ARGS((void));
162 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
163 static int fillchar_status
__ARGS((int *attr
, int is_curwin
));
165 #ifdef FEAT_VERTSPLIT
166 static int fillchar_vsep
__ARGS((int *attr
));
169 static void win_redr_custom
__ARGS((win_T
*wp
, int draw_ruler
));
171 #ifdef FEAT_CMDL_INFO
172 static void win_redr_ruler
__ARGS((win_T
*wp
, int always
));
175 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
176 /* Ugly global: overrule attribute used by screen_char() */
177 static int screen_char_attr
= 0;
181 * Redraw the current window later, with update_screen(type).
182 * Set must_redraw only if not already set to a higher value.
183 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
189 redraw_win_later(curwin
, type
);
193 redraw_win_later(wp
, type
)
197 if (wp
->w_redr_type
< type
)
199 wp
->w_redr_type
= type
;
200 if (type
>= NOT_VALID
)
201 wp
->w_lines_valid
= 0;
202 if (must_redraw
< type
) /* must_redraw is the maximum of all windows */
208 * Force a complete redraw later. Also resets the highlighting. To be used
209 * after executing a shell command that messes up the screen.
214 redraw_all_later(CLEAR
);
217 /* Use a code that will reset gui.highlight_mask in
218 * gui_stop_highlight(). */
219 screen_attr
= HL_ALL
+ 1;
222 /* Use attributes that is very unlikely to appear in text. */
223 screen_attr
= HL_BOLD
| HL_UNDERLINE
| HL_INVERSE
;
227 * Mark all windows to be redrawn later.
230 redraw_all_later(type
)
237 redraw_win_later(wp
, type
);
242 * Mark all windows that are editing the current buffer to be updated later.
245 redraw_curbuf_later(type
)
248 redraw_buf_later(curbuf
, type
);
252 redraw_buf_later(buf
, type
)
260 if (wp
->w_buffer
== buf
)
261 redraw_win_later(wp
, type
);
266 * Changed something in the current window, at buffer line "lnum", that
267 * requires that line and possibly other lines to be redrawn.
268 * Used when entering/leaving Insert mode with the cursor on a folded line.
269 * Used to remove the "$" from a change command.
270 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
271 * may become invalid and the whole window will have to be redrawn.
275 redrawWinline(lnum
, invalid
)
277 int invalid
; /* window line height is invalid now */
283 if (curwin
->w_redraw_top
== 0 || curwin
->w_redraw_top
> lnum
)
284 curwin
->w_redraw_top
= lnum
;
285 if (curwin
->w_redraw_bot
== 0 || curwin
->w_redraw_bot
< lnum
)
286 curwin
->w_redraw_bot
= lnum
;
292 /* A w_lines[] entry for this lnum has become invalid. */
293 i
= find_wl_entry(curwin
, lnum
);
295 curwin
->w_lines
[i
].wl_valid
= FALSE
;
301 * update all windows that are editing the current buffer
307 redraw_curbuf_later(type
);
314 * Based on the current value of curwin->w_topline, transfer a screenfull
315 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
322 static int did_intro
= FALSE
;
323 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
327 if (!screen_valid(TRUE
))
332 if (type
< must_redraw
) /* use maximal type */
335 /* must_redraw is reset here, so that when we run into some weird
336 * reason to redraw while busy redrawing (e.g., asynchronous
337 * scrolling), or update_topline() in win_update() will cause a
338 * scroll, the screen will be redrawn later or in win_update(). */
342 /* Need to update w_lines[]. */
343 if (curwin
->w_lines_valid
== 0 && type
< NOT_VALID
)
348 redraw_later(type
); /* remember type for next time */
350 if (type
> INVERTED_ALL
)
351 curwin
->w_lines_valid
= 0; /* don't use w_lines[].wl_size now */
355 updating_screen
= TRUE
;
357 ++display_tick
; /* let syntax code know we're in a next round of
358 * display updating */
362 * if the screen was scrolled up when displaying a message, scroll it down
366 clear_cmdline
= TRUE
;
367 if (msg_scrolled
> Rows
- 5) /* clearing is faster */
369 else if (type
!= CLEAR
)
371 check_for_delay(FALSE
);
372 if (screen_ins_lines(0, 0, msg_scrolled
, (int)Rows
, NULL
) == FAIL
)
376 if (W_WINROW(wp
) < msg_scrolled
)
378 if (W_WINROW(wp
) + wp
->w_height
> msg_scrolled
379 && wp
->w_redr_type
< REDRAW_TOP
380 && wp
->w_lines_valid
> 0
381 && wp
->w_topline
== wp
->w_lines
[0].wl_lnum
)
383 wp
->w_upd_rows
= msg_scrolled
- W_WINROW(wp
);
384 wp
->w_redr_type
= REDRAW_TOP
;
388 wp
->w_redr_type
= NOT_VALID
;
390 if (W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
)
392 wp
->w_redr_status
= TRUE
;
397 redraw_cmdline
= TRUE
;
399 redraw_tabline
= TRUE
;
403 need_wait_return
= FALSE
;
406 /* reset cmdline_row now (may have been changed temporarily) */
409 /* Check for changed highlighting */
410 if (need_highlight_changed
)
413 if (type
== CLEAR
) /* first clear screen */
415 screenclear(); /* will reset clear_cmdline */
419 if (clear_cmdline
) /* going to clear cmdline (done below) */
420 check_for_delay(FALSE
);
422 #ifdef FEAT_LINEBREAK
423 /* Force redraw when width of 'number' column changes. */
424 if (curwin
->w_redr_type
< NOT_VALID
425 && curwin
->w_nrwidth
!= (curwin
->w_p_nu
? number_width(curwin
) : 0))
426 curwin
->w_redr_type
= NOT_VALID
;
430 * Only start redrawing if there is really something to do.
432 if (type
== INVERTED
)
434 if (curwin
->w_redr_type
< type
436 && curwin
->w_lines
[0].wl_valid
438 && curwin
->w_topfill
== curwin
->w_old_topfill
439 && curwin
->w_botfill
== curwin
->w_old_botfill
441 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
445 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
446 && curwin
->w_old_visual_mode
== VIsual_mode
447 && (curwin
->w_valid
& VALID_VIRTCOL
)
448 && curwin
->w_old_curswant
== curwin
->w_curswant
)
451 curwin
->w_redr_type
= type
;
454 /* Redraw the tab pages line if needed. */
455 if (redraw_tabline
|| type
>= NOT_VALID
)
461 * Correct stored syntax highlighting info for changes in each displayed
462 * buffer. Each buffer must only be done once.
466 if (wp
->w_buffer
->b_mod_set
)
471 /* Check if we already did this buffer. */
472 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
473 if (wwp
->w_buffer
== wp
->w_buffer
)
480 syntax_present(wp
->w_buffer
))
481 syn_stack_apply_changes(wp
->w_buffer
);
487 * Go from top to bottom through the windows, redrawing the ones that need
490 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
493 #ifdef FEAT_SEARCH_EXTRA
494 search_hl
.rm
.regprog
= NULL
;
498 if (wp
->w_redr_type
!= 0)
501 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
505 # ifdef FEAT_SEARCH_EXTRA
508 # ifdef FEAT_CLIPBOARD
509 /* When Visual area changed, may have to update selection. */
510 if (clip_star
.available
&& clip_isautosel())
511 clip_update_selection();
514 /* Remove the cursor before starting to do anything, because
515 * scrolling may make it difficult to redraw the text under
526 /* redraw status line after the window to minimize cursor movement */
527 if (wp
->w_redr_status
)
534 #if defined(FEAT_SEARCH_EXTRA)
539 /* Reset b_mod_set flags. Going through all windows is probably faster
540 * than going through all buffers (there could be many buffers). */
541 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
542 wp
->w_buffer
->b_mod_set
= FALSE
;
544 curbuf
->b_mod_set
= FALSE
;
547 updating_screen
= FALSE
;
549 gui_may_resize_shell();
552 /* Clear or redraw the command line. Done last, because scrolling may
553 * mess up the command line. */
554 if (clear_cmdline
|| redraw_cmdline
)
557 /* May put up an introductory message when not editing a file */
558 if (!did_intro
&& bufempty()
559 && curbuf
->b_fname
== NULL
561 && firstwin
->w_next
== NULL
563 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
564 intro_message(FALSE
);
568 /* Redraw the cursor and update the scrollbars when all screen updating is
572 out_flush(); /* required before updating the cursor */
574 gui_update_cursor(FALSE
, FALSE
);
575 gui_update_scrollbars(FALSE
);
580 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
581 static void update_prepare
__ARGS((void));
582 static void update_finish
__ARGS((void));
585 * Prepare for updating one or more windows.
591 updating_screen
= TRUE
;
593 /* Remove the cursor before starting to do anything, because scrolling may
594 * make it difficult to redraw the text under it. */
598 #ifdef FEAT_SEARCH_EXTRA
604 * Finish updating one or more windows.
612 # ifdef FEAT_SEARCH_EXTRA
616 updating_screen
= FALSE
;
619 gui_may_resize_shell();
621 /* Redraw the cursor and update the scrollbars when all screen updating is
625 out_flush(); /* required before updating the cursor */
626 gui_update_cursor(FALSE
, FALSE
);
627 gui_update_scrollbars(FALSE
);
633 #if defined(FEAT_SIGNS) || defined(PROTO)
635 update_debug_sign(buf
, lnum
)
643 win_foldinfo
.fi_level
= 0;
646 /* update/delete a specific mark */
649 if (buf
!= NULL
&& lnum
> 0)
651 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
652 && lnum
< wp
->w_botline
)
654 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
655 wp
->w_redraw_top
= lnum
;
656 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
657 wp
->w_redraw_bot
= lnum
;
658 redraw_win_later(wp
, VALID
);
662 redraw_win_later(wp
, VALID
);
663 if (wp
->w_redr_type
!= 0)
670 /* update all windows that need updating */
674 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
676 if (wp
->w_redr_type
!= 0)
678 if (wp
->w_redr_status
)
682 if (curwin
->w_redr_type
!= 0)
691 #if defined(FEAT_GUI) || defined(PROTO)
693 * Update a single window, its status line and maybe the command line msg.
694 * Used for the GUI scrollbar.
702 #ifdef FEAT_CLIPBOARD
703 /* When Visual area changed, may have to update selection. */
704 if (clip_star
.available
&& clip_isautosel())
705 clip_update_selection();
711 /* When the screen was cleared redraw the tab pages line. */
715 if (wp
->w_redr_status
716 # ifdef FEAT_CMDL_INFO
720 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
731 * Update a single window.
733 * This may cause the windows below it also to be redrawn (when clearing the
734 * screen or scrolling lines).
736 * How the window is redrawn depends on wp->w_redr_type. Each type also
737 * implies the one below it.
738 * NOT_VALID redraw the whole window
739 * SOME_VALID redraw the whole window but do scroll when possible
740 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
741 * INVERTED redraw the changed part of the Visual area
742 * INVERTED_ALL redraw the whole Visual area
743 * VALID 1. scroll up/down to adjust for a changed w_topline
744 * 2. update lines at the top when scrolled down
745 * 3. redraw changed text:
746 * - if wp->w_buffer->b_mod_set set, update lines between
747 * b_mod_top and b_mod_bot.
748 * - if wp->w_redraw_top non-zero, redraw lines between
749 * wp->w_redraw_top and wp->w_redr_bot.
750 * - continue redrawing when syntax status is invalid.
751 * 4. if scrolled up, update lines at the bottom.
752 * This results in three areas that may need updating:
753 * top: from first row to top_end (when scrolled down)
754 * mid: from mid_start to mid_end (update inversion or changed text)
755 * bot: from bot_start to last row (when scrolled up)
761 buf_T
*buf
= wp
->w_buffer
;
763 int top_end
= 0; /* Below last row of the top area that needs
764 updating. 0 when no top area updating. */
765 int mid_start
= 999;/* first row of the mid area that needs
766 updating. 999 when no mid area updating. */
767 int mid_end
= 0; /* Below last row of the mid area that needs
768 updating. 0 when no mid area updating. */
769 int bot_start
= 999;/* first row of the bot area that needs
770 updating. 999 when no bot area updating */
772 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
773 w_topline got smaller a bit */
775 #ifdef FEAT_SEARCH_EXTRA
776 matchitem_T
*cur
; /* points to the match list */
777 int top_to_mod
= FALSE
; /* redraw above mod_top */
780 int row
; /* current window row to display */
781 linenr_T lnum
; /* current buffer lnum to display */
782 int idx
; /* current index in w_lines[] */
783 int srow
; /* starting row of the current line */
785 int eof
= FALSE
; /* if TRUE, we hit the end of the file */
786 int didline
= FALSE
; /* if TRUE, we finished the last line */
789 static int recursive
= FALSE
; /* being called recursively */
790 int old_botline
= wp
->w_botline
;
795 /* remember what happened to the previous line, to know if
796 * check_visual_highlight() can be used */
797 #define DID_NONE 1 /* didn't update a line */
798 #define DID_LINE 2 /* updated a normal line */
799 #define DID_FOLD 3 /* updated a folded line */
800 int did_update
= DID_NONE
;
801 linenr_T syntax_last_parsed
= 0; /* last parsed text line */
803 linenr_T mod_top
= 0;
804 linenr_T mod_bot
= 0;
805 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
809 type
= wp
->w_redr_type
;
811 if (type
== NOT_VALID
)
814 wp
->w_redr_status
= TRUE
;
816 wp
->w_lines_valid
= 0;
819 /* Window is zero-height: nothing to draw. */
820 if (wp
->w_height
== 0)
826 #ifdef FEAT_VERTSPLIT
827 /* Window is zero-width: Only need to draw the separator. */
828 if (wp
->w_width
== 0)
830 /* draw the vertical separator right of this window */
831 draw_vsep_win(wp
, 0);
837 #ifdef FEAT_SEARCH_EXTRA
838 /* Setup for match and 'hlsearch' highlighting. Disable any previous
840 cur
= wp
->w_match_head
;
843 cur
->hl
.rm
= cur
->match
;
844 if (cur
->hlg_id
== 0)
847 cur
->hl
.attr
= syn_id2attr(cur
->hlg_id
);
850 cur
->hl
.first_lnum
= 0;
855 search_hl
.first_lnum
= 0;
858 #ifdef FEAT_LINEBREAK
859 /* Force redraw when width of 'number' column changes. */
860 i
= wp
->w_p_nu
? number_width(wp
) : 0;
861 if (wp
->w_nrwidth
!= i
)
869 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
872 * When there are both inserted/deleted lines and specific lines to be
873 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
874 * everything (only happens when redrawing is off for while).
881 * Set mod_top to the first line that needs displaying because of
882 * changes. Set mod_bot to the first line after the changes.
884 mod_top
= wp
->w_redraw_top
;
885 if (wp
->w_redraw_bot
!= 0)
886 mod_bot
= wp
->w_redraw_bot
+ 1;
889 wp
->w_redraw_top
= 0; /* reset for next time */
890 wp
->w_redraw_bot
= 0;
893 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
895 mod_top
= buf
->b_mod_top
;
897 /* Need to redraw lines above the change that may be included
898 * in a pattern match. */
899 if (syntax_present(buf
))
901 mod_top
-= buf
->b_syn_sync_linebreaks
;
907 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
908 mod_bot
= buf
->b_mod_bot
;
910 #ifdef FEAT_SEARCH_EXTRA
911 /* When 'hlsearch' is on and using a multi-line search pattern, a
912 * change in one line may make the Search highlighting in a
913 * previous line invalid. Simple solution: redraw all visible
914 * lines above the change.
915 * Same for a match pattern.
917 if (search_hl
.rm
.regprog
!= NULL
918 && re_multiline(search_hl
.rm
.regprog
))
922 cur
= wp
->w_match_head
;
925 if (cur
->match
.regprog
!= NULL
926 && re_multiline(cur
->match
.regprog
))
937 if (mod_top
!= 0 && hasAnyFolding(wp
))
939 linenr_T lnumt
, lnumb
;
942 * A change in a line can cause lines above it to become folded or
943 * unfolded. Find the top most buffer line that may be affected.
944 * If the line was previously folded and displayed, get the first
945 * line of that fold. If the line is folded now, get the first
946 * folded line. Use the minimum of these two.
949 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
950 * the line below it. If there is no valid entry, use w_topline.
951 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
952 * to this line. If there is no valid entry, use MAXLNUM. */
953 lnumt
= wp
->w_topline
;
955 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
956 if (wp
->w_lines
[i
].wl_valid
)
958 if (wp
->w_lines
[i
].wl_lastlnum
< mod_top
)
959 lnumt
= wp
->w_lines
[i
].wl_lastlnum
+ 1;
960 if (lnumb
== MAXLNUM
&& wp
->w_lines
[i
].wl_lnum
>= mod_bot
)
962 lnumb
= wp
->w_lines
[i
].wl_lnum
;
963 /* When there is a fold column it might need updating
964 * in the next line ("J" just above an open fold). */
970 (void)hasFoldingWin(wp
, mod_top
, &mod_top
, NULL
, TRUE
, NULL
);
974 /* Now do the same for the bottom line (one above mod_bot). */
976 (void)hasFoldingWin(wp
, mod_bot
, NULL
, &mod_bot
, TRUE
, NULL
);
983 /* When a change starts above w_topline and the end is below
984 * w_topline, start redrawing at w_topline.
985 * If the end of the change is above w_topline: do like no change was
986 * made, but redraw the first line to find changes in syntax. */
987 if (mod_top
!= 0 && mod_top
< wp
->w_topline
)
989 if (mod_bot
> wp
->w_topline
)
990 mod_top
= wp
->w_topline
;
992 else if (syntax_present(buf
))
997 /* When line numbers are displayed need to redraw all lines below
998 * inserted/deleted lines. */
999 if (mod_top
!= 0 && buf
->b_mod_xlines
!= 0 && wp
->w_p_nu
)
1004 * When only displaying the lines at the top, set top_end. Used when
1005 * window has scrolled down for msg_scrolled.
1007 if (type
== REDRAW_TOP
)
1010 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
1012 j
+= wp
->w_lines
[i
].wl_size
;
1013 if (j
>= wp
->w_upd_rows
)
1020 /* not found (cannot happen?): redraw everything */
1023 /* top area defined, the rest is VALID */
1027 /* Trick: we want to avoid clearing the screen twice. screenclear() will
1028 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1029 * non-zero and thus not FALSE) will indicate that screenclear() was not
1032 screen_cleared
= MAYBE
;
1035 * If there are no changes on the screen that require a complete redraw,
1036 * handle three cases:
1037 * 1: we are off the top of the screen by a few lines: scroll down
1038 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1039 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1040 * w_lines[] that needs updating.
1042 if ((type
== VALID
|| type
== SOME_VALID
1043 || type
== INVERTED
|| type
== INVERTED_ALL
)
1045 && !wp
->w_botfill
&& !wp
->w_old_botfill
1049 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1052 * w_topline is the first changed line, the scrolling will be done
1056 else if (wp
->w_lines
[0].wl_valid
1057 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1059 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1060 && wp
->w_topfill
> wp
->w_old_topfill
)
1065 * New topline is above old topline: May scroll down.
1068 if (hasAnyFolding(wp
))
1072 /* count the number of lines we are off, counting a sequence
1073 * of folded lines as one */
1075 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1078 if (j
>= wp
->w_height
- 2)
1080 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1085 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1086 if (j
< wp
->w_height
- 2) /* not too far off */
1088 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1090 /* insert extra lines for previously invisible filler lines */
1091 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1092 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1093 - wp
->w_old_topfill
;
1095 if (i
< wp
->w_height
- 2) /* less than a screen off */
1098 * Try to insert the correct number of lines.
1099 * If not the last window, delete the lines at the bottom.
1100 * win_ins_lines may fail when the terminal can't do it.
1103 check_for_delay(FALSE
);
1104 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1106 if (wp
->w_lines_valid
!= 0)
1108 /* Need to update rows that are new, stop at the
1109 * first one that scrolled down. */
1112 scrolled_down
= TRUE
;
1115 /* Move the entries that were scrolled, disable
1116 * the entries for the lines to be redrawn. */
1117 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1118 wp
->w_lines_valid
= wp
->w_height
;
1119 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1120 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1122 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1126 mid_start
= 0; /* redraw all lines */
1129 mid_start
= 0; /* redraw all lines */
1132 mid_start
= 0; /* redraw all lines */
1137 * New topline is at or below old topline: May scroll up.
1138 * When topline didn't change, find first entry in w_lines[] that
1142 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1145 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1147 if (wp
->w_lines
[i
].wl_valid
1148 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1153 row
+= wp
->w_lines
[i
].wl_size
;
1157 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1164 * Try to delete the correct number of lines.
1165 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1168 /* If the topline didn't change, delete old filler lines,
1169 * otherwise delete filler lines of the new topline... */
1170 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1171 row
+= wp
->w_old_topfill
;
1173 row
+= diff_check_fill(wp
, wp
->w_topline
);
1174 /* ... but don't delete new filler lines. */
1175 row
-= wp
->w_topfill
;
1179 check_for_delay(FALSE
);
1180 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1181 bot_start
= wp
->w_height
- row
;
1183 mid_start
= 0; /* redraw all lines */
1185 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1188 * Skip the lines (below the deleted lines) that are still
1189 * valid and don't need redrawing. Copy their info
1190 * upwards, to compensate for the deleted lines. Set
1191 * bot_start to the first row that needs redrawing.
1197 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1198 /* stop at line that didn't fit, unless it is still
1199 * valid (no lines deleted) */
1200 if (row
> 0 && bot_start
+ row
1201 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1203 wp
->w_lines_valid
= idx
+ 1;
1206 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1208 /* stop at the last valid entry in w_lines[].wl_size */
1209 if (++j
>= wp
->w_lines_valid
)
1211 wp
->w_lines_valid
= idx
;
1216 /* Correct the first entry for filler lines at the top
1217 * when it won't get updated below. */
1218 if (wp
->w_p_diff
&& bot_start
> 0)
1219 wp
->w_lines
[0].wl_size
=
1220 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1227 /* When starting redraw in the first line, redraw all lines. When
1228 * there is only one window it's probably faster to clear the screen
1232 mid_end
= wp
->w_height
;
1233 if (lastwin
== firstwin
)
1235 /* Clear the screen when it was not done by win_del_lines() or
1236 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1238 if (screen_cleared
!= TRUE
)
1241 /* The screen was cleared, redraw the tab pages line. */
1248 /* When win_del_lines() or win_ins_lines() caused the screen to be
1249 * cleared (only happens for the first window) or when screenclear()
1250 * was called directly above, "must_redraw" will have been set to
1251 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1252 if (screen_cleared
== TRUE
)
1257 /* Not VALID or INVERTED: redraw all lines. */
1259 mid_end
= wp
->w_height
;
1262 if (type
== SOME_VALID
)
1264 /* SOME_VALID: redraw all lines. */
1266 mid_end
= wp
->w_height
;
1271 /* check if we are updating or removing the inverted part */
1272 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1273 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1280 && (VIsual_mode
!= wp
->w_old_visual_mode
1281 || type
== INVERTED_ALL
))
1284 * If the type of Visual selection changed, redraw the whole
1285 * selection. Also when the ownership of the X selection is
1288 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1290 from
= curwin
->w_cursor
.lnum
;
1296 to
= curwin
->w_cursor
.lnum
;
1298 /* redraw more when the cursor moved as well */
1299 if (wp
->w_old_cursor_lnum
< from
)
1300 from
= wp
->w_old_cursor_lnum
;
1301 if (wp
->w_old_cursor_lnum
> to
)
1302 to
= wp
->w_old_cursor_lnum
;
1303 if (wp
->w_old_visual_lnum
< from
)
1304 from
= wp
->w_old_visual_lnum
;
1305 if (wp
->w_old_visual_lnum
> to
)
1306 to
= wp
->w_old_visual_lnum
;
1311 * Find the line numbers that need to be updated: The lines
1312 * between the old cursor position and the current cursor
1313 * position. Also check if the Visual position changed.
1315 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1317 from
= curwin
->w_cursor
.lnum
;
1318 to
= wp
->w_old_cursor_lnum
;
1322 from
= wp
->w_old_cursor_lnum
;
1323 to
= curwin
->w_cursor
.lnum
;
1324 if (from
== 0) /* Visual mode just started */
1328 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1329 || VIsual
.col
!= wp
->w_old_visual_col
)
1331 if (wp
->w_old_visual_lnum
< from
1332 && wp
->w_old_visual_lnum
!= 0)
1333 from
= wp
->w_old_visual_lnum
;
1334 if (wp
->w_old_visual_lnum
> to
)
1335 to
= wp
->w_old_visual_lnum
;
1336 if (VIsual
.lnum
< from
)
1338 if (VIsual
.lnum
> to
)
1344 * If in block mode and changed column or curwin->w_curswant:
1346 * First compute the actual start and end column.
1348 if (VIsual_mode
== Ctrl_V
)
1352 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1354 if (curwin
->w_curswant
== MAXCOL
)
1357 if (fromc
!= wp
->w_old_cursor_fcol
1358 || toc
!= wp
->w_old_cursor_lcol
)
1360 if (from
> VIsual
.lnum
)
1362 if (to
< VIsual
.lnum
)
1365 wp
->w_old_cursor_fcol
= fromc
;
1366 wp
->w_old_cursor_lcol
= toc
;
1371 /* Use the line numbers of the old Visual area. */
1372 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1374 from
= wp
->w_old_cursor_lnum
;
1375 to
= wp
->w_old_visual_lnum
;
1379 from
= wp
->w_old_visual_lnum
;
1380 to
= wp
->w_old_cursor_lnum
;
1385 * There is no need to update lines above the top of the window.
1387 if (from
< wp
->w_topline
)
1388 from
= wp
->w_topline
;
1391 * If we know the value of w_botline, use it to restrict the update to
1392 * the lines that are visible in the window.
1394 if (wp
->w_valid
& VALID_BOTLINE
)
1396 if (from
>= wp
->w_botline
)
1397 from
= wp
->w_botline
- 1;
1398 if (to
>= wp
->w_botline
)
1399 to
= wp
->w_botline
- 1;
1403 * Find the minimal part to be updated.
1404 * Watch out for scrolling that made entries in w_lines[] invalid.
1405 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1406 * top_end; need to redraw from top_end to the "to" line.
1407 * A middle mouse click with a Visual selection may change the text
1408 * above the Visual area and reset wl_valid, do count these for
1409 * mid_end (in srow).
1413 lnum
= wp
->w_topline
;
1417 mid_start
= top_end
;
1420 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1422 if (wp
->w_lines
[idx
].wl_valid
)
1423 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1424 else if (!scrolled_down
)
1425 srow
+= wp
->w_lines
[idx
].wl_size
;
1427 # ifdef FEAT_FOLDING
1428 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1429 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1435 mid_end
= wp
->w_height
;
1436 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1438 if (wp
->w_lines
[idx
].wl_valid
1439 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1441 /* Only update until first row of this line */
1445 srow
+= wp
->w_lines
[idx
].wl_size
;
1450 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1452 wp
->w_old_visual_mode
= VIsual_mode
;
1453 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1454 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1455 wp
->w_old_visual_col
= VIsual
.col
;
1456 wp
->w_old_curswant
= curwin
->w_curswant
;
1460 wp
->w_old_visual_mode
= 0;
1461 wp
->w_old_cursor_lnum
= 0;
1462 wp
->w_old_visual_lnum
= 0;
1463 wp
->w_old_visual_col
= 0;
1465 #endif /* FEAT_VISUAL */
1467 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1468 /* reset got_int, otherwise regexp won't work */
1469 save_got_int
= got_int
;
1473 win_foldinfo
.fi_level
= 0;
1477 * Update all the window rows.
1479 idx
= 0; /* first entry in w_lines[].wl_size */
1482 lnum
= wp
->w_topline
; /* first line shown in window */
1485 /* stop updating when reached the end of the window (check for _past_
1486 * the end of the window is at the end of the loop) */
1487 if (row
== wp
->w_height
)
1493 /* stop updating when hit the end of the file */
1494 if (lnum
> buf
->b_ml
.ml_line_count
)
1500 /* Remember the starting row of the line that is going to be dealt
1501 * with. It is used further down when the line doesn't fit. */
1505 * Update a line when it is in an area that needs updating, when it
1506 * has changes or w_lines[idx] is invalid.
1507 * bot_start may be halfway a wrapped line after using
1508 * win_del_lines(), check if the current line includes it.
1509 * When syntax folding is being used, the saved syntax states will
1510 * already have been updated, we can't see where the syntax state is
1511 * the same again, just update until the end of the window.
1514 || (row
>= mid_start
&& row
< mid_end
)
1515 #ifdef FEAT_SEARCH_EXTRA
1518 || idx
>= wp
->w_lines_valid
1519 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1525 || did_update
== DID_FOLD
1526 || (did_update
== DID_LINE
1527 && syntax_present(buf
)
1529 # ifdef FEAT_FOLDING
1530 (foldmethodIsSyntax(wp
)
1531 && hasAnyFolding(wp
)) ||
1533 syntax_check_changed(lnum
)))
1537 #ifdef FEAT_SEARCH_EXTRA
1538 if (lnum
== mod_top
)
1543 * When at start of changed lines: May scroll following lines
1544 * up or down to minimize redrawing.
1545 * Don't do this when the change continues until the end.
1546 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1549 && mod_bot
!= MAXLNUM
1550 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1557 /* Count the old number of window rows, using w_lines[], which
1558 * should still contain the sizes for the lines as they are
1559 * currently displayed. */
1560 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1562 /* Only valid lines have a meaningful wl_lnum. Invalid
1563 * lines are part of the changed area. */
1564 if (wp
->w_lines
[i
].wl_valid
1565 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1567 old_rows
+= wp
->w_lines
[i
].wl_size
;
1569 if (wp
->w_lines
[i
].wl_valid
1570 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1572 /* Must have found the last valid entry above mod_bot.
1573 * Add following invalid entries. */
1575 while (i
< wp
->w_lines_valid
1576 && !wp
->w_lines
[i
].wl_valid
)
1577 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1583 if (i
>= wp
->w_lines_valid
)
1585 /* We can't find a valid line below the changed lines,
1586 * need to redraw until the end of the window.
1587 * Inserting/deleting lines has no use. */
1592 /* Able to count old number of rows: Count new window
1593 * rows, and may insert/delete lines */
1595 for (l
= lnum
; l
< mod_bot
; ++l
)
1598 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1603 if (l
== wp
->w_topline
)
1604 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1608 new_rows
+= plines_win(wp
, l
, TRUE
);
1610 if (new_rows
> wp
->w_height
- row
- 2)
1612 /* it's getting too much, must redraw the rest */
1617 xtra_rows
= new_rows
- old_rows
;
1620 /* May scroll text up. If there is not enough
1621 * remaining text or scrolling fails, must redraw the
1622 * rest. If scrolling works, must redraw the text
1623 * below the scrolled text. */
1624 if (row
- xtra_rows
>= wp
->w_height
- 2)
1628 check_for_delay(FALSE
);
1629 if (win_del_lines(wp
, row
,
1630 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1633 bot_start
= wp
->w_height
+ xtra_rows
;
1636 else if (xtra_rows
> 0)
1638 /* May scroll text down. If there is not enough
1639 * remaining text of scrolling fails, must redraw the
1641 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1645 check_for_delay(FALSE
);
1646 if (win_ins_lines(wp
, row
+ old_rows
,
1647 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1649 else if (top_end
> row
+ old_rows
)
1650 /* Scrolled the part at the top that requires
1652 top_end
+= xtra_rows
;
1656 /* When not updating the rest, may need to move w_lines[]
1658 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1662 int x
= row
+ new_rows
;
1664 /* move entries in w_lines[] upwards */
1667 /* stop at last valid entry in w_lines[] */
1668 if (i
>= wp
->w_lines_valid
)
1670 wp
->w_lines_valid
= j
;
1673 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1674 /* stop at a line that won't fit */
1675 if (x
+ (int)wp
->w_lines
[j
].wl_size
1678 wp
->w_lines_valid
= j
+ 1;
1681 x
+= wp
->w_lines
[j
++].wl_size
;
1689 /* move entries in w_lines[] downwards */
1691 wp
->w_lines_valid
+= j
;
1692 if (wp
->w_lines_valid
> wp
->w_height
)
1693 wp
->w_lines_valid
= wp
->w_height
;
1694 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1695 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1697 /* The w_lines[] entries for inserted lines are
1698 * now invalid, but wl_size may be used above.
1702 wp
->w_lines
[i
].wl_size
= 0;
1703 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1712 * When lines are folded, display one line for all of them.
1713 * Otherwise, display normally (can be several display lines when
1716 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1717 if (fold_count
!= 0)
1719 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1722 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1723 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1725 did_update
= DID_FOLD
;
1730 if (idx
< wp
->w_lines_valid
1731 && wp
->w_lines
[idx
].wl_valid
1732 && wp
->w_lines
[idx
].wl_lnum
== lnum
1733 && lnum
> wp
->w_topline
1734 && !(dy_flags
& DY_LASTLINE
)
1735 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1737 && diff_check_fill(wp
, lnum
) == 0
1741 /* This line is not going to fit. Don't draw anything here,
1742 * will draw "@ " lines below. */
1743 row
= wp
->w_height
+ 1;
1747 #ifdef FEAT_SEARCH_EXTRA
1748 prepare_search_hl(wp
, lnum
);
1751 /* Let the syntax stuff know we skipped a few lines. */
1752 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1753 && syntax_present(buf
))
1754 syntax_end_parsing(syntax_last_parsed
+ 1);
1760 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1763 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1764 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1767 did_update
= DID_LINE
;
1768 syntax_last_parsed
= lnum
;
1772 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1773 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1774 if (row
> wp
->w_height
) /* past end of screen */
1776 /* we may need the size of that too long line later on */
1777 if (dollar_vcol
== 0)
1778 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1782 if (dollar_vcol
== 0)
1783 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1786 lnum
+= fold_count
+ 1;
1793 /* This line does not need updating, advance to the next one */
1794 row
+= wp
->w_lines
[idx
++].wl_size
;
1795 if (row
> wp
->w_height
) /* past end of screen */
1798 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1803 did_update
= DID_NONE
;
1807 if (lnum
> buf
->b_ml
.ml_line_count
)
1814 * End of loop over all window lines.
1818 if (idx
> wp
->w_lines_valid
)
1819 wp
->w_lines_valid
= idx
;
1823 * Let the syntax stuff know we stop parsing here.
1825 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1826 syntax_end_parsing(syntax_last_parsed
+ 1);
1830 * If we didn't hit the end of the file, and we didn't finish the last
1831 * line we were working on, then the line didn't fit.
1833 wp
->w_empty_rows
= 0;
1835 wp
->w_filler_rows
= 0;
1837 if (!eof
&& !didline
)
1839 if (lnum
== wp
->w_topline
)
1842 * Single line that does not fit!
1843 * Don't overwrite it, it can be edited.
1845 wp
->w_botline
= lnum
+ 1;
1848 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1850 /* Window ends in filler lines. */
1851 wp
->w_botline
= lnum
;
1852 wp
->w_filler_rows
= wp
->w_height
- srow
;
1855 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1858 * Last line isn't finished: Display "@@@" at the end.
1860 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1861 W_WINROW(wp
) + wp
->w_height
,
1862 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1863 '@', '@', hl_attr(HLF_AT
));
1864 set_empty_rows(wp
, srow
);
1865 wp
->w_botline
= lnum
;
1869 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1870 wp
->w_botline
= lnum
;
1875 #ifdef FEAT_VERTSPLIT
1876 draw_vsep_win(wp
, row
);
1878 if (eof
) /* we hit the end of the file */
1880 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1882 j
= diff_check_fill(wp
, wp
->w_botline
);
1883 if (j
> 0 && !wp
->w_botfill
)
1886 * Display filler lines at the end of the file
1888 if (char2cells(fill_diff
) > 1)
1892 if (row
+ j
> wp
->w_height
)
1893 j
= wp
->w_height
- row
;
1894 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1899 else if (dollar_vcol
== 0)
1900 wp
->w_botline
= lnum
;
1902 /* make sure the rest of the screen is blank */
1903 /* put '~'s on rows that aren't part of the file. */
1904 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1907 /* Reset the type of redrawing required, the window has been updated. */
1908 wp
->w_redr_type
= 0;
1910 wp
->w_old_topfill
= wp
->w_topfill
;
1911 wp
->w_old_botfill
= wp
->w_botfill
;
1914 if (dollar_vcol
== 0)
1917 * There is a trick with w_botline. If we invalidate it on each
1918 * change that might modify it, this will cause a lot of expensive
1919 * calls to plines() in update_topline() each time. Therefore the
1920 * value of w_botline is often approximated, and this value is used to
1921 * compute the value of w_topline. If the value of w_botline was
1922 * wrong, check that the value of w_topline is correct (cursor is on
1923 * the visible part of the text). If it's not, we need to redraw
1924 * again. Mostly this just means scrolling up a few lines, so it
1925 * doesn't look too bad. Only do this for the current window (where
1926 * changes are relevant).
1928 wp
->w_valid
|= VALID_BOTLINE
;
1929 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1932 curwin
->w_valid
&= ~VALID_TOPLINE
;
1933 update_topline(); /* may invalidate w_botline again */
1934 if (must_redraw
!= 0)
1936 /* Don't update for changes in buffer again. */
1937 i
= curbuf
->b_mod_set
;
1938 curbuf
->b_mod_set
= FALSE
;
1941 curbuf
->b_mod_set
= i
;
1947 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1948 /* restore got_int, unless CTRL-C was hit while redrawing */
1950 got_int
= save_got_int
;
1955 static int draw_signcolumn
__ARGS((win_T
*wp
));
1958 * Return TRUE when window "wp" has a column to draw signs in.
1964 return (wp
->w_buffer
->b_signlist
!= NULL
1965 # ifdef FEAT_NETBEANS_INTG
1973 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1974 * as the filler character.
1977 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
1985 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
1992 #ifdef FEAT_RIGHTLEFT
1995 /* No check for cmdline window: should never be right-left. */
1996 # ifdef FEAT_FOLDING
2001 /* draw the fold column at the right */
2002 if (n
> W_WIDTH(wp
))
2004 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2005 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
2006 ' ', ' ', hl_attr(HLF_FC
));
2010 if (draw_signcolumn(wp
))
2014 /* draw the sign column left of the fold column */
2015 if (nn
> W_WIDTH(wp
))
2017 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2018 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2019 ' ', ' ', hl_attr(HLF_SC
));
2023 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2024 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2025 c2
, c2
, hl_attr(hl
));
2026 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2027 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2028 c1
, c2
, hl_attr(hl
));
2034 if (cmdwin_type
!= 0 && wp
== curwin
)
2036 /* draw the cmdline character in the leftmost column */
2038 if (n
> wp
->w_width
)
2040 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2041 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2042 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2046 if (wp
->w_p_fdc
> 0)
2048 int nn
= n
+ wp
->w_p_fdc
;
2050 /* draw the fold column at the left */
2051 if (nn
> W_WIDTH(wp
))
2053 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2054 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2055 ' ', ' ', hl_attr(HLF_FC
));
2060 if (draw_signcolumn(wp
))
2064 /* draw the sign column after the fold column */
2065 if (nn
> W_WIDTH(wp
))
2067 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2068 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2069 ' ', ' ', hl_attr(HLF_SC
));
2073 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2074 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2075 c1
, c2
, hl_attr(hl
));
2077 set_empty_rows(wp
, row
);
2082 * Display one folded line.
2085 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2088 foldinfo_T
*foldinfo
;
2094 linenr_T lnume
= lnum
+ fold_count
- 1;
2100 int off
= (int)(current_ScreenLine
- ScreenLines
);
2103 /* Build the fold line:
2104 * 1. Add the cmdwin_type for the command-line window
2105 * 2. Add the 'foldcolumn'
2106 * 3. Add the 'number' column
2107 * 4. Compose the text
2109 * 6. set highlighting for the Visual area an other text
2114 * 1. Add the cmdwin_type for the command-line window
2115 * Ignores 'rightleft', this window is never right-left.
2118 if (cmdwin_type
!= 0 && wp
== curwin
)
2120 ScreenLines
[off
] = cmdwin_type
;
2121 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2124 ScreenLinesUC
[off
] = 0;
2131 * 2. Add the 'foldcolumn'
2134 if (fdc
> W_WIDTH(wp
) - col
)
2135 fdc
= W_WIDTH(wp
) - col
;
2138 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2139 #ifdef FEAT_RIGHTLEFT
2144 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2146 /* reverse the fold column */
2147 for (i
= 0; i
< fdc
; ++i
)
2148 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2152 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2156 #ifdef FEAT_RIGHTLEFT
2157 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2158 for (ri = 0; ri < l; ++ri) \
2159 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2161 for (ri = 0; ri < l; ++ri) \
2162 ScreenAttrs[off + (p) + ri] = v
2164 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2165 ScreenAttrs[off + (p) + ri] = v
2168 /* Set all attributes of the 'number' column and the text */
2169 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2172 /* If signs are being displayed, add two spaces. */
2173 if (draw_signcolumn(wp
))
2175 len
= W_WIDTH(wp
) - col
;
2180 # ifdef FEAT_RIGHTLEFT
2182 /* the line number isn't reversed */
2183 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2184 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2187 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2194 * 3. Add the 'number' column
2198 len
= W_WIDTH(wp
) - col
;
2201 int w
= number_width(wp
);
2205 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2206 #ifdef FEAT_RIGHTLEFT
2208 /* the line number isn't reversed */
2209 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2213 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2219 * 4. Compose the folded-line string with 'foldtext', if set.
2221 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2223 txtcol
= col
; /* remember where text starts */
2226 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2227 * Right-left text is put in columns 0 - number-col, normal text is put
2228 * in columns number-col - window-width.
2234 int u8c
, u8cc
[MAX_MCO
];
2240 int prev_c
= 0; /* previous Arabic character */
2241 int prev_c1
= 0; /* first composing char for prev_c */
2244 # ifdef FEAT_RIGHTLEFT
2251 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2252 for (p
= text
; *p
!= NUL
; )
2254 cells
= (*mb_ptr2cells
)(p
);
2255 c_len
= (*mb_ptr2len
)(p
);
2256 if (col
+ cells
> W_WIDTH(wp
)
2257 # ifdef FEAT_RIGHTLEFT
2258 - (wp
->w_p_rl
? col
: 0)
2262 ScreenLines
[idx
] = *p
;
2265 u8c
= utfc_ptr2char(p
, u8cc
);
2266 if (*p
< 0x80 && u8cc
[0] == 0)
2268 ScreenLinesUC
[idx
] = 0;
2276 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2278 /* Do Arabic shaping. */
2283 /* The idea of what is the previous and next
2284 * character depends on 'rightleft'. */
2289 nc
= utf_ptr2char(p
+ c_len
);
2294 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2300 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2302 ScreenLines
[idx
] = firstbyte
;
2307 /* Non-BMP character: display as ? or fullwidth ?. */
2310 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2313 ScreenLinesUC
[idx
] = u8c
;
2314 for (i
= 0; i
< Screen_mco
; ++i
)
2316 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2322 ScreenLines
[idx
+ 1] = 0;
2324 else if (cells
> 1) /* double-byte character */
2326 if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2327 ScreenLines2
[idx
] = p
[1];
2329 ScreenLines
[idx
+ 1] = p
[1];
2339 len
= (int)STRLEN(text
);
2340 if (len
> W_WIDTH(wp
) - col
)
2341 len
= W_WIDTH(wp
) - col
;
2344 #ifdef FEAT_RIGHTLEFT
2346 STRNCPY(current_ScreenLine
, text
, len
);
2349 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2354 /* Fill the rest of the line with the fold filler */
2355 #ifdef FEAT_RIGHTLEFT
2359 while (col
< W_WIDTH(wp
)
2360 #ifdef FEAT_RIGHTLEFT
2361 - (wp
->w_p_rl
? txtcol
: 0)
2368 if (fill_fold
>= 0x80)
2370 ScreenLinesUC
[off
+ col
] = fill_fold
;
2371 ScreenLinesC
[0][off
+ col
] = 0;
2374 ScreenLinesUC
[off
+ col
] = 0;
2377 ScreenLines
[off
+ col
++] = fill_fold
;
2384 * 6. set highlighting for the Visual area an other text.
2385 * If all folded lines are in the Visual area, highlight the line.
2388 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2390 if (ltoreq(curwin
->w_cursor
, VIsual
))
2392 /* Visual is after curwin->w_cursor */
2393 top
= &curwin
->w_cursor
;
2398 /* Visual is before curwin->w_cursor */
2400 bot
= &curwin
->w_cursor
;
2402 if (lnum
>= top
->lnum
2403 && lnume
<= bot
->lnum
2404 && (VIsual_mode
!= 'v'
2405 || ((lnum
> top
->lnum
2406 || (lnum
== top
->lnum
2408 && (lnume
< bot
->lnum
2409 || (lnume
== bot
->lnum
2410 && (bot
->col
- (*p_sel
== 'e'))
2411 >= STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2413 if (VIsual_mode
== Ctrl_V
)
2415 /* Visual block mode: highlight the chars part of the block */
2416 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2418 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2419 len
= wp
->w_old_cursor_lcol
;
2421 len
= W_WIDTH(wp
) - txtcol
;
2422 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2423 len
- (int)wp
->w_old_cursor_fcol
);
2428 /* Set all attributes of the text */
2429 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2436 /* Show 'cursorcolumn' in the fold line. */
2437 if (wp
->w_p_cuc
&& (int)wp
->w_virtcol
+ txtcol
< W_WIDTH(wp
))
2438 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
] = hl_combine_attr(
2439 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
], hl_attr(HLF_CUC
));
2442 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2443 (int)W_WIDTH(wp
), FALSE
);
2446 * Update w_cline_height and w_cline_folded if the cursor line was
2447 * updated (saves a call to plines() later).
2450 && lnum
<= curwin
->w_cursor
.lnum
2451 && lnume
>= curwin
->w_cursor
.lnum
)
2453 curwin
->w_cline_row
= row
;
2454 curwin
->w_cline_height
= 1;
2455 curwin
->w_cline_folded
= TRUE
;
2456 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2461 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2464 copy_text_attr(off
, buf
, len
, attr
)
2472 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2475 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2477 for (i
= 0; i
< len
; ++i
)
2478 ScreenAttrs
[off
+ i
] = attr
;
2482 * Fill the foldcolumn at "p" for window "wp".
2483 * Only to be called when 'foldcolumn' > 0.
2486 fill_foldcolumn(p
, wp
, closed
, lnum
)
2489 int closed
; /* TRUE of FALSE */
2490 linenr_T lnum
; /* current line number */
2497 /* Init to all spaces. */
2498 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2500 level
= win_foldinfo
.fi_level
;
2503 /* If there is only one column put more info in it. */
2504 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2506 /* If the column is too narrow, we start at the lowest level that
2507 * fits and use numbers to indicated the depth. */
2508 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2509 if (first_level
< 1)
2512 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2514 if (win_foldinfo
.fi_lnum
== lnum
2515 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2517 else if (first_level
== 1)
2519 else if (first_level
+ i
<= 9)
2520 p
[i
] = '0' + first_level
+ i
;
2523 if (first_level
+ i
== level
)
2528 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2530 #endif /* FEAT_FOLDING */
2533 * Display line "lnum" of window 'wp' on the screen.
2534 * Start at row "startrow", stop when "endrow" is reached.
2535 * wp->w_virtcol needs to be valid.
2537 * Return the number of last row the line occupies.
2541 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2546 int nochange
; /* not updating for changed text */
2548 int col
; /* visual column on screen */
2549 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2550 int c
= 0; /* init for GCC */
2551 long vcol
= 0; /* virtual column (for tabs) */
2552 long vcol_prev
= -1; /* "vcol" of previous character */
2553 char_u
*line
; /* current line */
2554 char_u
*ptr
; /* current position in "line" */
2555 int row
; /* row in the window, excl w_winrow */
2556 int screen_row
; /* row on the screen, incl w_winrow */
2558 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2559 int n_extra
= 0; /* number of extra chars */
2560 char_u
*p_extra
= NULL
; /* string of extra chars, plus NUL */
2561 int c_extra
= NUL
; /* extra chars, all the same */
2562 int extra_attr
= 0; /* attributes when n_extra != 0 */
2563 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2564 displaying lcs_eol at end-of-line */
2565 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2566 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2568 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2569 int saved_n_extra
= 0;
2570 char_u
*saved_p_extra
= NULL
;
2571 int saved_c_extra
= 0;
2572 int saved_char_attr
= 0;
2574 int n_attr
= 0; /* chars with special attr */
2575 int saved_attr2
= 0; /* char_attr saved for n_attr */
2576 int n_attr3
= 0; /* chars with overruling special attr */
2577 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2579 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2581 int fromcol
, tocol
; /* start/end of inverting */
2582 int fromcol_prev
= -2; /* start of inverting after cursor */
2583 int noinvcur
= FALSE
; /* don't invert the cursor */
2590 int char_attr
= 0; /* attributes for next character */
2591 int attr_pri
= FALSE
; /* char_attr has priority */
2592 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2594 int attr
= 0; /* attributes for area highlighting */
2595 int area_attr
= 0; /* attributes desired by highlighting */
2596 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2598 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2599 int syntax_attr
= 0; /* attributes desired by syntax */
2600 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2602 int eol_hl_off
= 0; /* 1 if highlighted char after EOL */
2605 int has_spell
= FALSE
; /* this buffer has spell checking */
2606 # define SPWORDLEN 150
2607 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2608 int nextlinecol
= 0; /* column where nextline[] starts */
2609 int nextline_idx
= 0; /* index in nextline[] where next line
2611 int spell_attr
= 0; /* attributes desired by spelling */
2612 int word_end
= 0; /* last byte with same spell_attr */
2613 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2614 static int checked_col
= 0; /* column in "checked_lnum" up to which
2615 * there are no spell errors */
2616 static int cap_col
= -1; /* column to check for Cap word */
2617 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2618 int cur_checked_col
= 0; /* checked column for current line */
2620 int extra_check
; /* has syntax or linebreak */
2622 int multi_attr
= 0; /* attributes desired by multibyte */
2623 int mb_l
= 1; /* multi-byte byte length */
2624 int mb_c
= 0; /* decoded multi-byte character */
2625 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2626 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2629 int filler_lines
; /* nr of filler lines to be drawn */
2630 int filler_todo
; /* nr of filler lines still to do + 1 */
2631 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2632 int change_start
= MAXCOL
; /* first col of changed area */
2633 int change_end
= -1; /* last col of changed area */
2635 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2636 #ifdef FEAT_LINEBREAK
2637 int need_showbreak
= FALSE
;
2639 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2640 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2642 int line_attr
= 0; /* atrribute for the whole line */
2644 #ifdef FEAT_SEARCH_EXTRA
2645 matchitem_T
*cur
; /* points to the match list */
2646 match_T
*shl
; /* points to search_hl or a match */
2647 int shl_flag
; /* flag to indicate whether search_hl
2648 has been processed or not */
2649 int prevcol_hl_flag
; /* flag to indicate whether prevcol
2650 equals startcol of search_hl or one
2654 int prev_c
= 0; /* previous Arabic character */
2655 int prev_c1
= 0; /* first composing char for prev_c */
2657 #if defined(LINE_ATTR)
2658 int did_line_attr
= 0;
2661 /* draw_state: items that are drawn in sequence: */
2662 #define WL_START 0 /* nothing done yet */
2664 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2666 # define WL_CMDLINE WL_START
2669 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2671 # define WL_FOLD WL_CMDLINE
2674 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2676 # define WL_SIGN WL_FOLD /* column for signs */
2678 #define WL_NR WL_SIGN + 1 /* line number */
2679 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2680 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2682 # define WL_SBR WL_NR
2684 #define WL_LINE WL_SBR + 1 /* text in the line */
2685 int draw_state
= WL_START
; /* what to draw next */
2686 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2687 int feedback_col
= 0;
2688 int feedback_old_attr
= -1;
2692 if (startrow
> endrow
) /* past the end already! */
2696 screen_row
= row
+ W_WINROW(wp
);
2699 * To speed up the loop below, set extra_check when there is linebreak,
2700 * trailing white space and/or syntax processing to be done.
2702 #ifdef FEAT_LINEBREAK
2703 extra_check
= wp
->w_p_lbr
;
2708 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2710 /* Prepare for syntax highlighting in this line. When there is an
2711 * error, stop syntax highlighting. */
2712 save_did_emsg
= did_emsg
;
2714 syntax_start(wp
, lnum
);
2716 wp
->w_buffer
->b_syn_error
= TRUE
;
2719 did_emsg
= save_did_emsg
;
2728 && *wp
->w_buffer
->b_p_spl
!= NUL
2729 && wp
->w_buffer
->b_langp
.ga_len
> 0
2730 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2732 /* Prepare for spell checking. */
2736 /* Get the start of the next line, so that words that wrap to the next
2737 * line are found too: "et<line-break>al.".
2738 * Trick: skip a few chars for C/shell/Vim comments */
2739 nextline
[SPWORDLEN
] = NUL
;
2740 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2742 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2743 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2746 /* When a word wrapped from the previous line the start of the current
2748 if (lnum
== checked_lnum
)
2749 cur_checked_col
= checked_col
;
2752 /* When there was a sentence end in the previous line may require a
2753 * word starting with capital in this line. In line 1 always check
2754 * the first word. */
2755 if (lnum
!= capcol_lnum
)
2764 * handle visual active in this window
2769 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2771 /* Visual is after curwin->w_cursor */
2772 if (ltoreq(curwin
->w_cursor
, VIsual
))
2774 top
= &curwin
->w_cursor
;
2777 else /* Visual is before curwin->w_cursor */
2780 bot
= &curwin
->w_cursor
;
2782 if (VIsual_mode
== Ctrl_V
) /* block mode */
2784 if (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
)
2786 fromcol
= wp
->w_old_cursor_fcol
;
2787 tocol
= wp
->w_old_cursor_lcol
;
2790 else /* non-block mode */
2792 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2794 else if (lnum
== top
->lnum
)
2796 if (VIsual_mode
== 'V') /* linewise */
2800 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2801 if (gchar_pos(top
) == NUL
)
2802 tocol
= fromcol
+ 1;
2805 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2807 if (*p_sel
== 'e' && bot
->col
== 0
2808 #ifdef FEAT_VIRTUALEDIT
2816 else if (bot
->col
== MAXCOL
)
2822 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2825 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2833 /* Check if the character under the cursor should not be inverted */
2834 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2842 /* if inverting in this line set area_highlighting */
2845 area_highlighting
= TRUE
;
2846 attr
= hl_attr(HLF_V
);
2847 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2848 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2849 attr
= hl_attr(HLF_VNC
);
2855 * handle 'incsearch' and ":s///c" highlighting
2858 #endif /* FEAT_VISUAL */
2861 && lnum
>= curwin
->w_cursor
.lnum
2862 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2864 if (lnum
== curwin
->w_cursor
.lnum
)
2865 getvcol(curwin
, &(curwin
->w_cursor
),
2866 (colnr_T
*)&fromcol
, NULL
, NULL
);
2869 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2872 pos
.col
= search_match_endcol
;
2873 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2877 if (fromcol
== tocol
) /* do at least one character */
2878 tocol
= fromcol
+ 1; /* happens when past end of line */
2879 area_highlighting
= TRUE
;
2880 attr
= hl_attr(HLF_I
);
2884 filler_lines
= diff_check(wp
, lnum
);
2885 if (filler_lines
< 0)
2887 if (filler_lines
== -1)
2889 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2890 diff_hlf
= HLF_ADD
; /* added line */
2891 else if (change_start
== 0)
2892 diff_hlf
= HLF_TXD
; /* changed text */
2894 diff_hlf
= HLF_CHD
; /* changed line */
2897 diff_hlf
= HLF_ADD
; /* added line */
2899 area_highlighting
= TRUE
;
2901 if (lnum
== wp
->w_topline
)
2902 filler_lines
= wp
->w_topfill
;
2903 filler_todo
= filler_lines
;
2908 /* If this line has a sign with line highlighting set line_attr. */
2909 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2911 line_attr
= sign_get_attr((int)v
, TRUE
);
2913 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2914 /* Highlight the current line in the quickfix window. */
2915 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2916 line_attr
= hl_attr(HLF_L
);
2919 area_highlighting
= TRUE
;
2922 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2928 /* For checking first word with a capital skip white space. */
2930 cap_col
= (int)(skipwhite(line
) - line
);
2932 /* To be able to spell-check over line boundaries copy the end of the
2933 * current line into nextline[]. Above the start of the next line was
2934 * copied to nextline[SPWORDLEN]. */
2935 if (nextline
[SPWORDLEN
] == NUL
)
2937 /* No next line or it is empty. */
2938 nextlinecol
= MAXCOL
;
2943 v
= (long)STRLEN(line
);
2946 /* Short line, use it completely and append the start of the
2949 mch_memmove(nextline
, line
, (size_t)v
);
2950 mch_memmove(nextline
+ v
, nextline
+ SPWORDLEN
,
2951 STRLEN(nextline
+ SPWORDLEN
) + 1);
2952 nextline_idx
= v
+ 1;
2956 /* Long line, use only the last SPWORDLEN bytes. */
2957 nextlinecol
= v
- SPWORDLEN
;
2958 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2959 nextline_idx
= SPWORDLEN
+ 1;
2965 /* find start of trailing whitespace */
2966 if (wp
->w_p_list
&& lcs_trail
)
2968 trailcol
= (colnr_T
)STRLEN(ptr
);
2969 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
2971 trailcol
+= (colnr_T
) (ptr
- line
);
2976 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
2977 * first character to be displayed.
2986 char_u
*prev_ptr
= ptr
;
2988 while (vcol
< v
&& *ptr
!= NUL
)
2990 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
2998 #ifdef FEAT_VIRTUALEDIT
2999 /* When 'virtualedit' is set the end of the line may be before the
3000 * start of the displayed part. */
3001 if (vcol
< v
&& *ptr
== NUL
&& virtual_active())
3005 /* Handle a character that's not completely on the screen: Put ptr at
3006 * that character but skip the first few screen characters. */
3019 * Adjust for when the inverted text is before the screen,
3020 * and when the start of the inverted text is before the screen.
3024 else if (fromcol
>= 0 && fromcol
< vcol
)
3027 #ifdef FEAT_LINEBREAK
3028 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3030 need_showbreak
= TRUE
;
3033 /* When spell checking a word we need to figure out the start of the
3034 * word and if it's badly spelled or not. */
3038 hlf_T spell_hlf
= HLF_COUNT
;
3041 wp
->w_cursor
.lnum
= lnum
;
3042 wp
->w_cursor
.col
= (colnr_T
)(ptr
- line
);
3043 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3044 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3046 /* no bad word found at line start, don't check until end of a
3048 spell_hlf
= HLF_COUNT
;
3049 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
) - line
+ 1);
3053 /* bad word found, use attributes until end of word */
3054 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3056 /* Turn index into actual attributes. */
3057 if (spell_hlf
!= HLF_COUNT
)
3058 spell_attr
= highlight_attr
[spell_hlf
];
3063 /* Need to restart syntax highlighting for this line. */
3065 syntax_start(wp
, lnum
);
3072 * Correct highlighting for cursor that can't be disabled.
3073 * Avoids having to check this for each character.
3079 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3081 /* highlighting starts at cursor, let it start just after the
3083 fromcol_prev
= fromcol
;
3086 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3087 /* restart highlighting after the cursor */
3088 fromcol_prev
= wp
->w_virtcol
;
3090 if (fromcol
>= tocol
)
3094 #ifdef FEAT_SEARCH_EXTRA
3096 * Handle highlighting the last used search pattern and matches.
3097 * Do this for both search_hl and the match list.
3099 cur
= wp
->w_match_head
;
3101 while (cur
!= NULL
|| shl_flag
== FALSE
)
3103 if (shl_flag
== FALSE
)
3110 shl
->startcol
= MAXCOL
;
3111 shl
->endcol
= MAXCOL
;
3113 if (shl
->rm
.regprog
!= NULL
)
3115 v
= (long)(ptr
- line
);
3116 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3118 /* Need to get the line again, a multi-line regexp may have made it
3120 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3123 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3125 if (shl
->lnum
== lnum
)
3126 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3129 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3130 - shl
->rm
.startpos
[0].lnum
)
3131 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3133 shl
->endcol
= MAXCOL
;
3134 /* Highlight one character for an empty match. */
3135 if (shl
->startcol
== shl
->endcol
)
3138 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3139 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3144 if ((long)shl
->startcol
< v
) /* match at leftcol */
3146 shl
->attr_cur
= shl
->attr
;
3147 search_attr
= shl
->attr
;
3149 area_highlighting
= TRUE
;
3152 if (shl
!= &search_hl
&& cur
!= NULL
)
3158 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3159 * active, because it's not clear what is selected then. */
3160 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3162 line_attr
= hl_attr(HLF_CUL
);
3163 area_highlighting
= TRUE
;
3167 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3169 #ifdef FEAT_RIGHTLEFT
3172 /* Rightleft window: process the text in the normal direction, but put
3173 * it in current_ScreenLine[] from right to left. Start at the
3174 * rightmost column of the window. */
3175 col
= W_WIDTH(wp
) - 1;
3181 * Repeat for the whole displayed line.
3185 /* Skip this quickly when working on the text. */
3186 if (draw_state
!= WL_LINE
)
3189 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3191 draw_state
= WL_CMDLINE
;
3192 if (cmdwin_type
!= 0 && wp
== curwin
)
3194 /* Draw the cmdline character. */
3196 c_extra
= cmdwin_type
;
3197 char_attr
= hl_attr(HLF_AT
);
3203 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3205 draw_state
= WL_FOLD
;
3206 if (wp
->w_p_fdc
> 0)
3208 /* Draw the 'foldcolumn'. */
3209 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3210 n_extra
= wp
->w_p_fdc
;
3212 p_extra
[n_extra
] = NUL
;
3214 char_attr
= hl_attr(HLF_FC
);
3220 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3222 draw_state
= WL_SIGN
;
3223 /* Show the sign column when there are any signs in this
3224 * buffer or when using Netbeans. */
3225 if (draw_signcolumn(wp
)
3232 # ifdef FEAT_SIGN_ICONS
3236 /* Draw two cells with the sign value or blank. */
3238 char_attr
= hl_attr(HLF_SC
);
3241 if (row
== startrow
)
3243 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3245 # ifdef FEAT_SIGN_ICONS
3246 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3248 if (gui
.in_use
&& icon_sign
!= 0)
3250 /* Use the image in this position. */
3251 c_extra
= SIGN_BYTE
;
3252 # ifdef FEAT_NETBEANS_INTG
3253 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3254 c_extra
= MULTISIGN_BYTE
;
3256 char_attr
= icon_sign
;
3262 p_extra
= sign_get_text(text_sign
);
3263 if (p_extra
!= NULL
)
3266 n_extra
= (int)STRLEN(p_extra
);
3268 char_attr
= sign_get_attr(text_sign
, FALSE
);
3275 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3278 /* Display the line number. After the first fill with blanks
3279 * when the 'n' flag isn't in 'cpo' */
3285 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3287 /* Draw the line number (empty space after wrapping). */
3294 sprintf((char *)extra
, "%*ld ",
3295 number_width(wp
), (long)lnum
);
3296 if (wp
->w_skipcol
> 0)
3297 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3299 #ifdef FEAT_RIGHTLEFT
3300 if (wp
->w_p_rl
) /* reverse line numbers */
3308 n_extra
= number_width(wp
) + 1;
3309 char_attr
= hl_attr(HLF_N
);
3311 /* When 'cursorline' is set highlight the line number of
3312 * the current line differently. */
3313 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3314 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3319 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3320 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3322 draw_state
= WL_SBR
;
3324 if (filler_todo
> 0)
3326 /* Draw "deleted" diff line(s). */
3327 if (char2cells(fill_diff
) > 1)
3330 c_extra
= fill_diff
;
3331 # ifdef FEAT_RIGHTLEFT
3336 n_extra
= W_WIDTH(wp
) - col
;
3337 char_attr
= hl_attr(HLF_DED
);
3340 # ifdef FEAT_LINEBREAK
3341 if (*p_sbr
!= NUL
&& need_showbreak
)
3343 /* Draw 'showbreak' at the start of each broken line. */
3346 n_extra
= (int)STRLEN(p_sbr
);
3347 char_attr
= hl_attr(HLF_AT
);
3348 need_showbreak
= FALSE
;
3349 /* Correct end of highlighted area for 'showbreak',
3350 * required when 'linebreak' is also set. */
3358 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3360 draw_state
= WL_LINE
;
3363 /* Continue item from end of wrapped line. */
3364 n_extra
= saved_n_extra
;
3365 c_extra
= saved_c_extra
;
3366 p_extra
= saved_p_extra
;
3367 char_attr
= saved_char_attr
;
3374 /* When still displaying '$' of change command, stop at cursor */
3375 if (dollar_vcol
!= 0 && wp
== curwin
3376 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3382 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3384 /* Pretend we have finished updating the window. Except when
3385 * 'cursorcolumn' is set. */
3388 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3395 if (draw_state
== WL_LINE
&& area_highlighting
)
3397 /* handle Visual or match highlighting in this line */
3400 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3401 && (*mb_ptr2cells
)(ptr
) > 1)
3403 || ((int)vcol_prev
== fromcol_prev
3405 area_attr
= attr
; /* start highlighting */
3406 else if (area_attr
!= 0
3408 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3409 area_attr
= 0; /* stop highlighting */
3411 #ifdef FEAT_SEARCH_EXTRA
3415 * Check for start/end of search pattern match.
3416 * After end, check for start/end of next match.
3417 * When another match, have to check for start again.
3418 * Watch out for matching an empty string!
3419 * Do this for 'search_hl' and the match list (ordered by
3422 v
= (long)(ptr
- line
);
3423 cur
= wp
->w_match_head
;
3425 while (cur
!= NULL
|| shl_flag
== FALSE
)
3427 if (shl_flag
== FALSE
3429 && cur
->priority
> SEARCH_HL_PRIORITY
)
3437 while (shl
->rm
.regprog
!= NULL
)
3439 if (shl
->startcol
!= MAXCOL
3440 && v
>= (long)shl
->startcol
3441 && v
< (long)shl
->endcol
)
3443 shl
->attr_cur
= shl
->attr
;
3445 else if (v
== (long)shl
->endcol
)
3449 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3451 /* Need to get the line again, a multi-line regexp
3452 * may have made it invalid. */
3453 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3456 if (shl
->lnum
== lnum
)
3458 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3459 if (shl
->rm
.endpos
[0].lnum
== 0)
3460 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3462 shl
->endcol
= MAXCOL
;
3464 if (shl
->startcol
== shl
->endcol
)
3466 /* highlight empty match, try again after
3470 shl
->endcol
+= (*mb_ptr2len
)(line
3477 /* Loop to check if the match starts at the
3478 * current position */
3484 if (shl
!= &search_hl
&& cur
!= NULL
)
3488 /* Use attributes from match with highest priority among
3489 * 'search_hl' and the match list. */
3490 search_attr
= search_hl
.attr_cur
;
3491 cur
= wp
->w_match_head
;
3493 while (cur
!= NULL
|| shl_flag
== FALSE
)
3495 if (shl_flag
== FALSE
3497 && cur
->priority
> SEARCH_HL_PRIORITY
)
3505 if (shl
->attr_cur
!= 0)
3506 search_attr
= shl
->attr_cur
;
3507 if (shl
!= &search_hl
&& cur
!= NULL
)
3514 if (diff_hlf
!= (hlf_T
)0)
3516 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
3518 diff_hlf
= HLF_TXD
; /* changed text */
3519 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
3521 diff_hlf
= HLF_CHD
; /* changed line */
3522 line_attr
= hl_attr(diff_hlf
);
3526 /* Decide which of the highlight attributes to use. */
3529 char_attr
= area_attr
;
3530 else if (search_attr
!= 0)
3531 char_attr
= search_attr
;
3533 /* Use line_attr when not in the Visual or 'incsearch' area
3534 * (area_attr may be 0 when "noinvcur" is set). */
3535 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3536 || (vcol
< fromcol
|| vcol
>= tocol
)))
3537 char_attr
= line_attr
;
3544 char_attr
= syntax_attr
;
3552 * Get the next character to put on the screen.
3555 * The "p_extra" points to the extra stuff that is inserted to
3556 * represent special characters (non-printable stuff) and other
3557 * things. When all characters are the same, c_extra is used.
3558 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3559 * "p_extra[n_extra]".
3560 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3568 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3569 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3588 /* If the UTF-8 character is more than one byte:
3589 * Decode it into "mb_c". */
3590 mb_l
= (*mb_ptr2len
)(p_extra
);
3596 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3603 /* if this is a DBCS character, put it in "mb_c" */
3604 mb_l
= MB_BYTE2LEN(c
);
3605 if (mb_l
>= n_extra
)
3608 mb_c
= (c
<< 8) + p_extra
[1];
3610 if (mb_l
== 0) /* at the NUL at end-of-line */
3613 /* If a double-width char doesn't fit display a '>' in the
3616 # ifdef FEAT_RIGHTLEFT
3617 wp
->w_p_rl
? (col
<= 0) :
3619 (col
>= W_WIDTH(wp
) - 1))
3620 && (*mb_char2cells
)(mb_c
) == 2)
3626 multi_attr
= hl_attr(HLF_AT
);
3627 /* put the pointer back to output the double-width
3628 * character at the start of the next line. */
3634 n_extra
-= mb_l
- 1;
3635 p_extra
+= mb_l
- 1;
3646 * Get a character from the line itself.
3655 /* If the UTF-8 character is more than one byte: Decode it
3657 mb_l
= (*mb_ptr2len
)(ptr
);
3661 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3662 /* Overlong encoded ASCII or ASCII with composing char
3663 * is displayed normally, except a NUL. */
3668 /* At start of the line we can have a composing char.
3669 * Draw it as a space with a composing char. */
3670 if (utf_iscomposing(mb_c
))
3674 for (i
= Screen_mco
- 1; i
> 0; --i
)
3675 u8cc
[i
] = u8cc
[i
- 1];
3681 if ((mb_l
== 1 && c
>= 0x80)
3682 || (mb_l
>= 1 && mb_c
== 0)
3683 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3690 * Illegal UTF-8 byte: display as <xx>.
3691 * Non-BMP character : display as ? or fullwidth ?.
3697 transchar_hex(extra
, mb_c
);
3698 # ifdef FEAT_RIGHTLEFT
3699 if (wp
->w_p_rl
) /* reverse */
3704 else if (utf_char2cells(mb_c
) != 2)
3707 /* 0xff1f in UTF-8: full-width '?' */
3708 STRCPY(extra
, "\357\274\237");
3713 mb_c
= mb_ptr2char_adv(&p_extra
);
3714 mb_utf8
= (c
>= 0x80);
3715 n_extra
= (int)STRLEN(p_extra
);
3717 if (area_attr
== 0 && search_attr
== 0)
3719 n_attr
= n_extra
+ 1;
3720 extra_attr
= hl_attr(HLF_8
);
3721 saved_attr2
= char_attr
; /* save current attr */
3724 else if (mb_l
== 0) /* at the NUL at end-of-line */
3727 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3729 /* Do Arabic shaping. */
3733 /* The idea of what is the previous and next
3734 * character depends on 'rightleft'. */
3739 nc
= utf_ptr2char(ptr
+ mb_l
);
3744 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3750 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3758 mb_l
= MB_BYTE2LEN(c
);
3759 if (mb_l
== 0) /* at the NUL at end-of-line */
3763 /* We assume a second byte below 32 is illegal.
3764 * Hopefully this is OK for all double-byte encodings!
3767 mb_c
= (c
<< 8) + ptr
[1];
3772 /* head byte at end of line */
3774 transchar_nonprint(extra
, c
);
3778 /* illegal tail byte */
3780 STRCPY(extra
, "XX");
3783 n_extra
= (int)STRLEN(extra
) - 1;
3786 if (area_attr
== 0 && search_attr
== 0)
3788 n_attr
= n_extra
+ 1;
3789 extra_attr
= hl_attr(HLF_8
);
3790 saved_attr2
= char_attr
; /* save current attr */
3796 /* If a double-width char doesn't fit display a '>' in the
3797 * last column; the character is displayed at the start of the
3800 # ifdef FEAT_RIGHTLEFT
3801 wp
->w_p_rl
? (col
<= 0) :
3803 (col
>= W_WIDTH(wp
) - 1))
3804 && (*mb_char2cells
)(mb_c
) == 2)
3810 multi_attr
= hl_attr(HLF_AT
);
3811 /* Put pointer back so that the character will be
3812 * displayed at the start of the next line. */
3815 else if (*ptr
!= NUL
)
3818 /* If a double-width char doesn't fit at the left side display
3819 * a '<' in the first column. */
3820 if (n_skip
> 0 && mb_l
> 1)
3825 if (area_attr
== 0 && search_attr
== 0)
3827 n_attr
= n_extra
+ 1;
3828 extra_attr
= hl_attr(HLF_AT
);
3829 saved_attr2
= char_attr
; /* save current attr */
3840 /* 'list' : change char 160 to lcs_nbsp. */
3841 if (wp
->w_p_list
&& (c
== 160
3843 || (mb_utf8
&& mb_c
== 160)
3848 if (area_attr
== 0 && search_attr
== 0)
3851 extra_attr
= hl_attr(HLF_8
);
3852 saved_attr2
= char_attr
; /* save current attr */
3856 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3870 int can_spell
= TRUE
;
3874 /* Get syntax attribute, unless still at the start of the line
3875 * (double-wide char that doesn't fit). */
3876 v
= (long)(ptr
- line
);
3877 if (has_syntax
&& v
> 0)
3879 /* Get the syntax attribute for the character. If there
3880 * is an error, disable syntax highlighting. */
3881 save_did_emsg
= did_emsg
;
3884 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3886 has_spell
? &can_spell
:
3892 wp
->w_buffer
->b_syn_error
= TRUE
;
3896 did_emsg
= save_did_emsg
;
3898 /* Need to get the line again, a multi-line regexp may
3899 * have made it invalid. */
3900 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3904 char_attr
= syntax_attr
;
3906 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3911 /* Check spelling (unless at the end of the line).
3912 * Only do this when there is no syntax highlighting, the
3913 * @Spell cluster is not used or the current syntax item
3914 * contains the @Spell cluster. */
3915 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3920 char_attr
= syntax_attr
;
3928 char_u
*prev_ptr
, *p
;
3930 hlf_T spell_hlf
= HLF_COUNT
;
3934 prev_ptr
= ptr
- mb_l
;
3941 /* Use nextline[] if possible, it has the start of the
3942 * next line concatenated. */
3943 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3944 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
3947 cap_col
-= (int)(prev_ptr
- line
);
3948 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
3952 /* In Insert mode only highlight a word that
3953 * doesn't touch the cursor. */
3954 if (spell_hlf
!= HLF_COUNT
3955 && (State
& INSERT
) != 0
3956 && wp
->w_cursor
.lnum
== lnum
3957 && wp
->w_cursor
.col
>=
3958 (colnr_T
)(prev_ptr
- line
)
3959 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
3961 spell_hlf
= HLF_COUNT
;
3962 spell_redraw_lnum
= lnum
;
3965 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
3966 && (p
- nextline
) + len
> nextline_idx
)
3968 /* Remember that the good word continues at the
3969 * start of the next line. */
3970 checked_lnum
= lnum
+ 1;
3971 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
3974 /* Turn index into actual attributes. */
3975 if (spell_hlf
!= HLF_COUNT
)
3976 spell_attr
= highlight_attr
[spell_hlf
];
3981 && (p
- nextline
) + cap_col
>= nextline_idx
)
3983 /* Remember that the word in the next line
3984 * must start with a capital. */
3985 capcol_lnum
= lnum
+ 1;
3986 cap_col
= (int)((p
- nextline
) + cap_col
3990 /* Compute the actual column. */
3991 cap_col
+= (int)(prev_ptr
- line
);
3995 if (spell_attr
!= 0)
3998 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
4000 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
4003 #ifdef FEAT_LINEBREAK
4005 * Found last space before word: check for line break.
4007 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
4010 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
4014 1), (colnr_T
)vcol
, NULL
) - 1;
4021 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
4027 extra_attr
= hl_attr(HLF_8
);
4028 saved_attr2
= char_attr
; /* save current attr */
4032 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4045 * Handling of non-printable characters.
4047 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
4050 * when getting a character from the file, we may have to
4051 * turn it into something else on the way to putting it
4052 * into "ScreenLines".
4054 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
4056 /* tab amount depends on current column */
4057 n_extra
= (int)wp
->w_buffer
->b_p_ts
4058 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
4060 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4066 n_attr
= n_extra
+ 1;
4067 extra_attr
= hl_attr(HLF_8
);
4068 saved_attr2
= char_attr
; /* save current attr */
4071 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4086 && ((wp
->w_p_list
&& lcs_eol
> 0)
4087 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4090 && VIsual_mode
!= Ctrl_V
4093 # ifdef FEAT_RIGHTLEFT
4094 wp
->w_p_rl
? (col
>= 0) :
4096 (col
< W_WIDTH(wp
)))
4098 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4099 && lcs_eol_one
>= 0)
4101 /* Display a '$' after the line or highlight an extra
4102 * character if the line break is included. */
4103 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4104 /* For a diff line the highlighting continues after the
4108 diff_hlf
== (hlf_T
)0
4119 #ifdef FEAT_VIRTUALEDIT
4120 /* In virtualedit, visual selections may extend
4121 * beyond end of line. */
4122 if (area_highlighting
&& virtual_active()
4123 && tocol
!= MAXCOL
&& vcol
< tocol
)
4128 p_extra
= at_end_str
;
4138 --ptr
; /* put it back at the NUL */
4141 extra_attr
= hl_attr(HLF_AT
);
4146 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4153 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4158 p_extra
= transchar(c
);
4159 #ifdef FEAT_RIGHTLEFT
4160 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4161 rl_mirror(p_extra
); /* reverse "<12>" */
4163 n_extra
= byte2cells(c
) - 1;
4168 n_attr
= n_extra
+ 1;
4169 extra_attr
= hl_attr(HLF_8
);
4170 saved_attr2
= char_attr
; /* save current attr */
4173 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4176 #ifdef FEAT_VIRTUALEDIT
4177 else if (VIsual_active
4178 && (VIsual_mode
== Ctrl_V
4179 || VIsual_mode
== 'v')
4184 # ifdef FEAT_RIGHTLEFT
4185 wp
->w_p_rl
? (col
>= 0) :
4187 (col
< W_WIDTH(wp
))))
4190 --ptr
; /* put it back at the NUL */
4193 #if defined(LINE_ATTR)
4196 diff_hlf
!= (hlf_T
)0 ||
4200 # ifdef FEAT_RIGHTLEFT
4201 wp
->w_p_rl
? (col
>= 0) :
4203 (col
< W_WIDTH(wp
))))
4205 /* Highlight until the right side of the window */
4207 --ptr
; /* put it back at the NUL */
4209 /* Remember we do the char for line highlighting. */
4212 /* don't do search HL for the rest of the line */
4213 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4214 char_attr
= line_attr
;
4216 if (diff_hlf
== HLF_TXD
)
4219 if (attr
== 0 || char_attr
!= attr
)
4220 char_attr
= hl_attr(diff_hlf
);
4228 /* Don't override visual selection highlighting. */
4230 && draw_state
== WL_LINE
4232 char_attr
= extra_attr
;
4234 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4235 /* XIM don't send preedit_start and preedit_end, but they send
4236 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4237 * im_is_preediting() here. */
4239 && lnum
== curwin
->w_cursor
.lnum
4242 && im_is_preediting()
4243 && draw_state
== WL_LINE
)
4247 if (preedit_end_col
== MAXCOL
)
4248 getvcol(curwin
, &(curwin
->w_cursor
), &tcol
, NULL
, NULL
);
4250 tcol
= preedit_end_col
;
4251 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4253 if (feedback_old_attr
< 0)
4256 feedback_old_attr
= char_attr
;
4258 char_attr
= im_get_feedback_attr(feedback_col
);
4260 char_attr
= feedback_old_attr
;
4263 else if (feedback_old_attr
>= 0)
4265 char_attr
= feedback_old_attr
;
4266 feedback_old_attr
= -1;
4272 * Handle the case where we are in column 0 but not on the first
4273 * character of the line and the user wants us to show us a
4274 * special character (via 'listchars' option "precedes:<char>".
4276 if (lcs_prec_todo
!= NUL
4277 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4281 && draw_state
> WL_NR
4285 lcs_prec_todo
= NUL
;
4288 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4295 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4299 saved_attr3
= char_attr
; /* save current attr */
4300 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4306 * At end of the text line or just after the last character.
4309 #if defined(LINE_ATTR)
4310 || did_line_attr
== 1
4314 #ifdef FEAT_SEARCH_EXTRA
4315 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4317 /* we're not really at that column when skipping some text */
4318 if ((long)(wp
->w_p_wrap
? wp
->w_skipcol
: wp
->w_leftcol
) > prevcol
)
4322 /* invert at least one char, used for Visual and empty line or
4323 * highlight match at end of line. If it's beyond the last
4324 * char on the screen, just overwrite that one (tricky!) Not
4325 * needed when a '$' was displayed for 'list'. */
4326 #ifdef FEAT_SEARCH_EXTRA
4327 prevcol_hl_flag
= FALSE
;
4328 if (prevcol
== (long)search_hl
.startcol
)
4329 prevcol_hl_flag
= TRUE
;
4332 cur
= wp
->w_match_head
;
4335 if (prevcol
== (long)cur
->hl
.startcol
)
4337 prevcol_hl_flag
= TRUE
;
4344 if (lcs_eol
== lcs_eol_one
4345 && ((area_attr
!= 0 && vcol
== fromcol
&& c
== NUL
)
4346 #ifdef FEAT_SEARCH_EXTRA
4347 /* highlight 'hlsearch' match at end of line */
4348 || (prevcol_hl_flag
== TRUE
4349 # if defined(LINE_ATTR)
4350 && did_line_attr
<= 1
4358 #ifdef FEAT_RIGHTLEFT
4367 if (col
>= W_WIDTH(wp
))
4372 /* At the window boundary, highlight the last character
4373 * instead (better than nothing). */
4379 /* Add a blank character to highlight. */
4380 ScreenLines
[off
] = ' ';
4383 ScreenLinesUC
[off
] = 0;
4386 #ifdef FEAT_SEARCH_EXTRA
4389 /* Use attributes from match with highest priority among
4390 * 'search_hl' and the match list. */
4391 char_attr
= search_hl
.attr
;
4392 cur
= wp
->w_match_head
;
4394 while (cur
!= NULL
|| shl_flag
== FALSE
)
4396 if (shl_flag
== FALSE
4398 && cur
->priority
> SEARCH_HL_PRIORITY
)
4406 if ((ptr
- line
) - 1 == (long)shl
->startcol
)
4407 char_attr
= shl
->attr
;
4408 if (shl
!= &search_hl
&& cur
!= NULL
)
4413 ScreenAttrs
[off
] = char_attr
;
4414 #ifdef FEAT_RIGHTLEFT
4434 * At end of the text line.
4439 if (eol_hl_off
> 0 && vcol
- eol_hl_off
== (long)wp
->w_virtcol
)
4441 /* highlight last char after line */
4447 /* Highlight 'cursorcolumn' past end of the line. */
4452 /* check if line ends before left margin */
4453 if (vcol
< v
+ col
- win_col_off(wp
))
4455 vcol
= v
+ col
- win_col_off(wp
);
4457 && (int)wp
->w_virtcol
>= vcol
- eol_hl_off
4458 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4460 && lnum
!= wp
->w_cursor
.lnum
4461 # ifdef FEAT_RIGHTLEFT
4466 while (col
< W_WIDTH(wp
))
4468 ScreenLines
[off
] = ' ';
4471 ScreenLinesUC
[off
] = 0;
4474 if (vcol
== (long)wp
->w_virtcol
)
4476 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4479 ScreenAttrs
[off
++] = 0;
4485 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4490 * Update w_cline_height and w_cline_folded if the cursor line was
4491 * updated (saves a call to plines() later).
4493 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4495 curwin
->w_cline_row
= startrow
;
4496 curwin
->w_cline_height
= row
- startrow
;
4498 curwin
->w_cline_folded
= FALSE
;
4500 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4506 /* line continues beyond line end */
4513 #ifdef FEAT_RIGHTLEFT
4514 wp
->w_p_rl
? col
== 0 :
4516 col
== W_WIDTH(wp
) - 1)
4518 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4519 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4522 char_attr
= hl_attr(HLF_AT
);
4525 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4537 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4538 * highlight the cursor position itself. */
4539 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4540 && lnum
!= wp
->w_cursor
.lnum
4541 && draw_state
== WL_LINE
)
4543 vcol_save_attr
= char_attr
;
4544 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4547 vcol_save_attr
= -1;
4551 * Store character to be displayed.
4552 * Skip characters that are left of the screen for 'nowrap'.
4555 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4558 * Store the character.
4560 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4561 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4563 /* A double-wide character is: put first halve in left cell. */
4568 ScreenLines
[off
] = c
;
4570 if (enc_dbcs
== DBCS_JPNU
)
4571 ScreenLines2
[off
] = mb_c
& 0xff;
4578 ScreenLinesUC
[off
] = mb_c
;
4579 if ((c
& 0xff) == 0)
4580 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4581 for (i
= 0; i
< Screen_mco
; ++i
)
4583 ScreenLinesC
[i
][off
] = u8cc
[i
];
4589 ScreenLinesUC
[off
] = 0;
4593 ScreenAttrs
[off
] = multi_attr
;
4598 ScreenAttrs
[off
] = char_attr
;
4601 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4603 /* Need to fill two screen columns. */
4607 /* UTF-8: Put a 0 in the second screen char. */
4608 ScreenLines
[off
] = 0;
4610 /* DBCS: Put second byte in the second screen char. */
4611 ScreenLines
[off
] = mb_c
& 0xff;
4613 /* When "tocol" is halfway a character, set it to the end of
4614 * the character, otherwise highlighting won't stop. */
4617 #ifdef FEAT_RIGHTLEFT
4620 /* now it's time to backup one cell */
4627 #ifdef FEAT_RIGHTLEFT
4643 /* Only advance the "vcol" when after the 'number' column. */
4644 if (draw_state
>= WL_SBR
4652 if (vcol_save_attr
>= 0)
4653 char_attr
= vcol_save_attr
;
4656 /* restore attributes after "predeces" in 'listchars' */
4657 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4658 char_attr
= saved_attr3
;
4660 /* restore attributes after last 'listchars' or 'number' char */
4661 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4662 char_attr
= saved_attr2
;
4665 * At end of screen line and there is more to come: Display the line
4666 * so far. If there is no more to display it is caught above.
4669 #ifdef FEAT_RIGHTLEFT
4670 wp
->w_p_rl
? (col
< 0) :
4672 (col
>= W_WIDTH(wp
)))
4677 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4678 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4681 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4686 /* When not wrapping and finished diff lines, or when displayed
4687 * '$' and highlighting until last column, break here. */
4692 ) || lcs_eol_one
== -1)
4695 /* When the window is too narrow draw all "@" lines. */
4696 if (draw_state
!= WL_LINE
4702 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4703 #ifdef FEAT_VERTSPLIT
4704 draw_vsep_win(wp
, row
);
4709 /* When line got too long for screen break here. */
4716 if (screen_cur_row
== screen_row
- 1
4720 && W_WIDTH(wp
) == Columns
)
4722 /* Remember that the line wraps, used for modeless copy. */
4723 LineWraps
[screen_row
- 1] = TRUE
;
4726 * Special trick to make copy/paste of wrapped lines work with
4727 * xterm/screen: write an extra character beyond the end of
4728 * the line. This will work with all terminal types
4729 * (regardless of the xn,am settings).
4730 * Only do this on a fast tty.
4731 * Only do this if the cursor is on the current line
4732 * (something has been written in it).
4733 * Don't do this for the GUI.
4734 * Don't do this for double-width characters.
4735 * Don't do this for a window not at the right screen border.
4743 && ((*mb_off2cells
)(LineOffset
[screen_row
],
4744 LineOffset
[screen_row
] + screen_Columns
)
4746 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4748 LineOffset
[screen_row
] + screen_Columns
)
4753 /* First make sure we are at the end of the screen line,
4754 * then output the same character again to let the
4755 * terminal know about the wrap. If the terminal doesn't
4756 * auto-wrap, we overwrite the character. */
4757 if (screen_cur_col
!= W_WIDTH(wp
))
4758 screen_char(LineOffset
[screen_row
- 1]
4759 + (unsigned)Columns
- 1,
4760 screen_row
- 1, (int)(Columns
- 1));
4763 /* When there is a multi-byte character, just output a
4764 * space to keep it simple. */
4765 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4766 screen_row
- 1] + (Columns
- 1)]) > 1)
4770 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4772 /* force a redraw of the first char on the next line */
4773 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4774 screen_start(); /* don't know where cursor is now */
4779 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4780 #ifdef FEAT_RIGHTLEFT
4783 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4788 /* reset the drawing state for the start of a wrapped line */
4789 draw_state
= WL_START
;
4790 saved_n_extra
= n_extra
;
4791 saved_p_extra
= p_extra
;
4792 saved_c_extra
= c_extra
;
4793 saved_char_attr
= char_attr
;
4795 lcs_prec_todo
= lcs_prec
;
4796 #ifdef FEAT_LINEBREAK
4798 if (filler_todo
<= 0)
4800 need_showbreak
= TRUE
;
4804 /* When the filler lines are actually below the last line of the
4805 * file, don't draw the line itself, break here. */
4806 if (filler_todo
== 0 && wp
->w_botfill
)
4811 } /* for every character in the line */
4814 /* After an empty line check first word for capital. */
4815 if (*skipwhite(line
) == NUL
)
4817 capcol_lnum
= lnum
+ 1;
4826 static int comp_char_differs
__ARGS((int, int));
4829 * Return if the composing characters at "off_from" and "off_to" differ.
4832 comp_char_differs(off_from
, off_to
)
4838 for (i
= 0; i
< Screen_mco
; ++i
)
4840 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4842 if (ScreenLinesC
[i
][off_from
] == 0)
4850 * Check whether the given character needs redrawing:
4851 * - the (first byte of the) character is different
4852 * - the attributes are different
4853 * - the character is multi-byte and the next byte is different
4856 char_needs_redraw(off_from
, off_to
, cols
)
4862 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4863 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4867 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4868 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4869 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4870 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4871 != ScreenLines
[off_to
+ 1])))
4873 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4874 || (ScreenLinesUC
[off_from
] != 0
4875 && comp_char_differs(off_from
, off_to
))))
4883 * Move one "cooked" screen line to the screen, but only the characters that
4884 * have actually changed. Handle insert/delete character.
4885 * "coloff" gives the first column on the screen for this line.
4886 * "endcol" gives the columns where valid characters are.
4887 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4888 * needs to be cleared, negative otherwise.
4889 * "rlflag" is TRUE in a rightleft window:
4890 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4891 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4894 screen_line(row
, coloff
, endcol
, clear_width
4895 #ifdef FEAT_RIGHTLEFT
4903 #ifdef FEAT_RIGHTLEFT
4910 unsigned max_off_from
;
4911 unsigned max_off_to
;
4914 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4917 int force
= FALSE
; /* force update rest of the line */
4918 int redraw_this
/* bool: does character need redraw? */
4920 = TRUE
/* For GUI when while-loop empty */
4923 int redraw_next
; /* redraw_this for next character */
4925 int clear_next
= FALSE
;
4926 int char_cells
; /* 1: normal char */
4927 /* 2: occupies two display cells */
4928 # define CHAR_CELLS char_cells
4930 # define CHAR_CELLS 1
4933 # ifdef FEAT_CLIPBOARD
4934 clip_may_clear_selection(row
, row
);
4937 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
4938 off_to
= LineOffset
[row
] + coloff
;
4940 max_off_from
= off_from
+ screen_Columns
;
4941 max_off_to
= LineOffset
[row
] + screen_Columns
;
4944 #ifdef FEAT_RIGHTLEFT
4947 /* Clear rest first, because it's left of the text. */
4948 if (clear_width
> 0)
4950 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
4951 && ScreenAttrs
[off_to
] == 0
4953 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
4961 screen_fill(row
, row
+ 1, col
+ coloff
,
4962 endcol
+ coloff
+ 1, ' ', ' ', 0);
4965 off_to
= LineOffset
[row
] + col
+ coloff
;
4967 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
4969 #endif /* FEAT_RIGHTLEFT */
4971 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
4973 while (col
< endcol
)
4976 if (has_mbyte
&& (col
+ 1 < endcol
))
4977 char_cells
= (*mb_off2cells
)(off_from
, max_off_from
);
4982 redraw_this
= redraw_next
;
4983 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
4984 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
4987 /* If the next character was bold, then redraw the current character to
4988 * remove any pixels that might have spilt over into us. This only
4989 * happens in the GUI.
4991 if (redraw_next
&& gui
.in_use
)
4993 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
4995 hl
= syn_attr2attr(hl
);
5004 * Special handling when 'xs' termcap flag set (hpterm):
5005 * Attributes for characters are stored at the position where the
5006 * cursor is when writing the highlighting code. The
5007 * start-highlighting code must be written with the cursor on the
5008 * first highlighted character. The stop-highlighting code must
5009 * be written with the cursor just after the last highlighted
5011 * Overwriting a character doesn't remove it's highlighting. Need
5012 * to clear the rest of the line, and force redrawing it
5020 && ScreenAttrs
[off_to
] != 0
5021 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
5024 * Need to remove highlighting attributes here.
5026 windgoto(row
, col
+ coloff
);
5027 out_str(T_CE
); /* clear rest of this screen line */
5028 screen_start(); /* don't know where cursor is now */
5029 force
= TRUE
; /* force redraw of rest of the line */
5030 redraw_next
= TRUE
; /* or else next char would miss out */
5033 * If the previous character was highlighted, need to stop
5034 * highlighting at this character.
5036 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
5038 screen_attr
= ScreenAttrs
[off_to
- 1];
5039 term_windgoto(row
, col
+ coloff
);
5040 screen_stop_highlight();
5043 screen_attr
= 0; /* highlighting has stopped */
5048 /* Check if overwriting a double-byte with a single-byte or
5049 * the other way around requires another character to be
5050 * redrawn. For UTF-8 this isn't needed, because comparing
5051 * ScreenLinesUC[] is sufficient. */
5054 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5056 /* Writing a single-cell character over a double-cell
5057 * character: need to redraw the next cell. */
5058 ScreenLines
[off_to
+ 1] = 0;
5061 else if (char_cells
== 2
5063 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5064 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)
5066 /* Writing the second half of a double-cell character over
5067 * a double-cell character: need to redraw the second
5069 ScreenLines
[off_to
+ 2] = 0;
5073 if (enc_dbcs
== DBCS_JPNU
)
5074 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
5076 /* When writing a single-width character over a double-width
5077 * character and at the end of the redrawn text, need to clear out
5078 * the right halve of the old character.
5079 * Also required when writing the right halve of a double-width
5080 * char over the left halve of an existing one. */
5081 if (has_mbyte
&& col
+ char_cells
== endcol
5082 && ((char_cells
== 1
5083 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5085 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5086 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)))
5090 ScreenLines
[off_to
] = ScreenLines
[off_from
];
5094 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
5095 if (ScreenLinesUC
[off_from
] != 0)
5099 for (i
= 0; i
< Screen_mco
; ++i
)
5100 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
5103 if (char_cells
== 2)
5104 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
5107 #if defined(FEAT_GUI) || defined(UNIX)
5108 /* The bold trick makes a single row of pixels appear in the next
5109 * character. When a bold character is removed, the next
5110 * character should be redrawn too. This happens for our own GUI
5111 * and for some xterms. */
5116 # if defined(FEAT_GUI) && defined(UNIX)
5124 hl
= ScreenAttrs
[off_to
];
5126 hl
= syn_attr2attr(hl
);
5131 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5133 /* For simplicity set the attributes of second half of a
5134 * double-wide character equal to the first half. */
5135 if (char_cells
== 2)
5136 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5138 if (enc_dbcs
!= 0 && char_cells
== 2)
5139 screen_char_2(off_to
, row
, col
+ coloff
);
5142 screen_char(off_to
, row
, col
+ coloff
);
5148 && col
+ coloff
> 0)
5150 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5153 * Don't output stop-highlight when moving the cursor, it will
5154 * stop the highlighting when it should continue.
5158 else if (screen_attr
!= 0)
5159 screen_stop_highlight();
5162 off_to
+= CHAR_CELLS
;
5163 off_from
+= CHAR_CELLS
;
5170 /* Clear the second half of a double-wide character of which the left
5171 * half was overwritten with a single-wide character. */
5172 ScreenLines
[off_to
] = ' ';
5174 ScreenLinesUC
[off_to
] = 0;
5175 screen_char(off_to
, row
, col
+ coloff
);
5180 #ifdef FEAT_RIGHTLEFT
5189 /* blank out the rest of the line */
5190 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5191 && ScreenAttrs
[off_to
] == 0
5193 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5200 if (col
< clear_width
)
5204 * In the GUI, clearing the rest of the line may leave pixels
5205 * behind if the first character cleared was bold. Some bold
5206 * fonts spill over the left. In this case we redraw the previous
5207 * character too. If we didn't skip any blanks above, then we
5208 * only redraw if the character wasn't already redrawn anyway.
5210 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5212 hl
= ScreenAttrs
[off_to
];
5213 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5218 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5219 * that its width is 2. */
5220 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5221 else if (enc_dbcs
!= 0)
5223 /* find previous character by counting from first
5224 * column and get its width. */
5225 unsigned off
= LineOffset
[row
];
5226 unsigned max_off
= LineOffset
[row
] + screen_Columns
;
5228 while (off
< off_to
)
5230 prev_cells
= (*mb_off2cells
)(off
, max_off
);
5235 if (enc_dbcs
!= 0 && prev_cells
> 1)
5236 screen_char_2(off_to
- prev_cells
, row
,
5237 col
+ coloff
- prev_cells
);
5240 screen_char(off_to
- prev_cells
, row
,
5241 col
+ coloff
- prev_cells
);
5245 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5247 #ifdef FEAT_VERTSPLIT
5248 off_to
+= clear_width
- col
;
5254 if (clear_width
> 0)
5256 #ifdef FEAT_VERTSPLIT
5257 /* For a window that's left of another, draw the separator char. */
5258 if (col
+ coloff
< Columns
)
5262 c
= fillchar_vsep(&hl
);
5263 if (ScreenLines
[off_to
] != c
5265 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5266 != (c
>= 0x80 ? c
: 0))
5268 || ScreenAttrs
[off_to
] != hl
)
5270 ScreenLines
[off_to
] = c
;
5271 ScreenAttrs
[off_to
] = hl
;
5277 ScreenLinesUC
[off_to
] = c
;
5278 ScreenLinesC
[0][off_to
] = 0;
5281 ScreenLinesUC
[off_to
] = 0;
5284 screen_char(off_to
, row
, col
+ coloff
);
5289 LineWraps
[row
] = FALSE
;
5293 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5295 * Mirror text "str" for right-left displaying.
5296 * Only works for single-byte characters (e.g., numbers).
5305 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5314 #if defined(FEAT_WINDOWS) || defined(PROTO)
5316 * mark all status lines for redraw; used after first :cd
5323 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5324 if (wp
->w_status_height
)
5326 wp
->w_redr_status
= TRUE
;
5327 redraw_later(VALID
);
5332 * mark all status lines of the current buffer for redraw
5335 status_redraw_curbuf()
5339 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5340 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5342 wp
->w_redr_status
= TRUE
;
5343 redraw_later(VALID
);
5348 * Redraw all status lines that need to be redrawn.
5351 redraw_statuslines()
5355 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5356 if (wp
->w_redr_status
)
5357 win_redr_status(wp
);
5363 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5365 * Redraw all status lines at the bottom of frame "frp".
5368 win_redraw_last_status(frp
)
5371 if (frp
->fr_layout
== FR_LEAF
)
5372 frp
->fr_win
->w_redr_status
= TRUE
;
5373 else if (frp
->fr_layout
== FR_ROW
)
5375 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5376 win_redraw_last_status(frp
);
5378 else /* frp->fr_layout == FR_COL */
5380 frp
= frp
->fr_child
;
5381 while (frp
->fr_next
!= NULL
)
5383 win_redraw_last_status(frp
);
5388 #ifdef FEAT_VERTSPLIT
5390 * Draw the verticap separator right of window "wp" starting with line "row".
5393 draw_vsep_win(wp
, row
)
5400 if (wp
->w_vsep_width
)
5402 /* draw the vertical separator right of this window */
5403 c
= fillchar_vsep(&hl
);
5404 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5405 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5411 #ifdef FEAT_WILDMENU
5412 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5413 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5416 * Get the length of an item as it will be shown in the status line.
5419 status_match_len(xp
, s
)
5426 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5427 || xp
->xp_context
== EXPAND_MENUNAMES
);
5429 /* Check for menu separators - replace with '|'. */
5430 if (emenu
&& menu_is_separator(s
))
5436 if (skip_status_match_char(xp
, s
))
5438 len
+= ptr2cells(s
);
5446 * Return TRUE for characters that are not displayed in a status match.
5447 * These are backslashes used for escaping. Do show backslashes in help tags.
5450 skip_status_match_char(xp
, s
)
5454 return ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5456 || ((xp
->xp_context
== EXPAND_MENUS
5457 || xp
->xp_context
== EXPAND_MENUNAMES
)
5458 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5464 * Show wildchar matches in the status line.
5465 * Show at least the "match" item.
5466 * We start at item 'first_match' in the list and show all matches that fit.
5468 * If inversion is possible we use it. Else '=' characters are used.
5471 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5474 char_u
**matches
; /* list of matches */
5478 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5482 int clen
; /* length in screen cells */
5486 int highlight
= TRUE
;
5487 char_u
*selstart
= NULL
;
5488 int selstart_col
= 0;
5489 char_u
*selend
= NULL
;
5490 static int first_match
= 0;
5491 int add_left
= FALSE
;
5496 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5500 if (matches
== NULL
) /* interrupted completion? */
5505 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5508 buf
= alloc((unsigned)Columns
+ 1);
5512 if (match
== -1) /* don't show match but original text */
5517 /* count 1 for the ending ">" */
5518 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5521 else if (match
< first_match
)
5523 /* jumping left, as far as we can go */
5524 first_match
= match
;
5529 /* check if match fits on the screen */
5530 for (i
= first_match
; i
< match
; ++i
)
5531 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5532 if (first_match
> 0)
5534 /* jumping right, put match at the left */
5535 if ((long)clen
> Columns
)
5537 first_match
= match
;
5538 /* if showing the last match, we can add some on the left */
5540 for (i
= match
; i
< num_matches
; ++i
)
5542 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5543 if ((long)clen
>= Columns
)
5546 if (i
== num_matches
)
5551 while (first_match
> 0)
5553 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5554 if ((long)clen
>= Columns
)
5559 fillchar
= fillchar_status(&attr
, TRUE
);
5561 if (first_match
== 0)
5574 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5578 selstart
= buf
+ len
;
5579 selstart_col
= clen
;
5583 /* Check for menu separators - replace with '|' */
5585 emenu
= (xp
->xp_context
== EXPAND_MENUS
5586 || xp
->xp_context
== EXPAND_MENUNAMES
);
5587 if (emenu
&& menu_is_separator(s
))
5589 STRCPY(buf
+ len
, transchar('|'));
5590 l
= (int)STRLEN(buf
+ len
);
5596 for ( ; *s
!= NUL
; ++s
)
5598 if (skip_status_match_char(xp
, s
))
5600 clen
+= ptr2cells(s
);
5602 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5604 STRNCPY(buf
+ len
, s
, l
);
5611 STRCPY(buf
+ len
, transchar_byte(*s
));
5612 len
+= (int)STRLEN(buf
+ len
);
5618 *(buf
+ len
++) = ' ';
5619 *(buf
+ len
++) = ' ';
5621 if (++i
== num_matches
)
5625 if (i
!= num_matches
)
5627 *(buf
+ len
++) = '>';
5633 row
= cmdline_row
- 1;
5636 if (wild_menu_showing
== 0)
5638 if (msg_scrolled
> 0)
5640 /* Put the wildmenu just above the command line. If there is
5641 * no room, scroll the screen one line up. */
5642 if (cmdline_row
== Rows
- 1)
5644 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5652 wild_menu_showing
= WM_SCROLLED
;
5656 /* Create status line if needed by setting 'laststatus' to 2.
5657 * Set 'winminheight' to zero to avoid that the window is
5659 if (lastwin
->w_status_height
== 0)
5667 wild_menu_showing
= WM_SHOWN
;
5671 screen_puts(buf
, row
, 0, attr
);
5672 if (selstart
!= NULL
&& highlight
)
5675 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5678 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5681 #ifdef FEAT_VERTSPLIT
5682 win_redraw_last_status(topframe
);
5684 lastwin
->w_redr_status
= TRUE
;
5690 #if defined(FEAT_WINDOWS) || defined(PROTO)
5692 * Redraw the status line of window wp.
5694 * If inversion is possible we use it. Else '=' characters are used.
5707 wp
->w_redr_status
= FALSE
;
5708 if (wp
->w_status_height
== 0)
5710 /* no status line, can only be last window */
5711 redraw_cmdline
= TRUE
;
5713 else if (!redrawing()
5714 #ifdef FEAT_INS_EXPAND
5715 /* don't update status line when popup menu is visible and may be
5721 /* Don't redraw right now, do it later. */
5722 wp
->w_redr_status
= TRUE
;
5725 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5727 /* redraw custom status line */
5728 redraw_custum_statusline(wp
);
5733 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5735 get_trans_bufname(wp
->w_buffer
);
5737 len
= (int)STRLEN(p
);
5739 if (wp
->w_buffer
->b_help
5740 #ifdef FEAT_QUICKFIX
5743 || bufIsChanged(wp
->w_buffer
)
5744 || wp
->w_buffer
->b_p_ro
)
5746 if (wp
->w_buffer
->b_help
)
5748 STRCPY(p
+ len
, _("[Help]"));
5749 len
+= (int)STRLEN(p
+ len
);
5751 #ifdef FEAT_QUICKFIX
5754 STRCPY(p
+ len
, _("[Preview]"));
5755 len
+= (int)STRLEN(p
+ len
);
5758 if (bufIsChanged(wp
->w_buffer
))
5760 STRCPY(p
+ len
, "[+]");
5763 if (wp
->w_buffer
->b_p_ro
)
5765 STRCPY(p
+ len
, "[RO]");
5769 #ifndef FEAT_VERTSPLIT
5770 this_ru_col
= ru_col
;
5771 if (this_ru_col
< (Columns
+ 1) / 2)
5772 this_ru_col
= (Columns
+ 1) / 2;
5774 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5775 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5776 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5777 if (this_ru_col
<= 1)
5779 p
= (char_u
*)"<"; /* No room for file name! */
5789 /* Count total number of display cells. */
5790 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5791 clen
+= (*mb_ptr2cells
)(p
+ i
);
5792 /* Find first character that will fit.
5793 * Going from start to end is much faster for DBCS. */
5794 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5795 i
+= (*mb_ptr2len
)(p
+ i
))
5796 clen
-= (*mb_ptr2cells
)(p
+ i
);
5808 if (len
> this_ru_col
- 1)
5810 p
+= len
- (this_ru_col
- 1);
5812 len
= this_ru_col
- 1;
5815 row
= W_WINROW(wp
) + wp
->w_height
;
5816 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5817 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5818 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5820 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5821 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5822 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5823 - 1 + W_WINCOL(wp
)), attr
);
5825 #ifdef FEAT_CMDL_INFO
5826 win_redr_ruler(wp
, TRUE
);
5830 #ifdef FEAT_VERTSPLIT
5832 * May need to draw the character below the vertical separator.
5834 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5836 if (stl_connected(wp
))
5837 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5839 fillchar
= fillchar_vsep(&attr
);
5840 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5848 * Redraw the status line according to 'statusline' and take care of any
5849 * errors encountered.
5852 redraw_custum_statusline(wp
)
5855 int save_called_emsg
= called_emsg
;
5857 called_emsg
= FALSE
;
5858 win_redr_custom(wp
, FALSE
);
5860 set_string_option_direct((char_u
*)"statusline", -1,
5861 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5862 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5863 called_emsg
|= save_called_emsg
;
5867 # ifdef FEAT_VERTSPLIT
5869 * Return TRUE if the status line of window "wp" is connected to the status
5870 * line of the window right of it. If not, then it's a vertical separator.
5871 * Only call if (wp->w_vsep_width != 0).
5880 while (fr
->fr_parent
!= NULL
)
5882 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5884 if (fr
->fr_next
!= NULL
)
5889 if (fr
->fr_next
!= NULL
)
5898 #endif /* FEAT_WINDOWS */
5900 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
5902 * Get the value to show for the language mappings, active 'keymap'.
5905 get_keymap_str(wp
, buf
, len
)
5907 char_u
*buf
; /* buffer for the result */
5908 int len
; /* length of buffer */
5912 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
5917 buf_T
*old_curbuf
= curbuf
;
5918 win_T
*old_curwin
= curwin
;
5921 curbuf
= wp
->w_buffer
;
5923 STRCPY(buf
, "b:keymap_name"); /* must be writable */
5925 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
5927 curbuf
= old_curbuf
;
5928 curwin
= old_curwin
;
5929 if (p
== NULL
|| *p
== NUL
)
5933 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
5934 p
= wp
->w_buffer
->b_p_keymap
;
5937 p
= (char_u
*)"lang";
5939 if ((int)(STRLEN(p
) + 3) < len
)
5940 sprintf((char *)buf
, "<%s>", p
);
5947 return buf
[0] != NUL
;
5951 #if defined(FEAT_STL_OPT) || defined(PROTO)
5953 * Redraw the status line or ruler of window "wp".
5954 * When "wp" is NULL redraw the tab pages line from 'tabline'.
5957 win_redr_custom(wp
, draw_ruler
)
5959 int draw_ruler
; /* TRUE or FALSE */
5970 char_u buf
[MAXPATHL
];
5972 struct stl_hlrec hltab
[STL_MAX_ITEM
];
5973 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
5974 int use_sandbox
= FALSE
;
5976 /* setup environment for the task at hand */
5979 /* Use 'tabline'. Always at the first line of the screen. */
5983 attr
= hl_attr(HLF_TPF
);
5986 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
5991 row
= W_WINROW(wp
) + wp
->w_height
;
5992 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5993 maxwidth
= W_WIDTH(wp
);
5998 /* advance past any leading group spec - implicit in ru_col */
6003 if (atoi((char *) p
))
6004 while (VIM_ISDIGIT(*p
))
6009 #ifdef FEAT_VERTSPLIT
6010 col
= ru_col
- (Columns
- W_WIDTH(wp
));
6011 if (col
< (W_WIDTH(wp
) + 1) / 2)
6012 col
= (W_WIDTH(wp
) + 1) / 2;
6015 if (col
> (Columns
+ 1) / 2)
6016 col
= (Columns
+ 1) / 2;
6018 maxwidth
= W_WIDTH(wp
) - col
;
6020 if (!wp
->w_status_height
)
6024 --maxwidth
; /* writing in last column may cause scrolling */
6030 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
6035 if (*wp
->w_p_stl
!= NUL
)
6040 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
6041 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
6045 #ifdef FEAT_VERTSPLIT
6046 col
+= W_WINCOL(wp
);
6053 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
6056 fillchar
, maxwidth
, hltab
, tabtab
);
6057 len
= (int)STRLEN(buf
);
6059 while (width
< maxwidth
&& len
< sizeof(buf
) - 1)
6062 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
6064 buf
[len
++] = fillchar
;
6071 * Draw each snippet with the specified highlighting.
6075 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
6077 len
= (int)(hltab
[n
].start
- p
);
6078 screen_puts_len(p
, len
, row
, col
, curattr
);
6079 col
+= vim_strnsize(p
, len
);
6082 if (hltab
[n
].userhl
== 0)
6084 else if (hltab
[n
].userhl
< 0)
6085 curattr
= syn_id2attr(-hltab
[n
].userhl
);
6087 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
6088 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
6091 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
6093 screen_puts(p
, row
, col
, curattr
);
6097 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6102 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
6104 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
6106 TabPageIdxs
[col
++] = fillchar
;
6107 p
= tabtab
[n
].start
;
6108 fillchar
= tabtab
[n
].userhl
;
6110 while (col
< Columns
)
6111 TabPageIdxs
[col
++] = fillchar
;
6115 #endif /* FEAT_STL_OPT */
6118 * Output a single character directly to the screen and update ScreenLines.
6121 screen_putchar(c
, row
, col
, attr
)
6127 char_u buf
[MB_MAXBYTES
+ 1];
6129 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6136 screen_puts(buf
, row
, col
, attr
);
6140 * Get a single character directly from ScreenLines into "bytes[]".
6141 * Also return its attribute in *attrp;
6144 screen_getbytes(row
, col
, bytes
, attrp
)
6152 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6154 off
= LineOffset
[row
] + col
;
6155 *attrp
= ScreenAttrs
[off
];
6156 bytes
[0] = ScreenLines
[off
];
6160 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6161 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6162 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6164 bytes
[0] = ScreenLines
[off
];
6165 bytes
[1] = ScreenLines2
[off
];
6168 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6170 bytes
[1] = ScreenLines
[off
+ 1];
6178 static int screen_comp_differs
__ARGS((int, int*));
6181 * Return TRUE if composing characters for screen posn "off" differs from
6182 * composing characters in "u8cc".
6185 screen_comp_differs(off
, u8cc
)
6191 for (i
= 0; i
< Screen_mco
; ++i
)
6193 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6203 * Put string '*text' on the screen at position 'row' and 'col', with
6204 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6205 * Note: only outputs within one row, message is truncated at screen boundary!
6206 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6209 screen_puts(text
, row
, col
, attr
)
6215 screen_puts_len(text
, -1, row
, col
, attr
);
6219 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6223 screen_puts_len(text
, len
, row
, col
, attr
)
6236 int mbyte_cells
= 1;
6239 int clear_next_cell
= FALSE
;
6241 int prev_c
= 0; /* previous Arabic character */
6247 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6250 off
= LineOffset
[row
] + col
;
6252 max_off
= LineOffset
[row
] + screen_Columns
;
6254 while (col
< screen_Columns
6255 && (len
< 0 || (int)(ptr
- text
) < len
)
6260 /* check if this is the first byte of a multibyte */
6263 if (enc_utf8
&& len
> 0)
6264 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6266 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6267 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6269 else if (enc_dbcs
!= 0)
6270 mbyte_cells
= mbyte_blen
;
6274 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6275 (int)((text
+ len
) - ptr
));
6277 u8c
= utfc_ptr2char(ptr
, u8cc
);
6278 mbyte_cells
= utf_char2cells(u8c
);
6280 /* Non-BMP character: display as ? or fullwidth ?. */
6283 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6285 attr
= hl_attr(HLF_8
);
6289 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6291 /* Do Arabic shaping. */
6292 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6294 /* Past end of string to be displayed. */
6300 nc
= utfc_ptr2char(ptr
+ mbyte_blen
, pcc
);
6305 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6314 if (ScreenLines
[off
] != c
6316 || (mbyte_cells
== 2
6317 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6318 || (enc_dbcs
== DBCS_JPNU
6320 && ScreenLines2
[off
] != ptr
[1])
6322 && (ScreenLinesUC
[off
] != (u8char_T
)u8c
6323 || screen_comp_differs(off
, u8cc
)))
6325 || ScreenAttrs
[off
] != attr
6329 #if defined(FEAT_GUI) || defined(UNIX)
6330 /* The bold trick makes a single row of pixels appear in the next
6331 * character. When a bold character is removed, the next
6332 * character should be redrawn too. This happens for our own GUI
6333 * and for some xterms.
6334 * Force the redraw by setting the attribute to a different value
6335 * than "attr", the contents of ScreenLines[] may be needed by
6336 * mb_off2cells() further on.
6337 * Don't do this for the last drawn character, because the next
6338 * character may not be redrawn. */
6343 # if defined(FEAT_GUI) && defined(UNIX)
6353 n
= ScreenAttrs
[off
];
6355 if (col
+ mbyte_cells
< screen_Columns
6356 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6357 && (len
< 0 ? ptr
[mbyte_blen
] != NUL
6358 : ptr
+ mbyte_blen
< text
+ len
))
6359 ScreenAttrs
[off
+ mbyte_cells
] = attr
+ 1;
6361 if (col
+ 1 < screen_Columns
6362 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6363 && (len
< 0 ? ptr
[1] != NUL
: ptr
+ 1 < text
+ len
))
6364 ScreenLines
[off
+ 1] = 0;
6369 /* When at the end of the text and overwriting a two-cell
6370 * character with a one-cell character, need to clear the next
6371 * cell. Also when overwriting the left halve of a two-cell char
6372 * with the right halve of a two-cell char. Do this only once
6373 * (mb_off2cells() may return 2 on the right halve). */
6374 if (clear_next_cell
)
6375 clear_next_cell
= FALSE
;
6377 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6378 : ptr
+ mbyte_blen
>= text
+ len
)
6379 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6380 || (mbyte_cells
== 2
6381 && (*mb_off2cells
)(off
, max_off
) == 1
6382 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6383 clear_next_cell
= TRUE
;
6385 /* Make sure we never leave a second byte of a double-byte behind,
6386 * it confuses mb_off2cells(). */
6388 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6389 || (mbyte_cells
== 2
6390 && (*mb_off2cells
)(off
, max_off
) == 1
6391 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6392 ScreenLines
[off
+ mbyte_blen
] = 0;
6394 ScreenLines
[off
] = c
;
6395 ScreenAttrs
[off
] = attr
;
6399 if (c
< 0x80 && u8cc
[0] == 0)
6400 ScreenLinesUC
[off
] = 0;
6405 ScreenLinesUC
[off
] = u8c
;
6406 for (i
= 0; i
< Screen_mco
; ++i
)
6408 ScreenLinesC
[i
][off
] = u8cc
[i
];
6413 if (mbyte_cells
== 2)
6415 ScreenLines
[off
+ 1] = 0;
6416 ScreenAttrs
[off
+ 1] = attr
;
6418 screen_char(off
, row
, col
);
6420 else if (mbyte_cells
== 2)
6422 ScreenLines
[off
+ 1] = ptr
[1];
6423 ScreenAttrs
[off
+ 1] = attr
;
6424 screen_char_2(off
, row
, col
);
6426 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6428 ScreenLines2
[off
] = ptr
[1];
6429 screen_char(off
, row
, col
);
6433 screen_char(off
, row
, col
);
6441 if (clear_next_cell
)
6442 ptr
= (char_u
*)" ";
6454 #ifdef FEAT_SEARCH_EXTRA
6456 * Prepare for 'hlsearch' highlighting.
6461 if (p_hls
&& !no_hlsearch
)
6463 last_pat_prog(&search_hl
.rm
);
6464 search_hl
.attr
= hl_attr(HLF_L
);
6469 * Clean up for 'hlsearch' highlighting.
6474 if (search_hl
.rm
.regprog
!= NULL
)
6476 vim_free(search_hl
.rm
.regprog
);
6477 search_hl
.rm
.regprog
= NULL
;
6482 * Advance to the match in window "wp" line "lnum" or past it.
6485 prepare_search_hl(wp
, lnum
)
6489 matchitem_T
*cur
; /* points to the match list */
6490 match_T
*shl
; /* points to search_hl or a match */
6491 int shl_flag
; /* flag to indicate whether search_hl
6492 has been processed or not */
6496 * When using a multi-line pattern, start searching at the top
6497 * of the window or just after a closed fold.
6498 * Do this both for search_hl and the match list.
6500 cur
= wp
->w_match_head
;
6502 while (cur
!= NULL
|| shl_flag
== FALSE
)
6504 if (shl_flag
== FALSE
)
6511 if (shl
->rm
.regprog
!= NULL
6513 && re_multiline(shl
->rm
.regprog
))
6515 if (shl
->first_lnum
== 0)
6517 # ifdef FEAT_FOLDING
6518 for (shl
->first_lnum
= lnum
;
6519 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6520 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6521 NULL
, NULL
, TRUE
, NULL
))
6524 shl
->first_lnum
= wp
->w_topline
;
6528 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6530 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6533 shl
->first_lnum
= shl
->lnum
6534 + shl
->rm
.endpos
[0].lnum
6535 - shl
->rm
.startpos
[0].lnum
;
6536 n
= shl
->rm
.endpos
[0].col
;
6545 if (shl
!= &search_hl
&& cur
!= NULL
)
6551 * Search for a next 'hlsearch' or match.
6553 * Sets shl->lnum and shl->rm contents.
6554 * Note: Assumes a previous match is always before "lnum", unless
6555 * shl->lnum is zero.
6556 * Careful: Any pointers for buffer lines will become invalid.
6559 next_search_hl(win
, shl
, lnum
, mincol
)
6561 match_T
*shl
; /* points to search_hl or a match */
6563 colnr_T mincol
; /* minimal column for a match */
6571 /* Check for three situations:
6572 * 1. If the "lnum" is below a previous match, start a new search.
6573 * 2. If the previous match includes "mincol", use it.
6574 * 3. Continue after the previous match.
6576 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6579 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6584 * Repeat searching for a match until one is found that includes "mincol"
6585 * or none is found in this line.
6587 called_emsg
= FALSE
;
6590 /* Three situations:
6591 * 1. No useful previous match: search from start of line.
6592 * 2. Not Vi compatible or empty match: continue at next character.
6593 * Break the loop if this is beyond the end of the line.
6594 * 3. Vi compatible searching: continue at end of previous match.
6598 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6599 || (shl
->rm
.endpos
[0].lnum
== 0
6600 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6604 matchcol
= shl
->rm
.startpos
[0].col
;
6605 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6614 matchcol
+= mb_ptr2len(ml
);
6620 matchcol
= shl
->rm
.endpos
[0].col
;
6623 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
);
6626 /* Error while handling regexp: stop using this regexp. */
6627 if (shl
== &search_hl
)
6629 /* don't free regprog in the match list, it's a copy */
6630 vim_free(shl
->rm
.regprog
);
6633 shl
->rm
.regprog
= NULL
;
6635 got_int
= FALSE
; /* avoid the "Type :quit to exit Vim" message */
6640 shl
->lnum
= 0; /* no match found */
6643 if (shl
->rm
.startpos
[0].lnum
> 0
6644 || shl
->rm
.startpos
[0].col
>= mincol
6646 || shl
->rm
.endpos
[0].col
> mincol
)
6648 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6649 break; /* useful match found */
6656 screen_start_highlight(attr
)
6659 attrentry_T
*aep
= NULL
;
6673 /* The GUI handles this internally. */
6674 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6680 if (attr
> HL_ALL
) /* special HL attr. */
6683 aep
= syn_cterm_attr2entry(attr
);
6685 aep
= syn_term_attr2entry(attr
);
6686 if (aep
== NULL
) /* did ":syntax clear" */
6689 attr
= aep
->ae_attr
;
6691 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6693 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6694 && cterm_normal_fg_bold
)
6695 /* If the Normal FG color has BOLD attribute and the new HL
6696 * has a FG color defined, clear BOLD. */
6698 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6700 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6701 /* underline or undercurl */
6703 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6705 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6709 * Output the color or start string after bold etc., in case the
6710 * bold etc. override the color setting.
6716 if (aep
->ae_u
.cterm
.fg_color
)
6717 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6718 if (aep
->ae_u
.cterm
.bg_color
)
6719 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6723 if (aep
->ae_u
.term
.start
!= NULL
)
6724 out_str(aep
->ae_u
.term
.start
);
6732 screen_stop_highlight()
6734 int do_ME
= FALSE
; /* output T_ME code */
6736 if (screen_attr
!= 0
6747 /* use internal GUI code */
6748 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6754 if (screen_attr
> HL_ALL
) /* special HL attr. */
6761 * Assume that t_me restores the original colors!
6763 aep
= syn_cterm_attr2entry(screen_attr
);
6764 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6765 || aep
->ae_u
.cterm
.bg_color
))
6770 aep
= syn_term_attr2entry(screen_attr
);
6771 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6773 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6776 out_str(aep
->ae_u
.term
.stop
);
6779 if (aep
== NULL
) /* did ":syntax clear" */
6782 screen_attr
= aep
->ae_attr
;
6786 * Often all ending-codes are equal to T_ME. Avoid outputting the
6787 * same sequence several times.
6789 if (screen_attr
& HL_STANDOUT
)
6791 if (STRCMP(T_SE
, T_ME
) == 0)
6796 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6798 if (STRCMP(T_UE
, T_ME
) == 0)
6803 if (screen_attr
& HL_ITALIC
)
6805 if (STRCMP(T_CZR
, T_ME
) == 0)
6810 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6815 /* set Normal cterm colors */
6816 if (cterm_normal_fg_color
!= 0)
6817 term_fg_color(cterm_normal_fg_color
- 1);
6818 if (cterm_normal_bg_color
!= 0)
6819 term_bg_color(cterm_normal_bg_color
- 1);
6820 if (cterm_normal_fg_bold
)
6829 * Reset the colors for a cterm. Used when leaving Vim.
6830 * The machine specific code may override this again.
6833 reset_cterm_colors()
6837 /* set Normal cterm colors */
6838 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
6843 if (cterm_normal_fg_bold
)
6852 * Put character ScreenLines["off"] on the screen at position "row" and "col",
6853 * using the attributes from ScreenAttrs["off"].
6856 screen_char(off
, row
, col
)
6863 /* Check for illegal values, just in case (could happen just after
6865 if (row
>= screen_Rows
|| col
>= screen_Columns
)
6868 /* Outputting the last character on the screen may scrollup the screen.
6869 * Don't to it! Mark the character invalid (update it when scrolled up) */
6870 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
6871 #ifdef FEAT_RIGHTLEFT
6872 /* account for first command-line character in rightleft mode */
6877 ScreenAttrs
[off
] = (sattr_T
)-1;
6882 * Stop highlighting first, so it's easier to move the cursor.
6884 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
6885 if (screen_char_attr
!= 0)
6886 attr
= screen_char_attr
;
6889 attr
= ScreenAttrs
[off
];
6890 if (screen_attr
!= attr
)
6891 screen_stop_highlight();
6895 if (screen_attr
!= attr
)
6896 screen_start_highlight(attr
);
6899 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6901 char_u buf
[MB_MAXBYTES
+ 1];
6903 /* Convert UTF-8 character to bytes and write it. */
6905 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
6908 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
6917 out_char(ScreenLines
[off
]);
6919 /* double-byte character in single-width cell */
6920 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6921 out_char(ScreenLines2
[off
]);
6931 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
6932 * on the screen at position 'row' and 'col'.
6933 * The attributes of the first byte is used for all. This is required to
6934 * output the two bytes of a double-byte character with nothing in between.
6937 screen_char_2(off
, row
, col
)
6942 /* Check for illegal values (could be wrong when screen was resized). */
6943 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
6946 /* Outputting the last character on the screen may scrollup the screen.
6947 * Don't to it! Mark the character invalid (update it when scrolled up) */
6948 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
6950 ScreenAttrs
[off
] = (sattr_T
)-1;
6954 /* Output the first byte normally (positions the cursor), then write the
6955 * second byte directly. */
6956 screen_char(off
, row
, col
);
6957 out_char(ScreenLines
[off
+ 1]);
6962 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
6964 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
6965 * This uses the contents of ScreenLines[] and doesn't change it.
6968 screen_draw_rectangle(row
, col
, height
, width
, invert
)
6981 /* Can't use ScreenLines unless initialized */
6982 if (ScreenLines
== NULL
)
6986 screen_char_attr
= HL_INVERSE
;
6987 for (r
= row
; r
< row
+ height
; ++r
)
6989 off
= LineOffset
[r
];
6991 max_off
= off
+ screen_Columns
;
6993 for (c
= col
; c
< col
+ width
; ++c
)
6996 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
, max_off
) > 1)
6998 screen_char_2(off
+ c
, r
, c
);
7004 screen_char(off
+ c
, r
, c
);
7006 if (utf_off2cells(off
+ c
, max_off
) > 1)
7012 screen_char_attr
= 0;
7016 #ifdef FEAT_VERTSPLIT
7018 * Redraw the characters for a vertically split window.
7021 redraw_block(row
, end
, wp
)
7029 # ifdef FEAT_CLIPBOARD
7030 clip_may_clear_selection(row
, end
- 1);
7041 width
= wp
->w_width
;
7043 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
7048 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7049 * with character 'c1' in first column followed by 'c2' in the other columns.
7050 * Use attributes 'attr'.
7053 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
7054 int start_row
, end_row
;
7055 int start_col
, end_col
;
7066 #if defined(FEAT_GUI) || defined(UNIX)
7067 int force_next
= FALSE
;
7070 if (end_row
> screen_Rows
) /* safety check */
7071 end_row
= screen_Rows
;
7072 if (end_col
> screen_Columns
) /* safety check */
7073 end_col
= screen_Columns
;
7074 if (ScreenLines
== NULL
7075 || start_row
>= end_row
7076 || start_col
>= end_col
) /* nothing to do */
7079 /* it's a "normal" terminal when not in a GUI or cterm */
7085 for (row
= start_row
; row
< end_row
; ++row
)
7088 * Try to use delete-line termcap code, when no attributes or in a
7089 * "normal" terminal, where a bold/italic space is just a
7094 && end_col
== Columns
7099 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
7102 * check if we really need to clear something
7105 if (c1
!= ' ') /* don't clear first char */
7108 off
= LineOffset
[row
] + col
;
7109 end_off
= LineOffset
[row
] + end_col
;
7111 /* skip blanks (used often, keep it fast!) */
7114 while (off
< end_off
&& ScreenLines
[off
] == ' '
7115 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
7119 while (off
< end_off
&& ScreenLines
[off
] == ' '
7120 && ScreenAttrs
[off
] == 0)
7122 if (off
< end_off
) /* something to be cleared */
7124 col
= off
- LineOffset
[row
];
7125 screen_stop_highlight();
7126 term_windgoto(row
, col
);/* clear rest of this screen line */
7128 screen_start(); /* don't know where cursor is now */
7129 col
= end_col
- col
;
7130 while (col
--) /* clear chars in ScreenLines */
7132 ScreenLines
[off
] = ' ';
7135 ScreenLinesUC
[off
] = 0;
7137 ScreenAttrs
[off
] = 0;
7141 did_delete
= TRUE
; /* the chars are cleared now */
7144 off
= LineOffset
[row
] + start_col
;
7146 for (col
= start_col
; col
< end_col
; ++col
)
7148 if (ScreenLines
[off
] != c
7150 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
7151 != (c
>= 0x80 ? c
: 0))
7153 || ScreenAttrs
[off
] != attr
7154 #if defined(FEAT_GUI) || defined(UNIX)
7159 #if defined(FEAT_GUI) || defined(UNIX)
7160 /* The bold trick may make a single row of pixels appear in
7161 * the next character. When a bold character is removed, the
7162 * next character should be redrawn too. This happens for our
7163 * own GUI and for some xterms. */
7168 # if defined(FEAT_GUI) && defined(UNIX)
7176 if (ScreenLines
[off
] != ' '
7177 && (ScreenAttrs
[off
] > HL_ALL
7178 || ScreenAttrs
[off
] & HL_BOLD
))
7184 ScreenLines
[off
] = c
;
7190 ScreenLinesUC
[off
] = c
;
7191 ScreenLinesC
[0][off
] = 0;
7194 ScreenLinesUC
[off
] = 0;
7197 ScreenAttrs
[off
] = attr
;
7198 if (!did_delete
|| c
!= ' ')
7199 screen_char(off
, row
, col
);
7202 if (col
== start_col
)
7209 if (end_col
== Columns
)
7210 LineWraps
[row
] = FALSE
;
7211 if (row
== Rows
- 1) /* overwritten the command line */
7213 redraw_cmdline
= TRUE
;
7214 if (c1
== ' ' && c2
== ' ')
7215 clear_cmdline
= FALSE
; /* command line has been cleared */
7217 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7223 * Check if there should be a delay. Used before clearing or redrawing the
7224 * screen or the command line.
7227 check_for_delay(check_msg_scroll
)
7228 int check_msg_scroll
;
7230 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7232 && emsg_silent
== 0)
7235 ui_delay(1000L, TRUE
);
7236 emsg_on_display
= FALSE
;
7237 if (check_msg_scroll
)
7243 * screen_valid - allocate screen buffers if size changed
7244 * If "clear" is TRUE: clear screen if it has been resized.
7245 * Returns TRUE if there is a valid screen to write to.
7246 * Returns FALSE when starting up and screen not initialized yet.
7252 screenalloc(clear
); /* allocate screen buffers if size changed */
7253 return (ScreenLines
!= NULL
);
7257 * Resize the shell to Rows and Columns.
7258 * Allocate ScreenLines[] and associated items.
7260 * There may be some time between setting Rows and Columns and (re)allocating
7261 * ScreenLines[]. This happens when starting up and when (manually) changing
7262 * the shell size. Always use screen_Rows and screen_Columns to access items
7263 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7264 * final size of the shell is needed.
7270 int new_row
, old_row
;
7275 int outofmem
= FALSE
;
7277 schar_T
*new_ScreenLines
;
7279 u8char_T
*new_ScreenLinesUC
= NULL
;
7280 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7281 schar_T
*new_ScreenLines2
= NULL
;
7284 sattr_T
*new_ScreenAttrs
;
7285 unsigned *new_LineOffset
;
7286 char_u
*new_LineWraps
;
7288 short *new_TabPageIdxs
;
7291 static int entered
= FALSE
; /* avoid recursiveness */
7292 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7295 * Allocation of the screen buffers is done only when the size changes and
7296 * when Rows and Columns have been set and we have started doing full
7299 if ((ScreenLines
!= NULL
7300 && Rows
== screen_Rows
7301 && Columns
== screen_Columns
7303 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7304 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7305 && p_mco
== Screen_mco
7310 || (!full_screen
&& ScreenLines
== NULL
))
7314 * It's possible that we produce an out-of-memory message below, which
7315 * will cause this function to be called again. To break the loop, just
7323 * Note that the window sizes are updated before reallocating the arrays,
7324 * thus we must not redraw here!
7326 ++RedrawingDisabled
;
7328 win_new_shellsize(); /* fit the windows in the new sized shell */
7330 comp_col(); /* recompute columns for shown command and ruler */
7333 * We're changing the size of the screen.
7334 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7335 * - Move lines from the old arrays into the new arrays, clear extra
7336 * lines (unless the screen is going to be cleared).
7337 * - Free the old arrays.
7339 * If anything fails, make ScreenLines NULL, so we don't do anything!
7340 * Continuing with the old ScreenLines may result in a crash, because the
7343 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7346 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7347 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7349 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
) * MAX_MCO
);
7352 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7353 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7354 for (i
= 0; i
< p_mco
; ++i
)
7355 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc((long_u
)(
7356 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7358 if (enc_dbcs
== DBCS_JPNU
)
7359 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7360 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7362 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7363 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7364 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7365 Rows
* sizeof(unsigned)), FALSE
);
7366 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7368 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7371 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7373 if (win_alloc_lines(wp
) == FAIL
)
7383 for (i
= 0; i
< p_mco
; ++i
)
7384 if (new_ScreenLinesC
[i
] == NULL
)
7387 if (new_ScreenLines
== NULL
7389 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7390 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7392 || new_ScreenAttrs
== NULL
7393 || new_LineOffset
== NULL
7394 || new_LineWraps
== NULL
7396 || new_TabPageIdxs
== NULL
7400 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7402 /* guess the size */
7403 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7405 /* Remember we did this to avoid getting outofmem messages over
7406 * and over again. */
7407 done_outofmem_msg
= TRUE
;
7409 vim_free(new_ScreenLines
);
7410 new_ScreenLines
= NULL
;
7412 vim_free(new_ScreenLinesUC
);
7413 new_ScreenLinesUC
= NULL
;
7414 for (i
= 0; i
< p_mco
; ++i
)
7416 vim_free(new_ScreenLinesC
[i
]);
7417 new_ScreenLinesC
[i
] = NULL
;
7419 vim_free(new_ScreenLines2
);
7420 new_ScreenLines2
= NULL
;
7422 vim_free(new_ScreenAttrs
);
7423 new_ScreenAttrs
= NULL
;
7424 vim_free(new_LineOffset
);
7425 new_LineOffset
= NULL
;
7426 vim_free(new_LineWraps
);
7427 new_LineWraps
= NULL
;
7429 vim_free(new_TabPageIdxs
);
7430 new_TabPageIdxs
= NULL
;
7435 done_outofmem_msg
= FALSE
;
7437 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7439 new_LineOffset
[new_row
] = new_row
* Columns
;
7440 new_LineWraps
[new_row
] = FALSE
;
7443 * If the screen is not going to be cleared, copy as much as
7444 * possible from the old screen to the new one and clear the rest
7445 * (used when resizing the window at the "--more--" prompt or when
7446 * executing an external command, for the GUI).
7450 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7451 ' ', (size_t)Columns
* sizeof(schar_T
));
7455 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7456 0, (size_t)Columns
* sizeof(u8char_T
));
7457 for (i
= 0; i
< p_mco
; ++i
)
7458 (void)vim_memset(new_ScreenLinesC
[i
]
7459 + new_row
* Columns
,
7460 0, (size_t)Columns
* sizeof(u8char_T
));
7462 if (enc_dbcs
== DBCS_JPNU
)
7463 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7464 0, (size_t)Columns
* sizeof(schar_T
));
7466 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7467 0, (size_t)Columns
* sizeof(sattr_T
));
7468 old_row
= new_row
+ (screen_Rows
- Rows
);
7469 if (old_row
>= 0 && ScreenLines
!= NULL
)
7471 if (screen_Columns
< Columns
)
7472 len
= screen_Columns
;
7476 /* When switching to utf-8 don't copy characters, they
7477 * may be invalid now. Also when p_mco changes. */
7478 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7479 && p_mco
== Screen_mco
)
7481 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7482 ScreenLines
+ LineOffset
[old_row
],
7483 (size_t)len
* sizeof(schar_T
));
7485 if (enc_utf8
&& ScreenLinesUC
!= NULL
7486 && p_mco
== Screen_mco
)
7488 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7489 ScreenLinesUC
+ LineOffset
[old_row
],
7490 (size_t)len
* sizeof(u8char_T
));
7491 for (i
= 0; i
< p_mco
; ++i
)
7492 mch_memmove(new_ScreenLinesC
[i
]
7493 + new_LineOffset
[new_row
],
7494 ScreenLinesC
[i
] + LineOffset
[old_row
],
7495 (size_t)len
* sizeof(u8char_T
));
7497 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7498 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7499 ScreenLines2
+ LineOffset
[old_row
],
7500 (size_t)len
* sizeof(schar_T
));
7502 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7503 ScreenAttrs
+ LineOffset
[old_row
],
7504 (size_t)len
* sizeof(sattr_T
));
7508 /* Use the last line of the screen for the current line. */
7509 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7514 ScreenLines
= new_ScreenLines
;
7516 ScreenLinesUC
= new_ScreenLinesUC
;
7517 for (i
= 0; i
< p_mco
; ++i
)
7518 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7520 ScreenLines2
= new_ScreenLines2
;
7522 ScreenAttrs
= new_ScreenAttrs
;
7523 LineOffset
= new_LineOffset
;
7524 LineWraps
= new_LineWraps
;
7526 TabPageIdxs
= new_TabPageIdxs
;
7529 /* It's important that screen_Rows and screen_Columns reflect the actual
7530 * size of ScreenLines[]. Set them before calling anything. */
7532 old_Rows
= screen_Rows
;
7535 screen_Columns
= Columns
;
7537 must_redraw
= CLEAR
; /* need to clear the screen later */
7544 && ScreenLines
!= NULL
7545 && old_Rows
!= Rows
)
7547 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7549 * Adjust the position of the cursor, for when executing an external
7552 if (msg_row
>= Rows
) /* Rows got smaller */
7553 msg_row
= Rows
- 1; /* put cursor at last row */
7554 else if (Rows
> old_Rows
) /* Rows got bigger */
7555 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7556 if (msg_col
>= Columns
) /* Columns got smaller */
7557 msg_col
= Columns
- 1; /* put cursor at last column */
7562 --RedrawingDisabled
;
7566 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7576 vim_free(ScreenLinesUC
);
7577 for (i
= 0; i
< Screen_mco
; ++i
)
7578 vim_free(ScreenLinesC
[i
]);
7579 vim_free(ScreenLines2
);
7581 vim_free(ScreenLines
);
7582 vim_free(ScreenAttrs
);
7583 vim_free(LineOffset
);
7584 vim_free(LineWraps
);
7586 vim_free(TabPageIdxs
);
7593 check_for_delay(FALSE
);
7594 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7595 screenclear2(); /* clear the screen */
7603 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7605 || (gui
.in_use
&& gui
.starting
)
7613 screen_attr
= -1; /* force setting the Normal colors */
7614 screen_stop_highlight(); /* don't want highlighting here */
7616 #ifdef FEAT_CLIPBOARD
7617 /* disable selection without redrawing it */
7618 clip_scroll_selection(9999);
7621 /* blank out ScreenLines */
7622 for (i
= 0; i
< Rows
; ++i
)
7624 lineclear(LineOffset
[i
], (int)Columns
);
7625 LineWraps
[i
] = FALSE
;
7628 if (can_clear(T_CL
))
7630 out_str(T_CL
); /* clear the display */
7631 clear_cmdline
= FALSE
;
7632 mode_displayed
= FALSE
;
7636 /* can't clear the screen, mark all chars with invalid attributes */
7637 for (i
= 0; i
< Rows
; ++i
)
7638 lineinvalid(LineOffset
[i
], (int)Columns
);
7639 clear_cmdline
= TRUE
;
7642 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7644 win_rest_invalid(firstwin
);
7645 redraw_cmdline
= TRUE
;
7647 redraw_tabline
= TRUE
;
7649 if (must_redraw
== CLEAR
) /* no need to clear again */
7650 must_redraw
= NOT_VALID
;
7652 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7654 screen_start(); /* don't know where cursor is now */
7655 msg_scrolled
= 0; /* can't scroll back */
7661 * Clear one line in ScreenLines.
7664 lineclear(off
, width
)
7668 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7671 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7672 (size_t)width
* sizeof(u8char_T
));
7674 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7678 * Mark one line in ScreenLines invalid by setting the attributes to an
7682 lineinvalid(off
, width
)
7686 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7689 #ifdef FEAT_VERTSPLIT
7691 * Copy part of a Screenline for vertically split window "wp".
7694 linecopy(to
, from
, wp
)
7699 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7700 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7702 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7703 wp
->w_width
* sizeof(schar_T
));
7709 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7710 wp
->w_width
* sizeof(u8char_T
));
7711 for (i
= 0; i
< p_mco
; ++i
)
7712 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7713 wp
->w_width
* sizeof(u8char_T
));
7715 if (enc_dbcs
== DBCS_JPNU
)
7716 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7717 wp
->w_width
* sizeof(schar_T
));
7719 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7720 wp
->w_width
* sizeof(sattr_T
));
7725 * Return TRUE if clearing with term string "p" would work.
7726 * It can't work when the string is empty or it won't set the right background.
7732 return (*p
!= NUL
&& (t_colors
<= 1
7736 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7740 * Reset cursor position. Use whenever cursor was moved because of outputting
7741 * something directly to the screen (shell commands) or a terminal control
7747 screen_cur_row
= screen_cur_col
= 9999;
7751 * Move the cursor to position "row","col" in the screen.
7752 * This tries to find the most efficient way to move, minimizing the number of
7753 * characters sent to the terminal.
7770 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
7771 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7776 #define PLAN_WRITE 4
7777 /* Can't use ScreenLines unless initialized */
7778 if (ScreenLines
== NULL
)
7781 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7783 /* Check for valid position. */
7784 if (row
< 0) /* window without text lines? */
7786 if (row
>= screen_Rows
)
7787 row
= screen_Rows
- 1;
7788 if (col
>= screen_Columns
)
7789 col
= screen_Columns
- 1;
7791 /* check if no cursor movement is allowed in highlight mode */
7792 if (screen_attr
&& *T_MS
== NUL
)
7793 noinvcurs
= HIGHL_COST
;
7796 goto_cost
= GOTO_COST
+ noinvcurs
;
7799 * Plan how to do the positioning:
7800 * 1. Use CR to move it to column 0, same row.
7801 * 2. Use T_LE to move it a few columns to the left.
7802 * 3. Use NL to move a few lines down, column 0.
7803 * 4. Move a few columns to the right with T_ND or by writing chars.
7805 * Don't do this if the cursor went beyond the last column, the cursor
7806 * position is unknown then (some terminals wrap, some don't )
7808 * First check if the highlighting attributes allow us to write
7809 * characters to move the cursor to the right.
7811 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
7814 * If the cursor is in the same row, bigger col, we can use CR
7817 bs
= NULL
; /* init for GCC */
7819 if (row
== screen_cur_row
&& col
< screen_cur_col
)
7821 /* "le" is preferred over "bc", because "bc" is obsolete */
7823 bs
= T_LE
; /* "cursor left" */
7825 bs
= T_BC
; /* "backspace character (old) */
7827 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
7830 if (col
+ 1 < cost
) /* using CR is less characters */
7834 cost
= 1; /* CR is just one character */
7841 if (noinvcurs
) /* will stop highlighting */
7849 * If the cursor is above where we want to be, we can use CR LF.
7851 else if (row
> screen_cur_row
)
7855 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
7856 if (noinvcurs
) /* will stop highlighting */
7864 * If the cursor is in the same row, smaller col, just use write.
7869 wouldbe_col
= screen_cur_col
;
7874 * Check if any characters that need to be written have the
7875 * correct attributes. Also avoid UTF-8 characters.
7877 i
= col
- wouldbe_col
;
7880 if (cost
< goto_cost
&& i
> 0)
7883 * Check if the attributes are correct without additionally
7884 * stopping highlighting.
7886 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
7887 while (i
&& *p
++ == attr
)
7892 * Try if it works when highlighting is stopped here.
7897 while (i
&& *p
++ == 0)
7901 cost
= 999; /* different attributes, don't do it */
7906 /* Don't use an UTF-8 char for positioning, it's slow. */
7907 for (i
= wouldbe_col
; i
< col
; ++i
)
7908 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
7918 * We can do it without term_windgoto()!
7920 if (cost
< goto_cost
)
7922 if (plan
== PLAN_LE
)
7925 screen_stop_highlight();
7926 while (screen_cur_col
> col
)
7932 else if (plan
== PLAN_CR
)
7935 screen_stop_highlight();
7939 else if (plan
== PLAN_NL
)
7942 screen_stop_highlight();
7943 while (screen_cur_row
< row
)
7951 i
= col
- screen_cur_col
;
7955 * Use cursor-right if it's one character only. Avoids
7956 * removing a line of pixels from the last bold char, when
7957 * using the bold trick in the GUI.
7959 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
7968 off
= LineOffset
[row
] + screen_cur_col
;
7971 if (ScreenAttrs
[off
] != screen_attr
)
7972 screen_stop_highlight();
7976 out_char(ScreenLines
[off
]);
7978 if (enc_dbcs
== DBCS_JPNU
7979 && ScreenLines
[off
] == 0x8e)
7980 out_char(ScreenLines2
[off
]);
7991 if (cost
>= goto_cost
)
7994 screen_stop_highlight();
7995 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
7997 term_cursor_right(col
- screen_cur_col
);
7999 term_windgoto(row
, col
);
8001 screen_cur_row
= row
;
8002 screen_cur_col
= col
;
8007 * Set cursor to its position in the current window.
8015 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
8016 W_WINCOL(curwin
) + (
8017 #ifdef FEAT_RIGHTLEFT
8018 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
8020 has_mbyte
? (*mb_ptr2cells
)(ml_get_cursor()) :
8030 * insert 'line_count' lines at 'row' in window 'wp'
8031 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8032 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8034 * Returns FAIL if the lines are not inserted, OK for success.
8037 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
8050 wp
->w_lines_valid
= 0;
8052 if (wp
->w_height
< 5)
8055 if (line_count
> wp
->w_height
- row
)
8056 line_count
= wp
->w_height
- row
;
8058 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
8059 if (retval
!= MAYBE
)
8063 * If there is a next window or a status line, we first try to delete the
8064 * lines at the bottom to avoid messing what is after the window.
8065 * If this fails and there are following windows, don't do anything to avoid
8066 * messing up those windows, better just redraw.
8070 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
8072 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8073 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
8075 else if (wp
->w_next
)
8080 * if no lines deleted, blank the lines that will end up below the window
8085 wp
->w_redr_status
= TRUE
;
8087 redraw_cmdline
= TRUE
;
8088 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
8089 lastrow
= nextrow
+ line_count
;
8092 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
8093 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8097 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
8100 /* deletion will have messed up other windows */
8104 wp
->w_redr_status
= TRUE
;
8106 win_rest_invalid(W_NEXT(wp
));
8115 * delete "line_count" window lines at "row" in window "wp"
8116 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8117 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8119 * Return OK for success, FAIL if the lines are not deleted.
8122 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
8132 wp
->w_lines_valid
= 0;
8134 if (line_count
> wp
->w_height
- row
)
8135 line_count
= wp
->w_height
- row
;
8137 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
8138 if (retval
!= MAYBE
)
8141 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
8142 (int)Rows
, FALSE
, NULL
) == FAIL
)
8147 * If there are windows or status lines below, try to put them at the
8148 * correct place. If we can't do that, they have to be redrawn.
8150 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
8152 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8153 line_count
, (int)Rows
, NULL
) == FAIL
)
8155 wp
->w_redr_status
= TRUE
;
8156 win_rest_invalid(wp
->w_next
);
8160 * If this is the last window and there is no status line, redraw the
8161 * command line later.
8165 redraw_cmdline
= TRUE
;
8170 * Common code for win_ins_lines() and win_del_lines().
8171 * Returns OK or FAIL when the work has been done.
8172 * Returns MAYBE when not finished yet.
8175 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8184 if (!redrawing() || line_count
<= 0)
8187 /* only a few lines left: redraw is faster */
8188 if (mayclear
&& Rows
- line_count
< 5
8189 #ifdef FEAT_VERTSPLIT
8190 && wp
->w_width
== Columns
8194 screenclear(); /* will set wp->w_lines_valid to 0 */
8199 * Delete all remaining lines
8201 if (row
+ line_count
>= wp
->w_height
)
8203 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8204 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8210 * when scrolling, the message on the command line should be cleared,
8211 * otherwise it will stay there forever.
8213 clear_cmdline
= TRUE
;
8216 * If the terminal can set a scroll region, use that.
8217 * Always do this in a vertically split window. This will redraw from
8218 * ScreenLines[] when t_CV isn't defined. That's faster than using
8220 * Don't use a scroll region when we are going to redraw the text, writing
8221 * a character in the lower right corner of the scroll region causes a
8222 * scroll-up in the DJGPP version.
8225 #ifdef FEAT_VERTSPLIT
8226 || W_WIDTH(wp
) != Columns
8230 #ifdef FEAT_VERTSPLIT
8231 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8233 scroll_region_set(wp
, row
);
8235 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8236 wp
->w_height
- row
, FALSE
, wp
);
8238 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8239 wp
->w_height
- row
, wp
);
8240 #ifdef FEAT_VERTSPLIT
8241 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8243 scroll_region_reset();
8248 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8256 * window 'wp' and everything after it is messed up, mark it for redraw
8259 win_rest_invalid(wp
)
8268 redraw_win_later(wp
, NOT_VALID
);
8270 wp
->w_redr_status
= TRUE
;
8274 redraw_cmdline
= TRUE
;
8278 * The rest of the routines in this file perform screen manipulations. The
8279 * given operation is performed physically on the screen. The corresponding
8280 * change is also made to the internal screen image. In this way, the editor
8281 * anticipates the effect of editing changes on the appearance of the screen.
8282 * That way, when we call screenupdate a complete redraw isn't usually
8283 * necessary. Another advantage is that we can keep adding code to anticipate
8284 * screen changes, and in the meantime, everything still works.
8288 * types for inserting or deleting lines
8298 #define USE_REDRAW 9
8301 * insert lines on the screen and update ScreenLines[]
8302 * 'end' is the line after the scrolled part. Normally it is Rows.
8303 * When scrolling region used 'off' is the offset from the top for the region.
8304 * 'row' and 'end' are relative to the start of the region.
8306 * return FAIL for failure, OK for success.
8309 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8314 win_T
*wp
; /* NULL or window to use width from */
8322 int can_ce
= can_clear(T_CE
);
8326 * - there is no valid screen
8327 * - the screen has to be redrawn completely
8328 * - the line count is less than one
8329 * - the line count is more than 'ttyscroll'
8331 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8335 * There are seven ways to insert lines:
8336 * 0. When in a vertically split window and t_CV isn't set, redraw the
8337 * characters from ScreenLines[].
8338 * 1. Use T_CD (clear to end of display) if it exists and the result of
8339 * the insert is just empty lines
8340 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8341 * present or line_count > 1. It looks better if we do all the inserts
8343 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8344 * insert is just empty lines and T_CE is not present or line_count >
8346 * 4. Use T_AL (insert line) if it exists.
8347 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8349 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8351 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8352 * the 'da' flag is not set or we have clear line capability.
8353 * 8. redraw the characters from ScreenLines[].
8355 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8356 * the scrollbar for the window. It does have insert line, use that if it
8359 result_empty
= (row
+ line_count
>= end
);
8360 #ifdef FEAT_VERTSPLIT
8361 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8365 if (can_clear(T_CD
) && result_empty
)
8367 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8369 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8371 else if (*T_AL
!= NUL
)
8373 else if (can_ce
&& result_empty
)
8375 else if (*T_DL
!= NUL
&& result_empty
)
8377 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8383 * For clearing the lines screen_del_lines() is used. This will also take
8384 * care of t_db if necessary.
8386 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8387 type
== USE_T_CE
|| type
== USE_T_DL
)
8388 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8391 * If text is retained below the screen, first clear or delete as many
8392 * lines at the bottom of the window as are about to be inserted so that
8393 * the deleted lines won't later surface during a screen_del_lines.
8396 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8398 #ifdef FEAT_CLIPBOARD
8399 /* Remove a modeless selection when inserting lines halfway the screen
8400 * or not the full width of the screen. */
8402 # ifdef FEAT_VERTSPLIT
8403 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8406 clip_clear_selection();
8408 clip_scroll_selection(-line_count
);
8412 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8413 * scrolling is actually carried out. */
8414 gui_dont_update_cursor();
8417 if (*T_CCS
!= NUL
) /* cursor relative to region */
8420 cursor_row
= row
+ off
;
8423 * Shift LineOffset[] line_count down to reflect the inserted lines.
8424 * Clear the inserted lines in ScreenLines[].
8428 for (i
= 0; i
< line_count
; ++i
)
8430 #ifdef FEAT_VERTSPLIT
8431 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8433 /* need to copy part of a line */
8435 while ((j
-= line_count
) >= row
)
8436 linecopy(j
+ line_count
, j
, wp
);
8438 if (can_clear((char_u
*)" "))
8439 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8441 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8442 LineWraps
[j
] = FALSE
;
8448 temp
= LineOffset
[j
];
8449 while ((j
-= line_count
) >= row
)
8451 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8452 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8454 LineOffset
[j
+ line_count
] = temp
;
8455 LineWraps
[j
+ line_count
] = FALSE
;
8456 if (can_clear((char_u
*)" "))
8457 lineclear(temp
, (int)Columns
);
8459 lineinvalid(temp
, (int)Columns
);
8463 screen_stop_highlight();
8464 windgoto(cursor_row
, 0);
8466 #ifdef FEAT_VERTSPLIT
8467 /* redraw the characters */
8468 if (type
== USE_REDRAW
)
8469 redraw_block(row
, end
, wp
);
8472 if (type
== USE_T_CAL
)
8474 term_append_lines(line_count
);
8475 screen_start(); /* don't know where cursor is now */
8479 for (i
= 0; i
< line_count
; i
++)
8481 if (type
== USE_T_AL
)
8483 if (i
&& cursor_row
!= 0)
8484 windgoto(cursor_row
, 0);
8487 else /* type == USE_T_SR */
8489 screen_start(); /* don't know where cursor is now */
8494 * With scroll-reverse and 'da' flag set we need to clear the lines that
8495 * have been scrolled down into the region.
8497 if (type
== USE_T_SR
&& *T_DA
)
8499 for (i
= 0; i
< line_count
; ++i
)
8501 windgoto(off
+ i
, 0);
8503 screen_start(); /* don't know where cursor is now */
8508 gui_can_update_cursor();
8510 out_flush(); /* always flush after a scroll */
8516 * delete lines on the screen and update ScreenLines[]
8517 * 'end' is the line after the scrolled part. Normally it is Rows.
8518 * When scrolling region used 'off' is the offset from the top for the region.
8519 * 'row' and 'end' are relative to the start of the region.
8521 * Return OK for success, FAIL if the lines are not deleted.
8525 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8530 int force
; /* even when line_count > p_ttyscroll */
8531 win_T
*wp
; /* NULL or window to use width from */
8538 int result_empty
; /* result is empty until end of region */
8539 int can_delete
; /* deleting line codes can be used */
8544 * - there is no valid screen
8545 * - the screen has to be redrawn completely
8546 * - the line count is less than one
8547 * - the line count is more than 'ttyscroll'
8549 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8550 (!force
&& line_count
> p_ttyscroll
))
8554 * Check if the rest of the current region will become empty.
8556 result_empty
= row
+ line_count
>= end
;
8559 * We can delete lines only when 'db' flag not set or when 'ce' option
8562 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8565 * There are six ways to delete lines:
8566 * 0. When in a vertically split window and t_CV isn't set, redraw the
8567 * characters from ScreenLines[].
8568 * 1. Use T_CD if it exists and the result is empty.
8569 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8570 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8571 * none of the other ways work.
8572 * 4. Use T_CE (erase line) if the result is empty.
8573 * 5. Use T_DL (delete line) if it exists.
8574 * 6. redraw the characters from ScreenLines[].
8576 #ifdef FEAT_VERTSPLIT
8577 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8581 if (can_clear(T_CD
) && result_empty
)
8583 #if defined(__BEOS__) && defined(BEOS_DR8)
8585 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8586 * its internal termcap... this works okay for tests which test *T_DB !=
8587 * NUL. It has the disadvantage that the user cannot use any :set t_*
8588 * command to get T_DB (back) to empty_option, only :set term=... will do
8590 * Anyway, this hack will hopefully go away with the next OS release.
8593 else if (row
== 0 && T_DB
== empty_option
8594 && (line_count
== 1 || *T_CDL
== NUL
))
8596 else if (row
== 0 && (
8598 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8599 * up, so use delete-line command */
8605 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8607 else if (can_clear(T_CE
) && result_empty
8608 #ifdef FEAT_VERTSPLIT
8609 && (wp
== NULL
|| wp
->w_width
== Columns
)
8613 else if (*T_DL
!= NUL
&& can_delete
)
8615 else if (*T_CDL
!= NUL
&& can_delete
)
8620 #ifdef FEAT_CLIPBOARD
8621 /* Remove a modeless selection when deleting lines halfway the screen or
8622 * not the full width of the screen. */
8624 # ifdef FEAT_VERTSPLIT
8625 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8628 clip_clear_selection();
8630 clip_scroll_selection(line_count
);
8634 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8635 * scrolling is actually carried out. */
8636 gui_dont_update_cursor();
8639 if (*T_CCS
!= NUL
) /* cursor relative to region */
8646 cursor_row
= row
+ off
;
8647 cursor_end
= end
+ off
;
8651 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8652 * Clear the inserted lines in ScreenLines[].
8656 for (i
= 0; i
< line_count
; ++i
)
8658 #ifdef FEAT_VERTSPLIT
8659 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8661 /* need to copy part of a line */
8663 while ((j
+= line_count
) <= end
- 1)
8664 linecopy(j
- line_count
, j
, wp
);
8666 if (can_clear((char_u
*)" "))
8667 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8669 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8670 LineWraps
[j
] = FALSE
;
8675 /* whole width, moving the line pointers is faster */
8677 temp
= LineOffset
[j
];
8678 while ((j
+= line_count
) <= end
- 1)
8680 LineOffset
[j
- line_count
] = LineOffset
[j
];
8681 LineWraps
[j
- line_count
] = LineWraps
[j
];
8683 LineOffset
[j
- line_count
] = temp
;
8684 LineWraps
[j
- line_count
] = FALSE
;
8685 if (can_clear((char_u
*)" "))
8686 lineclear(temp
, (int)Columns
);
8688 lineinvalid(temp
, (int)Columns
);
8692 screen_stop_highlight();
8694 #ifdef FEAT_VERTSPLIT
8695 /* redraw the characters */
8696 if (type
== USE_REDRAW
)
8697 redraw_block(row
, end
, wp
);
8700 if (type
== USE_T_CD
) /* delete the lines */
8702 windgoto(cursor_row
, 0);
8704 screen_start(); /* don't know where cursor is now */
8706 else if (type
== USE_T_CDL
)
8708 windgoto(cursor_row
, 0);
8709 term_delete_lines(line_count
);
8710 screen_start(); /* don't know where cursor is now */
8713 * Deleting lines at top of the screen or scroll region: Just scroll
8714 * the whole screen (scroll region) up by outputting newlines on the
8717 else if (type
== USE_NL
)
8719 windgoto(cursor_end
- 1, 0);
8720 for (i
= line_count
; --i
>= 0; )
8721 out_char('\n'); /* cursor will remain on same line */
8725 for (i
= line_count
; --i
>= 0; )
8727 if (type
== USE_T_DL
)
8729 windgoto(cursor_row
, 0);
8730 out_str(T_DL
); /* delete a line */
8732 else /* type == USE_T_CE */
8734 windgoto(cursor_row
+ i
, 0);
8735 out_str(T_CE
); /* erase a line */
8737 screen_start(); /* don't know where cursor is now */
8742 * If the 'db' flag is set, we need to clear the lines that have been
8743 * scrolled up at the bottom of the region.
8745 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8747 for (i
= line_count
; i
> 0; --i
)
8749 windgoto(cursor_end
- i
, 0);
8750 out_str(T_CE
); /* erase a line */
8751 screen_start(); /* don't know where cursor is now */
8756 gui_can_update_cursor();
8758 out_flush(); /* always flush after a scroll */
8765 * show the current mode and ruler
8767 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8768 * If clear_cmdline is FALSE there may be a message there that needs to be
8769 * cleared only if a mode is shown.
8770 * Return the length of the message (0 if no message).
8780 #ifdef FEAT_INS_EXPAND
8784 do_mode
= ((p_smd
&& msg_silent
== 0)
8785 && ((State
& INSERT
)
8791 if (do_mode
|| Recording
)
8794 * Don't show mode right now, when not redrawing or inside a mapping.
8795 * Call char_avail() only when we are going to show something, because
8796 * it takes a bit of time.
8798 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
8800 redraw_cmdline
= TRUE
; /* show mode later */
8804 nwr_save
= need_wait_return
;
8806 /* wait a bit before overwriting an important message */
8807 check_for_delay(FALSE
);
8809 /* if the cmdline is more than one line high, erase top lines */
8810 need_clear
= clear_cmdline
;
8811 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
8812 msg_clr_cmdline(); /* will reset clear_cmdline */
8814 /* Position on the last line in the window, column 0 */
8817 attr
= hl_attr(HLF_CM
); /* Highlight mode */
8820 MSG_PUTS_ATTR("--", attr
);
8821 #if defined(FEAT_XIM)
8822 if (xic
!= NULL
&& im_get_status() && !p_imdisable
8823 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
8824 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
8825 MSG_PUTS_ATTR(" IM", attr
);
8827 MSG_PUTS_ATTR(" XIM", attr
);
8830 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
8833 if (hangul_input_state_get())
8834 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
8837 #ifdef FEAT_INS_EXPAND
8838 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
8840 /* These messages can get long, avoid a wrap in a narrow
8841 * window. Prefer showing edit_submode_extra. */
8842 length
= (Rows
- msg_row
) * Columns
- 3;
8843 if (edit_submode_extra
!= NULL
)
8844 length
-= vim_strsize(edit_submode_extra
);
8847 if (edit_submode_pre
!= NULL
)
8848 length
-= vim_strsize(edit_submode_pre
);
8849 if (length
- vim_strsize(edit_submode
) > 0)
8851 if (edit_submode_pre
!= NULL
)
8852 msg_puts_attr(edit_submode_pre
, attr
);
8853 msg_puts_attr(edit_submode
, attr
);
8855 if (edit_submode_extra
!= NULL
)
8857 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
8858 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
8859 sub_attr
= hl_attr(edit_submode_highl
);
8862 msg_puts_attr(edit_submode_extra
, sub_attr
);
8870 #ifdef FEAT_VREPLACE
8871 if (State
& VREPLACE_FLAG
)
8872 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
8875 if (State
& REPLACE_FLAG
)
8876 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
8877 else if (State
& INSERT
)
8879 #ifdef FEAT_RIGHTLEFT
8881 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
8883 MSG_PUTS_ATTR(_(" INSERT"), attr
);
8885 else if (restart_edit
== 'I')
8886 MSG_PUTS_ATTR(_(" (insert)"), attr
);
8887 else if (restart_edit
== 'R')
8888 MSG_PUTS_ATTR(_(" (replace)"), attr
);
8889 else if (restart_edit
== 'V')
8890 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
8891 #ifdef FEAT_RIGHTLEFT
8893 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
8896 MSG_PUTS_ATTR(farsi_text_5
, attr
);
8900 if (State
& LANGMAP
)
8903 if (curwin
->w_p_arab
)
8904 MSG_PUTS_ATTR(_(" Arabic"), attr
);
8907 MSG_PUTS_ATTR(_(" (lang)"), attr
);
8910 if ((State
& INSERT
) && p_paste
)
8911 MSG_PUTS_ATTR(_(" (paste)"), attr
);
8918 /* Don't concatenate separate words to avoid translation
8920 switch ((VIsual_select
? 4 : 0)
8921 + (VIsual_mode
== Ctrl_V
) * 2
8922 + (VIsual_mode
== 'V'))
8924 case 0: p
= N_(" VISUAL"); break;
8925 case 1: p
= N_(" VISUAL LINE"); break;
8926 case 2: p
= N_(" VISUAL BLOCK"); break;
8927 case 4: p
= N_(" SELECT"); break;
8928 case 5: p
= N_(" SELECT LINE"); break;
8929 default: p
= N_(" SELECT BLOCK"); break;
8931 MSG_PUTS_ATTR(_(p
), attr
);
8934 MSG_PUTS_ATTR(" --", attr
);
8940 #ifdef FEAT_INS_EXPAND
8941 && edit_submode
== NULL
/* otherwise it gets too long */
8945 MSG_PUTS_ATTR(_("recording"), attr
);
8949 mode_displayed
= TRUE
;
8950 if (need_clear
|| clear_cmdline
)
8952 msg_didout
= FALSE
; /* overwrite this message */
8955 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
8957 else if (clear_cmdline
&& msg_silent
== 0)
8958 /* Clear the whole command line. Will reset "clear_cmdline". */
8961 #ifdef FEAT_CMDL_INFO
8963 /* In Visual mode the size of the selected area must be redrawn. */
8968 /* If the last window has no status line, the ruler is after the mode
8969 * message and must be redrawn */
8971 # ifdef FEAT_WINDOWS
8972 && lastwin
->w_status_height
== 0
8975 win_redr_ruler(lastwin
, TRUE
);
8977 redraw_cmdline
= FALSE
;
8978 clear_cmdline
= FALSE
;
8984 * Position for a mode message.
8994 * Delete mode message. Used when ESC is typed which is expected to end
8995 * Insert mode (but Insert mode didn't end yet!).
8996 * Caller should check "mode_displayed".
9003 * Don't delete it right now, when not redrawing or insided a mapping.
9005 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
9006 redraw_cmdline
= TRUE
; /* delete mode later */
9011 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
9016 #if defined(FEAT_WINDOWS)
9018 * Draw the tab pages line at the top of the Vim window.
9035 int attr_sel
= hl_attr(HLF_TPS
);
9036 int attr_nosel
= hl_attr(HLF_TP
);
9037 int attr_fill
= hl_attr(HLF_TPF
);
9040 int use_sep_chars
= (t_colors
< 8
9046 redraw_tabline
= FALSE
;
9048 #ifdef FEAT_GUI_TABLINE
9049 /* Take care of a GUI tabline. */
9050 if (gui_use_tabline())
9052 gui_update_tabline();
9057 if (tabline_height() < 1)
9060 #if defined(FEAT_STL_OPT)
9062 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9063 for (scol
= 0; scol
< Columns
; ++scol
)
9064 TabPageIdxs
[scol
] = 0;
9066 /* Use the 'tabline' option if it's set. */
9069 int save_called_emsg
= called_emsg
;
9071 /* Check for an error. If there is one we would loop in redrawing the
9072 * screen. Avoid that by making 'tabline' empty. */
9073 called_emsg
= FALSE
;
9074 win_redr_custom(NULL
, FALSE
);
9076 set_string_option_direct((char_u
*)"tabline", -1,
9077 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9078 called_emsg
|= save_called_emsg
;
9083 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
9086 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
9093 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
9098 if (tp
->tp_topframe
== topframe
)
9100 if (use_sep_chars
&& col
> 0)
9101 screen_putchar('|', 0, col
++, attr
);
9103 if (tp
->tp_topframe
!= topframe
)
9106 screen_putchar(' ', 0, col
++, attr
);
9115 cwp
= tp
->tp_curwin
;
9116 wp
= tp
->tp_firstwin
;
9120 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
9121 if (bufIsChanged(wp
->w_buffer
))
9123 if (modified
|| wincount
> 1)
9127 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
9128 len
= (int)STRLEN(NameBuff
);
9129 if (col
+ len
>= Columns
- 3)
9131 screen_puts_len(NameBuff
, len
, 0, col
,
9132 #if defined(FEAT_SYN_HL)
9133 hl_combine_attr(attr
, hl_attr(HLF_T
))
9141 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
9142 screen_putchar(' ', 0, col
++, attr
);
9145 room
= scol
- col
+ tabwidth
- 1;
9148 /* Get buffer name in NameBuff[] */
9149 get_trans_bufname(cwp
->w_buffer
);
9150 shorten_dir(NameBuff
);
9151 len
= vim_strsize(NameBuff
);
9157 len
-= ptr2cells(p
);
9167 if (len
> Columns
- col
- 1)
9168 len
= Columns
- col
- 1;
9170 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9173 screen_putchar(' ', 0, col
++, attr
);
9175 /* Store the tab page number in TabPageIdxs[], so that
9176 * jump_to_mouse() knows where each one is. */
9179 TabPageIdxs
[scol
++] = tabcount
;
9186 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9188 /* Put an "X" for closing the current tab if there are several. */
9189 if (first_tabpage
->tp_next
!= NULL
)
9191 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9192 TabPageIdxs
[Columns
- 1] = -999;
9196 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9198 redraw_tabline
= FALSE
;
9202 * Get buffer name for "buf" into NameBuff[].
9203 * Takes care of special buffer names and translates special characters.
9206 get_trans_bufname(buf
)
9209 if (buf_spname(buf
) != NULL
)
9210 STRCPY(NameBuff
, buf_spname(buf
));
9212 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9213 trans_characters(NameBuff
, MAXPATHL
);
9217 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9219 * Get the character to use in a status line. Get its attributes in "*attr".
9222 fillchar_status(attr
, is_curwin
)
9229 *attr
= hl_attr(HLF_S
);
9234 *attr
= hl_attr(HLF_SNC
);
9237 /* Use fill when there is highlighting, and highlighting of current
9238 * window differs, or the fillchars differ, or this is not the
9240 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9241 || !is_curwin
|| firstwin
== lastwin
)
9242 || (fill_stl
!= fill_stlnc
)))
9250 #ifdef FEAT_VERTSPLIT
9252 * Get the character to use in a separator between vertically split windows.
9253 * Get its attributes in "*attr".
9259 *attr
= hl_attr(HLF_C
);
9260 if (*attr
== 0 && fill_vert
== ' ')
9268 * Return TRUE if redrawing should currently be done.
9273 return (!RedrawingDisabled
9274 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9278 * Return TRUE if printing messages should currently be done.
9283 return (!(p_lz
&& char_avail() && !KeyTyped
));
9287 * Show current status info in ruler and various other places
9288 * If always is FALSE, only show ruler if position has changed.
9294 if (!always
&& !redrawing())
9296 #ifdef FEAT_INS_EXPAND
9299 # ifdef FEAT_WINDOWS
9300 /* Don't redraw right now, do it later. */
9301 curwin
->w_redr_status
= TRUE
;
9306 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9307 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9309 redraw_custum_statusline(curwin
);
9313 #ifdef FEAT_CMDL_INFO
9314 win_redr_ruler(curwin
, always
);
9319 # ifdef FEAT_STL_OPT
9320 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9321 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9328 #ifdef FEAT_CMDL_INFO
9330 win_redr_ruler(wp
, always
)
9338 int empty_line
= FALSE
;
9342 #ifdef FEAT_VERTSPLIT
9345 int width
= Columns
;
9346 # define WITH_OFF(x) x
9347 # define WITH_WIDTH(x) x
9349 # define WITH_OFF(x) 0
9350 # define WITH_WIDTH(x) Columns
9351 # define this_ru_col ru_col
9354 /* If 'ruler' off or redrawing disabled, don't do anything */
9359 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9360 * after deleting lines, before cursor.lnum is corrected.
9362 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9365 #ifdef FEAT_INS_EXPAND
9366 /* Don't draw the ruler while doing insert-completion, it might overwrite
9367 * the (long) mode message. */
9368 # ifdef FEAT_WINDOWS
9369 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9371 if (edit_submode
!= NULL
)
9373 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9381 int save_called_emsg
= called_emsg
;
9383 called_emsg
= FALSE
;
9384 win_redr_custom(wp
, TRUE
);
9386 set_string_option_direct((char_u
*)"rulerformat", -1,
9387 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9388 called_emsg
|= save_called_emsg
;
9394 * Check if not in Insert mode and the line is empty (will show "0-1").
9396 if (!(State
& INSERT
)
9397 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9401 * Only draw the ruler when something changed.
9403 validate_virtcol_win(wp
);
9406 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9407 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9408 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9409 #ifdef FEAT_VIRTUALEDIT
9410 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9412 || wp
->w_topline
!= wp
->w_ru_topline
9413 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9415 || wp
->w_topfill
!= wp
->w_ru_topfill
9417 || empty_line
!= wp
->w_ru_empty
)
9421 if (wp
->w_status_height
)
9423 row
= W_WINROW(wp
) + wp
->w_height
;
9424 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9425 # ifdef FEAT_VERTSPLIT
9427 width
= W_WIDTH(wp
);
9436 #ifdef FEAT_VERTSPLIT
9442 /* In list mode virtcol needs to be recomputed */
9443 virtcol
= wp
->w_virtcol
;
9444 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9446 wp
->w_p_list
= FALSE
;
9447 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9448 wp
->w_p_list
= TRUE
;
9452 * Some sprintfs return the length, some return a pointer.
9453 * To avoid portability problems we use strlen() here.
9455 sprintf((char *)buffer
, "%ld,",
9456 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9458 : (long)(wp
->w_cursor
.lnum
));
9459 col_print(buffer
+ STRLEN(buffer
),
9460 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9464 * Add a "50%" if there is room for it.
9465 * On the last line, don't print in the last column (scrolls the
9466 * screen up on some terminals).
9468 i
= (int)STRLEN(buffer
);
9469 get_rel_pos(wp
, buffer
+ i
+ 1);
9470 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9472 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9475 #ifdef FEAT_VERTSPLIT
9476 this_ru_col
= ru_col
- (Columns
- width
);
9477 if (this_ru_col
< 0)
9480 /* Never use more than half the window/screen width, leave the other
9481 * half for the filename. */
9482 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9483 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9484 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9486 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9490 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9493 buffer
[i
++] = fillchar
;
9496 get_rel_pos(wp
, buffer
+ i
);
9498 /* Truncate at window boundary. */
9503 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9505 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9506 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9515 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9516 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9518 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9520 screen_fill(row
, row
+ 1,
9521 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9522 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9523 fillchar
, fillchar
, attr
);
9524 /* don't redraw the cmdline because of showing the ruler */
9526 wp
->w_ru_cursor
= wp
->w_cursor
;
9527 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9528 wp
->w_ru_empty
= empty_line
;
9529 wp
->w_ru_topline
= wp
->w_topline
;
9530 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9532 wp
->w_ru_topfill
= wp
->w_topfill
;
9538 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9540 * Return the width of the 'number' column.
9541 * Caller may need to check if 'number' is set.
9542 * Otherwise it depends on 'numberwidth' and the line count.
9551 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9552 if (lnum
== wp
->w_nrwidth_line_count
)
9553 return wp
->w_nrwidth_width
;
9554 wp
->w_nrwidth_line_count
= lnum
;
9563 /* 'numberwidth' gives the minimal width plus one */
9564 if (n
< wp
->w_p_nuw
- 1)
9565 n
= wp
->w_p_nuw
- 1;
9567 wp
->w_nrwidth_width
= n
;