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_custom_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.
274 redrawWinline(lnum
, invalid
)
276 int invalid UNUSED
; /* window line height is invalid now */
282 if (curwin
->w_redraw_top
== 0 || curwin
->w_redraw_top
> lnum
)
283 curwin
->w_redraw_top
= lnum
;
284 if (curwin
->w_redraw_bot
== 0 || curwin
->w_redraw_bot
< lnum
)
285 curwin
->w_redraw_bot
= lnum
;
291 /* A w_lines[] entry for this lnum has become invalid. */
292 i
= find_wl_entry(curwin
, lnum
);
294 curwin
->w_lines
[i
].wl_valid
= FALSE
;
300 * update all windows that are editing the current buffer
306 redraw_curbuf_later(type
);
313 * Based on the current value of curwin->w_topline, transfer a screenfull
314 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
321 static int did_intro
= FALSE
;
322 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
326 if (!screen_valid(TRUE
))
331 if (type
< must_redraw
) /* use maximal type */
334 /* must_redraw is reset here, so that when we run into some weird
335 * reason to redraw while busy redrawing (e.g., asynchronous
336 * scrolling), or update_topline() in win_update() will cause a
337 * scroll, the screen will be redrawn later or in win_update(). */
341 /* Need to update w_lines[]. */
342 if (curwin
->w_lines_valid
== 0 && type
< NOT_VALID
)
347 redraw_later(type
); /* remember type for next time */
349 if (type
> INVERTED_ALL
)
350 curwin
->w_lines_valid
= 0; /* don't use w_lines[].wl_size now */
354 updating_screen
= TRUE
;
356 ++display_tick
; /* let syntax code know we're in a next round of
357 * display updating */
361 * if the screen was scrolled up when displaying a message, scroll it down
365 clear_cmdline
= TRUE
;
366 if (msg_scrolled
> Rows
- 5) /* clearing is faster */
368 else if (type
!= CLEAR
)
370 check_for_delay(FALSE
);
371 if (screen_ins_lines(0, 0, msg_scrolled
, (int)Rows
, NULL
) == FAIL
)
375 if (W_WINROW(wp
) < msg_scrolled
)
377 if (W_WINROW(wp
) + wp
->w_height
> msg_scrolled
378 && wp
->w_redr_type
< REDRAW_TOP
379 && wp
->w_lines_valid
> 0
380 && wp
->w_topline
== wp
->w_lines
[0].wl_lnum
)
382 wp
->w_upd_rows
= msg_scrolled
- W_WINROW(wp
);
383 wp
->w_redr_type
= REDRAW_TOP
;
387 wp
->w_redr_type
= NOT_VALID
;
389 if (W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
)
391 wp
->w_redr_status
= TRUE
;
396 redraw_cmdline
= TRUE
;
398 redraw_tabline
= TRUE
;
402 need_wait_return
= FALSE
;
405 /* reset cmdline_row now (may have been changed temporarily) */
408 /* Check for changed highlighting */
409 if (need_highlight_changed
)
412 if (type
== CLEAR
) /* first clear screen */
414 screenclear(); /* will reset clear_cmdline */
418 if (clear_cmdline
) /* going to clear cmdline (done below) */
419 check_for_delay(FALSE
);
421 #ifdef FEAT_LINEBREAK
422 /* Force redraw when width of 'number' column changes. */
423 if (curwin
->w_redr_type
< NOT_VALID
424 && curwin
->w_nrwidth
!= (curwin
->w_p_nu
? number_width(curwin
) : 0))
425 curwin
->w_redr_type
= NOT_VALID
;
429 * Only start redrawing if there is really something to do.
431 if (type
== INVERTED
)
433 if (curwin
->w_redr_type
< type
435 && curwin
->w_lines
[0].wl_valid
437 && curwin
->w_topfill
== curwin
->w_old_topfill
438 && curwin
->w_botfill
== curwin
->w_old_botfill
440 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
444 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
445 && curwin
->w_old_visual_mode
== VIsual_mode
446 && (curwin
->w_valid
& VALID_VIRTCOL
)
447 && curwin
->w_old_curswant
== curwin
->w_curswant
)
450 curwin
->w_redr_type
= type
;
453 /* Redraw the tab pages line if needed. */
454 if (redraw_tabline
|| type
>= NOT_VALID
)
460 * Correct stored syntax highlighting info for changes in each displayed
461 * buffer. Each buffer must only be done once.
465 if (wp
->w_buffer
->b_mod_set
)
470 /* Check if we already did this buffer. */
471 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
472 if (wwp
->w_buffer
== wp
->w_buffer
)
479 syntax_present(wp
->w_buffer
))
480 syn_stack_apply_changes(wp
->w_buffer
);
486 * Go from top to bottom through the windows, redrawing the ones that need
489 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
492 #ifdef FEAT_SEARCH_EXTRA
493 search_hl
.rm
.regprog
= NULL
;
497 if (wp
->w_redr_type
!= 0)
500 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
504 # ifdef FEAT_SEARCH_EXTRA
507 # ifdef FEAT_CLIPBOARD
508 /* When Visual area changed, may have to update selection. */
509 if (clip_star
.available
&& clip_isautosel())
510 clip_update_selection();
513 /* Remove the cursor before starting to do anything, because
514 * scrolling may make it difficult to redraw the text under
525 /* redraw status line after the window to minimize cursor movement */
526 if (wp
->w_redr_status
)
533 #if defined(FEAT_SEARCH_EXTRA)
538 /* Reset b_mod_set flags. Going through all windows is probably faster
539 * than going through all buffers (there could be many buffers). */
540 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
541 wp
->w_buffer
->b_mod_set
= FALSE
;
543 curbuf
->b_mod_set
= FALSE
;
546 updating_screen
= FALSE
;
548 gui_may_resize_shell();
551 /* Clear or redraw the command line. Done last, because scrolling may
552 * mess up the command line. */
553 if (clear_cmdline
|| redraw_cmdline
)
556 /* May put up an introductory message when not editing a file */
557 if (!did_intro
&& bufempty()
558 && curbuf
->b_fname
== NULL
560 && firstwin
->w_next
== NULL
562 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
563 intro_message(FALSE
);
567 /* Redraw the cursor and update the scrollbars when all screen updating is
571 out_flush(); /* required before updating the cursor */
573 gui_update_cursor(FALSE
, FALSE
);
574 gui_update_scrollbars(FALSE
);
579 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
580 static void update_prepare
__ARGS((void));
581 static void update_finish
__ARGS((void));
584 * Prepare for updating one or more windows.
590 updating_screen
= TRUE
;
592 /* Remove the cursor before starting to do anything, because scrolling may
593 * make it difficult to redraw the text under it. */
597 #ifdef FEAT_SEARCH_EXTRA
603 * Finish updating one or more windows.
611 # ifdef FEAT_SEARCH_EXTRA
615 updating_screen
= FALSE
;
618 gui_may_resize_shell();
620 /* Redraw the cursor and update the scrollbars when all screen updating is
624 out_flush(); /* required before updating the cursor */
625 gui_update_cursor(FALSE
, FALSE
);
626 gui_update_scrollbars(FALSE
);
632 #if defined(FEAT_SIGNS) || defined(PROTO)
634 update_debug_sign(buf
, lnum
)
642 win_foldinfo
.fi_level
= 0;
645 /* update/delete a specific mark */
648 if (buf
!= NULL
&& lnum
> 0)
650 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
651 && lnum
< wp
->w_botline
)
653 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
654 wp
->w_redraw_top
= lnum
;
655 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
656 wp
->w_redraw_bot
= lnum
;
657 redraw_win_later(wp
, VALID
);
661 redraw_win_later(wp
, VALID
);
662 if (wp
->w_redr_type
!= 0)
669 /* update all windows that need updating */
673 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
675 if (wp
->w_redr_type
!= 0)
677 if (wp
->w_redr_status
)
681 if (curwin
->w_redr_type
!= 0)
690 #if defined(FEAT_GUI) || defined(PROTO)
692 * Update a single window, its status line and maybe the command line msg.
693 * Used for the GUI scrollbar.
701 #ifdef FEAT_CLIPBOARD
702 /* When Visual area changed, may have to update selection. */
703 if (clip_star
.available
&& clip_isautosel())
704 clip_update_selection();
710 /* When the screen was cleared redraw the tab pages line. */
714 if (wp
->w_redr_status
715 # ifdef FEAT_CMDL_INFO
719 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
730 * Update a single window.
732 * This may cause the windows below it also to be redrawn (when clearing the
733 * screen or scrolling lines).
735 * How the window is redrawn depends on wp->w_redr_type. Each type also
736 * implies the one below it.
737 * NOT_VALID redraw the whole window
738 * SOME_VALID redraw the whole window but do scroll when possible
739 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
740 * INVERTED redraw the changed part of the Visual area
741 * INVERTED_ALL redraw the whole Visual area
742 * VALID 1. scroll up/down to adjust for a changed w_topline
743 * 2. update lines at the top when scrolled down
744 * 3. redraw changed text:
745 * - if wp->w_buffer->b_mod_set set, update lines between
746 * b_mod_top and b_mod_bot.
747 * - if wp->w_redraw_top non-zero, redraw lines between
748 * wp->w_redraw_top and wp->w_redr_bot.
749 * - continue redrawing when syntax status is invalid.
750 * 4. if scrolled up, update lines at the bottom.
751 * This results in three areas that may need updating:
752 * top: from first row to top_end (when scrolled down)
753 * mid: from mid_start to mid_end (update inversion or changed text)
754 * bot: from bot_start to last row (when scrolled up)
760 buf_T
*buf
= wp
->w_buffer
;
762 int top_end
= 0; /* Below last row of the top area that needs
763 updating. 0 when no top area updating. */
764 int mid_start
= 999;/* first row of the mid area that needs
765 updating. 999 when no mid area updating. */
766 int mid_end
= 0; /* Below last row of the mid area that needs
767 updating. 0 when no mid area updating. */
768 int bot_start
= 999;/* first row of the bot area that needs
769 updating. 999 when no bot area updating */
771 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
772 w_topline got smaller a bit */
774 #ifdef FEAT_SEARCH_EXTRA
775 matchitem_T
*cur
; /* points to the match list */
776 int top_to_mod
= FALSE
; /* redraw above mod_top */
779 int row
; /* current window row to display */
780 linenr_T lnum
; /* current buffer lnum to display */
781 int idx
; /* current index in w_lines[] */
782 int srow
; /* starting row of the current line */
784 int eof
= FALSE
; /* if TRUE, we hit the end of the file */
785 int didline
= FALSE
; /* if TRUE, we finished the last line */
788 static int recursive
= FALSE
; /* being called recursively */
789 int old_botline
= wp
->w_botline
;
794 /* remember what happened to the previous line, to know if
795 * check_visual_highlight() can be used */
796 #define DID_NONE 1 /* didn't update a line */
797 #define DID_LINE 2 /* updated a normal line */
798 #define DID_FOLD 3 /* updated a folded line */
799 int did_update
= DID_NONE
;
800 linenr_T syntax_last_parsed
= 0; /* last parsed text line */
802 linenr_T mod_top
= 0;
803 linenr_T mod_bot
= 0;
804 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
808 type
= wp
->w_redr_type
;
810 if (type
== NOT_VALID
)
813 wp
->w_redr_status
= TRUE
;
815 wp
->w_lines_valid
= 0;
818 /* Window is zero-height: nothing to draw. */
819 if (wp
->w_height
== 0)
825 #ifdef FEAT_VERTSPLIT
826 /* Window is zero-width: Only need to draw the separator. */
827 if (wp
->w_width
== 0)
829 /* draw the vertical separator right of this window */
830 draw_vsep_win(wp
, 0);
836 #ifdef FEAT_SEARCH_EXTRA
837 /* Setup for match and 'hlsearch' highlighting. Disable any previous
839 cur
= wp
->w_match_head
;
842 cur
->hl
.rm
= cur
->match
;
843 if (cur
->hlg_id
== 0)
846 cur
->hl
.attr
= syn_id2attr(cur
->hlg_id
);
849 cur
->hl
.first_lnum
= 0;
851 /* Set the time limit to 'redrawtime'. */
852 profile_setlimit(p_rdt
, &(cur
->hl
.tm
));
858 search_hl
.first_lnum
= 0;
859 /* time limit is set at the toplevel, for all windows */
862 #ifdef FEAT_LINEBREAK
863 /* Force redraw when width of 'number' column changes. */
864 i
= wp
->w_p_nu
? number_width(wp
) : 0;
865 if (wp
->w_nrwidth
!= i
)
873 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
876 * When there are both inserted/deleted lines and specific lines to be
877 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
878 * everything (only happens when redrawing is off for while).
885 * Set mod_top to the first line that needs displaying because of
886 * changes. Set mod_bot to the first line after the changes.
888 mod_top
= wp
->w_redraw_top
;
889 if (wp
->w_redraw_bot
!= 0)
890 mod_bot
= wp
->w_redraw_bot
+ 1;
893 wp
->w_redraw_top
= 0; /* reset for next time */
894 wp
->w_redraw_bot
= 0;
897 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
899 mod_top
= buf
->b_mod_top
;
901 /* Need to redraw lines above the change that may be included
902 * in a pattern match. */
903 if (syntax_present(buf
))
905 mod_top
-= buf
->b_syn_sync_linebreaks
;
911 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
912 mod_bot
= buf
->b_mod_bot
;
914 #ifdef FEAT_SEARCH_EXTRA
915 /* When 'hlsearch' is on and using a multi-line search pattern, a
916 * change in one line may make the Search highlighting in a
917 * previous line invalid. Simple solution: redraw all visible
918 * lines above the change.
919 * Same for a match pattern.
921 if (search_hl
.rm
.regprog
!= NULL
922 && re_multiline(search_hl
.rm
.regprog
))
926 cur
= wp
->w_match_head
;
929 if (cur
->match
.regprog
!= NULL
930 && re_multiline(cur
->match
.regprog
))
941 if (mod_top
!= 0 && hasAnyFolding(wp
))
943 linenr_T lnumt
, lnumb
;
946 * A change in a line can cause lines above it to become folded or
947 * unfolded. Find the top most buffer line that may be affected.
948 * If the line was previously folded and displayed, get the first
949 * line of that fold. If the line is folded now, get the first
950 * folded line. Use the minimum of these two.
953 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
954 * the line below it. If there is no valid entry, use w_topline.
955 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
956 * to this line. If there is no valid entry, use MAXLNUM. */
957 lnumt
= wp
->w_topline
;
959 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
960 if (wp
->w_lines
[i
].wl_valid
)
962 if (wp
->w_lines
[i
].wl_lastlnum
< mod_top
)
963 lnumt
= wp
->w_lines
[i
].wl_lastlnum
+ 1;
964 if (lnumb
== MAXLNUM
&& wp
->w_lines
[i
].wl_lnum
>= mod_bot
)
966 lnumb
= wp
->w_lines
[i
].wl_lnum
;
967 /* When there is a fold column it might need updating
968 * in the next line ("J" just above an open fold). */
974 (void)hasFoldingWin(wp
, mod_top
, &mod_top
, NULL
, TRUE
, NULL
);
978 /* Now do the same for the bottom line (one above mod_bot). */
980 (void)hasFoldingWin(wp
, mod_bot
, NULL
, &mod_bot
, TRUE
, NULL
);
987 /* When a change starts above w_topline and the end is below
988 * w_topline, start redrawing at w_topline.
989 * If the end of the change is above w_topline: do like no change was
990 * made, but redraw the first line to find changes in syntax. */
991 if (mod_top
!= 0 && mod_top
< wp
->w_topline
)
993 if (mod_bot
> wp
->w_topline
)
994 mod_top
= wp
->w_topline
;
996 else if (syntax_present(buf
))
1001 /* When line numbers are displayed need to redraw all lines below
1002 * inserted/deleted lines. */
1003 if (mod_top
!= 0 && buf
->b_mod_xlines
!= 0 && wp
->w_p_nu
)
1008 * When only displaying the lines at the top, set top_end. Used when
1009 * window has scrolled down for msg_scrolled.
1011 if (type
== REDRAW_TOP
)
1014 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
1016 j
+= wp
->w_lines
[i
].wl_size
;
1017 if (j
>= wp
->w_upd_rows
)
1024 /* not found (cannot happen?): redraw everything */
1027 /* top area defined, the rest is VALID */
1031 /* Trick: we want to avoid clearing the screen twice. screenclear() will
1032 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1033 * non-zero and thus not FALSE) will indicate that screenclear() was not
1036 screen_cleared
= MAYBE
;
1039 * If there are no changes on the screen that require a complete redraw,
1040 * handle three cases:
1041 * 1: we are off the top of the screen by a few lines: scroll down
1042 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1043 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1044 * w_lines[] that needs updating.
1046 if ((type
== VALID
|| type
== SOME_VALID
1047 || type
== INVERTED
|| type
== INVERTED_ALL
)
1049 && !wp
->w_botfill
&& !wp
->w_old_botfill
1053 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1056 * w_topline is the first changed line, the scrolling will be done
1060 else if (wp
->w_lines
[0].wl_valid
1061 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1063 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1064 && wp
->w_topfill
> wp
->w_old_topfill
)
1069 * New topline is above old topline: May scroll down.
1072 if (hasAnyFolding(wp
))
1076 /* count the number of lines we are off, counting a sequence
1077 * of folded lines as one */
1079 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1082 if (j
>= wp
->w_height
- 2)
1084 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1089 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1090 if (j
< wp
->w_height
- 2) /* not too far off */
1092 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1094 /* insert extra lines for previously invisible filler lines */
1095 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1096 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1097 - wp
->w_old_topfill
;
1099 if (i
< wp
->w_height
- 2) /* less than a screen off */
1102 * Try to insert the correct number of lines.
1103 * If not the last window, delete the lines at the bottom.
1104 * win_ins_lines may fail when the terminal can't do it.
1107 check_for_delay(FALSE
);
1108 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1110 if (wp
->w_lines_valid
!= 0)
1112 /* Need to update rows that are new, stop at the
1113 * first one that scrolled down. */
1116 scrolled_down
= TRUE
;
1119 /* Move the entries that were scrolled, disable
1120 * the entries for the lines to be redrawn. */
1121 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1122 wp
->w_lines_valid
= wp
->w_height
;
1123 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1124 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1126 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1130 mid_start
= 0; /* redraw all lines */
1133 mid_start
= 0; /* redraw all lines */
1136 mid_start
= 0; /* redraw all lines */
1141 * New topline is at or below old topline: May scroll up.
1142 * When topline didn't change, find first entry in w_lines[] that
1146 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1149 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1151 if (wp
->w_lines
[i
].wl_valid
1152 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1157 row
+= wp
->w_lines
[i
].wl_size
;
1161 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1168 * Try to delete the correct number of lines.
1169 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1172 /* If the topline didn't change, delete old filler lines,
1173 * otherwise delete filler lines of the new topline... */
1174 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1175 row
+= wp
->w_old_topfill
;
1177 row
+= diff_check_fill(wp
, wp
->w_topline
);
1178 /* ... but don't delete new filler lines. */
1179 row
-= wp
->w_topfill
;
1183 check_for_delay(FALSE
);
1184 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1185 bot_start
= wp
->w_height
- row
;
1187 mid_start
= 0; /* redraw all lines */
1189 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1192 * Skip the lines (below the deleted lines) that are still
1193 * valid and don't need redrawing. Copy their info
1194 * upwards, to compensate for the deleted lines. Set
1195 * bot_start to the first row that needs redrawing.
1201 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1202 /* stop at line that didn't fit, unless it is still
1203 * valid (no lines deleted) */
1204 if (row
> 0 && bot_start
+ row
1205 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1207 wp
->w_lines_valid
= idx
+ 1;
1210 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1212 /* stop at the last valid entry in w_lines[].wl_size */
1213 if (++j
>= wp
->w_lines_valid
)
1215 wp
->w_lines_valid
= idx
;
1220 /* Correct the first entry for filler lines at the top
1221 * when it won't get updated below. */
1222 if (wp
->w_p_diff
&& bot_start
> 0)
1223 wp
->w_lines
[0].wl_size
=
1224 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1231 /* When starting redraw in the first line, redraw all lines. When
1232 * there is only one window it's probably faster to clear the screen
1236 mid_end
= wp
->w_height
;
1237 if (lastwin
== firstwin
)
1239 /* Clear the screen when it was not done by win_del_lines() or
1240 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1242 if (screen_cleared
!= TRUE
)
1245 /* The screen was cleared, redraw the tab pages line. */
1252 /* When win_del_lines() or win_ins_lines() caused the screen to be
1253 * cleared (only happens for the first window) or when screenclear()
1254 * was called directly above, "must_redraw" will have been set to
1255 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1256 if (screen_cleared
== TRUE
)
1261 /* Not VALID or INVERTED: redraw all lines. */
1263 mid_end
= wp
->w_height
;
1266 if (type
== SOME_VALID
)
1268 /* SOME_VALID: redraw all lines. */
1270 mid_end
= wp
->w_height
;
1275 /* check if we are updating or removing the inverted part */
1276 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1277 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1284 && (VIsual_mode
!= wp
->w_old_visual_mode
1285 || type
== INVERTED_ALL
))
1288 * If the type of Visual selection changed, redraw the whole
1289 * selection. Also when the ownership of the X selection is
1292 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1294 from
= curwin
->w_cursor
.lnum
;
1300 to
= curwin
->w_cursor
.lnum
;
1302 /* redraw more when the cursor moved as well */
1303 if (wp
->w_old_cursor_lnum
< from
)
1304 from
= wp
->w_old_cursor_lnum
;
1305 if (wp
->w_old_cursor_lnum
> to
)
1306 to
= wp
->w_old_cursor_lnum
;
1307 if (wp
->w_old_visual_lnum
< from
)
1308 from
= wp
->w_old_visual_lnum
;
1309 if (wp
->w_old_visual_lnum
> to
)
1310 to
= wp
->w_old_visual_lnum
;
1315 * Find the line numbers that need to be updated: The lines
1316 * between the old cursor position and the current cursor
1317 * position. Also check if the Visual position changed.
1319 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1321 from
= curwin
->w_cursor
.lnum
;
1322 to
= wp
->w_old_cursor_lnum
;
1326 from
= wp
->w_old_cursor_lnum
;
1327 to
= curwin
->w_cursor
.lnum
;
1328 if (from
== 0) /* Visual mode just started */
1332 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1333 || VIsual
.col
!= wp
->w_old_visual_col
)
1335 if (wp
->w_old_visual_lnum
< from
1336 && wp
->w_old_visual_lnum
!= 0)
1337 from
= wp
->w_old_visual_lnum
;
1338 if (wp
->w_old_visual_lnum
> to
)
1339 to
= wp
->w_old_visual_lnum
;
1340 if (VIsual
.lnum
< from
)
1342 if (VIsual
.lnum
> to
)
1348 * If in block mode and changed column or curwin->w_curswant:
1350 * First compute the actual start and end column.
1352 if (VIsual_mode
== Ctrl_V
)
1356 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1358 if (curwin
->w_curswant
== MAXCOL
)
1361 if (fromc
!= wp
->w_old_cursor_fcol
1362 || toc
!= wp
->w_old_cursor_lcol
)
1364 if (from
> VIsual
.lnum
)
1366 if (to
< VIsual
.lnum
)
1369 wp
->w_old_cursor_fcol
= fromc
;
1370 wp
->w_old_cursor_lcol
= toc
;
1375 /* Use the line numbers of the old Visual area. */
1376 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1378 from
= wp
->w_old_cursor_lnum
;
1379 to
= wp
->w_old_visual_lnum
;
1383 from
= wp
->w_old_visual_lnum
;
1384 to
= wp
->w_old_cursor_lnum
;
1389 * There is no need to update lines above the top of the window.
1391 if (from
< wp
->w_topline
)
1392 from
= wp
->w_topline
;
1395 * If we know the value of w_botline, use it to restrict the update to
1396 * the lines that are visible in the window.
1398 if (wp
->w_valid
& VALID_BOTLINE
)
1400 if (from
>= wp
->w_botline
)
1401 from
= wp
->w_botline
- 1;
1402 if (to
>= wp
->w_botline
)
1403 to
= wp
->w_botline
- 1;
1407 * Find the minimal part to be updated.
1408 * Watch out for scrolling that made entries in w_lines[] invalid.
1409 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1410 * top_end; need to redraw from top_end to the "to" line.
1411 * A middle mouse click with a Visual selection may change the text
1412 * above the Visual area and reset wl_valid, do count these for
1413 * mid_end (in srow).
1417 lnum
= wp
->w_topline
;
1421 mid_start
= top_end
;
1424 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1426 if (wp
->w_lines
[idx
].wl_valid
)
1427 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1428 else if (!scrolled_down
)
1429 srow
+= wp
->w_lines
[idx
].wl_size
;
1431 # ifdef FEAT_FOLDING
1432 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1433 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1439 mid_end
= wp
->w_height
;
1440 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1442 if (wp
->w_lines
[idx
].wl_valid
1443 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1445 /* Only update until first row of this line */
1449 srow
+= wp
->w_lines
[idx
].wl_size
;
1454 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1456 wp
->w_old_visual_mode
= VIsual_mode
;
1457 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1458 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1459 wp
->w_old_visual_col
= VIsual
.col
;
1460 wp
->w_old_curswant
= curwin
->w_curswant
;
1464 wp
->w_old_visual_mode
= 0;
1465 wp
->w_old_cursor_lnum
= 0;
1466 wp
->w_old_visual_lnum
= 0;
1467 wp
->w_old_visual_col
= 0;
1469 #endif /* FEAT_VISUAL */
1471 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1472 /* reset got_int, otherwise regexp won't work */
1473 save_got_int
= got_int
;
1477 win_foldinfo
.fi_level
= 0;
1481 * Update all the window rows.
1483 idx
= 0; /* first entry in w_lines[].wl_size */
1486 lnum
= wp
->w_topline
; /* first line shown in window */
1489 /* stop updating when reached the end of the window (check for _past_
1490 * the end of the window is at the end of the loop) */
1491 if (row
== wp
->w_height
)
1497 /* stop updating when hit the end of the file */
1498 if (lnum
> buf
->b_ml
.ml_line_count
)
1504 /* Remember the starting row of the line that is going to be dealt
1505 * with. It is used further down when the line doesn't fit. */
1509 * Update a line when it is in an area that needs updating, when it
1510 * has changes or w_lines[idx] is invalid.
1511 * bot_start may be halfway a wrapped line after using
1512 * win_del_lines(), check if the current line includes it.
1513 * When syntax folding is being used, the saved syntax states will
1514 * already have been updated, we can't see where the syntax state is
1515 * the same again, just update until the end of the window.
1518 || (row
>= mid_start
&& row
< mid_end
)
1519 #ifdef FEAT_SEARCH_EXTRA
1522 || idx
>= wp
->w_lines_valid
1523 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1529 || did_update
== DID_FOLD
1530 || (did_update
== DID_LINE
1531 && syntax_present(buf
)
1533 # ifdef FEAT_FOLDING
1534 (foldmethodIsSyntax(wp
)
1535 && hasAnyFolding(wp
)) ||
1537 syntax_check_changed(lnum
)))
1541 #ifdef FEAT_SEARCH_EXTRA
1542 if (lnum
== mod_top
)
1547 * When at start of changed lines: May scroll following lines
1548 * up or down to minimize redrawing.
1549 * Don't do this when the change continues until the end.
1550 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1553 && mod_bot
!= MAXLNUM
1554 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1561 /* Count the old number of window rows, using w_lines[], which
1562 * should still contain the sizes for the lines as they are
1563 * currently displayed. */
1564 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1566 /* Only valid lines have a meaningful wl_lnum. Invalid
1567 * lines are part of the changed area. */
1568 if (wp
->w_lines
[i
].wl_valid
1569 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1571 old_rows
+= wp
->w_lines
[i
].wl_size
;
1573 if (wp
->w_lines
[i
].wl_valid
1574 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1576 /* Must have found the last valid entry above mod_bot.
1577 * Add following invalid entries. */
1579 while (i
< wp
->w_lines_valid
1580 && !wp
->w_lines
[i
].wl_valid
)
1581 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1587 if (i
>= wp
->w_lines_valid
)
1589 /* We can't find a valid line below the changed lines,
1590 * need to redraw until the end of the window.
1591 * Inserting/deleting lines has no use. */
1596 /* Able to count old number of rows: Count new window
1597 * rows, and may insert/delete lines */
1599 for (l
= lnum
; l
< mod_bot
; ++l
)
1602 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1607 if (l
== wp
->w_topline
)
1608 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1612 new_rows
+= plines_win(wp
, l
, TRUE
);
1614 if (new_rows
> wp
->w_height
- row
- 2)
1616 /* it's getting too much, must redraw the rest */
1621 xtra_rows
= new_rows
- old_rows
;
1624 /* May scroll text up. If there is not enough
1625 * remaining text or scrolling fails, must redraw the
1626 * rest. If scrolling works, must redraw the text
1627 * below the scrolled text. */
1628 if (row
- xtra_rows
>= wp
->w_height
- 2)
1632 check_for_delay(FALSE
);
1633 if (win_del_lines(wp
, row
,
1634 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1637 bot_start
= wp
->w_height
+ xtra_rows
;
1640 else if (xtra_rows
> 0)
1642 /* May scroll text down. If there is not enough
1643 * remaining text of scrolling fails, must redraw the
1645 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1649 check_for_delay(FALSE
);
1650 if (win_ins_lines(wp
, row
+ old_rows
,
1651 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1653 else if (top_end
> row
+ old_rows
)
1654 /* Scrolled the part at the top that requires
1656 top_end
+= xtra_rows
;
1660 /* When not updating the rest, may need to move w_lines[]
1662 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1666 int x
= row
+ new_rows
;
1668 /* move entries in w_lines[] upwards */
1671 /* stop at last valid entry in w_lines[] */
1672 if (i
>= wp
->w_lines_valid
)
1674 wp
->w_lines_valid
= j
;
1677 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1678 /* stop at a line that won't fit */
1679 if (x
+ (int)wp
->w_lines
[j
].wl_size
1682 wp
->w_lines_valid
= j
+ 1;
1685 x
+= wp
->w_lines
[j
++].wl_size
;
1693 /* move entries in w_lines[] downwards */
1695 wp
->w_lines_valid
+= j
;
1696 if (wp
->w_lines_valid
> wp
->w_height
)
1697 wp
->w_lines_valid
= wp
->w_height
;
1698 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1699 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1701 /* The w_lines[] entries for inserted lines are
1702 * now invalid, but wl_size may be used above.
1706 wp
->w_lines
[i
].wl_size
= 0;
1707 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1716 * When lines are folded, display one line for all of them.
1717 * Otherwise, display normally (can be several display lines when
1720 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1721 if (fold_count
!= 0)
1723 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1726 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1727 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1729 did_update
= DID_FOLD
;
1734 if (idx
< wp
->w_lines_valid
1735 && wp
->w_lines
[idx
].wl_valid
1736 && wp
->w_lines
[idx
].wl_lnum
== lnum
1737 && lnum
> wp
->w_topline
1738 && !(dy_flags
& DY_LASTLINE
)
1739 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1741 && diff_check_fill(wp
, lnum
) == 0
1745 /* This line is not going to fit. Don't draw anything here,
1746 * will draw "@ " lines below. */
1747 row
= wp
->w_height
+ 1;
1751 #ifdef FEAT_SEARCH_EXTRA
1752 prepare_search_hl(wp
, lnum
);
1755 /* Let the syntax stuff know we skipped a few lines. */
1756 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1757 && syntax_present(buf
))
1758 syntax_end_parsing(syntax_last_parsed
+ 1);
1764 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1767 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1768 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1771 did_update
= DID_LINE
;
1772 syntax_last_parsed
= lnum
;
1776 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1777 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1778 if (row
> wp
->w_height
) /* past end of screen */
1780 /* we may need the size of that too long line later on */
1781 if (dollar_vcol
== 0)
1782 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1786 if (dollar_vcol
== 0)
1787 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1790 lnum
+= fold_count
+ 1;
1797 /* This line does not need updating, advance to the next one */
1798 row
+= wp
->w_lines
[idx
++].wl_size
;
1799 if (row
> wp
->w_height
) /* past end of screen */
1802 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1807 did_update
= DID_NONE
;
1811 if (lnum
> buf
->b_ml
.ml_line_count
)
1818 * End of loop over all window lines.
1822 if (idx
> wp
->w_lines_valid
)
1823 wp
->w_lines_valid
= idx
;
1827 * Let the syntax stuff know we stop parsing here.
1829 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1830 syntax_end_parsing(syntax_last_parsed
+ 1);
1834 * If we didn't hit the end of the file, and we didn't finish the last
1835 * line we were working on, then the line didn't fit.
1837 wp
->w_empty_rows
= 0;
1839 wp
->w_filler_rows
= 0;
1841 if (!eof
&& !didline
)
1843 if (lnum
== wp
->w_topline
)
1846 * Single line that does not fit!
1847 * Don't overwrite it, it can be edited.
1849 wp
->w_botline
= lnum
+ 1;
1852 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1854 /* Window ends in filler lines. */
1855 wp
->w_botline
= lnum
;
1856 wp
->w_filler_rows
= wp
->w_height
- srow
;
1859 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1862 * Last line isn't finished: Display "@@@" at the end.
1864 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1865 W_WINROW(wp
) + wp
->w_height
,
1866 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1867 '@', '@', hl_attr(HLF_AT
));
1868 set_empty_rows(wp
, srow
);
1869 wp
->w_botline
= lnum
;
1873 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1874 wp
->w_botline
= lnum
;
1879 #ifdef FEAT_VERTSPLIT
1880 draw_vsep_win(wp
, row
);
1882 if (eof
) /* we hit the end of the file */
1884 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1886 j
= diff_check_fill(wp
, wp
->w_botline
);
1887 if (j
> 0 && !wp
->w_botfill
)
1890 * Display filler lines at the end of the file
1892 if (char2cells(fill_diff
) > 1)
1896 if (row
+ j
> wp
->w_height
)
1897 j
= wp
->w_height
- row
;
1898 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1903 else if (dollar_vcol
== 0)
1904 wp
->w_botline
= lnum
;
1906 /* make sure the rest of the screen is blank */
1907 /* put '~'s on rows that aren't part of the file. */
1908 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1911 /* Reset the type of redrawing required, the window has been updated. */
1912 wp
->w_redr_type
= 0;
1914 wp
->w_old_topfill
= wp
->w_topfill
;
1915 wp
->w_old_botfill
= wp
->w_botfill
;
1918 if (dollar_vcol
== 0)
1921 * There is a trick with w_botline. If we invalidate it on each
1922 * change that might modify it, this will cause a lot of expensive
1923 * calls to plines() in update_topline() each time. Therefore the
1924 * value of w_botline is often approximated, and this value is used to
1925 * compute the value of w_topline. If the value of w_botline was
1926 * wrong, check that the value of w_topline is correct (cursor is on
1927 * the visible part of the text). If it's not, we need to redraw
1928 * again. Mostly this just means scrolling up a few lines, so it
1929 * doesn't look too bad. Only do this for the current window (where
1930 * changes are relevant).
1932 wp
->w_valid
|= VALID_BOTLINE
;
1933 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1936 curwin
->w_valid
&= ~VALID_TOPLINE
;
1937 update_topline(); /* may invalidate w_botline again */
1938 if (must_redraw
!= 0)
1940 /* Don't update for changes in buffer again. */
1941 i
= curbuf
->b_mod_set
;
1942 curbuf
->b_mod_set
= FALSE
;
1945 curbuf
->b_mod_set
= i
;
1951 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1952 /* restore got_int, unless CTRL-C was hit while redrawing */
1954 got_int
= save_got_int
;
1959 static int draw_signcolumn
__ARGS((win_T
*wp
));
1962 * Return TRUE when window "wp" has a column to draw signs in.
1968 return (wp
->w_buffer
->b_signlist
!= NULL
1969 # ifdef FEAT_NETBEANS_INTG
1977 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1978 * as the filler character.
1981 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
1989 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
1996 #ifdef FEAT_RIGHTLEFT
1999 /* No check for cmdline window: should never be right-left. */
2000 # ifdef FEAT_FOLDING
2005 /* draw the fold column at the right */
2006 if (n
> W_WIDTH(wp
))
2008 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2009 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
2010 ' ', ' ', hl_attr(HLF_FC
));
2014 if (draw_signcolumn(wp
))
2018 /* draw the sign column left of the fold column */
2019 if (nn
> W_WIDTH(wp
))
2021 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2022 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2023 ' ', ' ', hl_attr(HLF_SC
));
2027 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2028 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2029 c2
, c2
, hl_attr(hl
));
2030 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2031 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2032 c1
, c2
, hl_attr(hl
));
2038 if (cmdwin_type
!= 0 && wp
== curwin
)
2040 /* draw the cmdline character in the leftmost column */
2042 if (n
> wp
->w_width
)
2044 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2045 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2046 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2050 if (wp
->w_p_fdc
> 0)
2052 int nn
= n
+ wp
->w_p_fdc
;
2054 /* draw the fold column at the left */
2055 if (nn
> W_WIDTH(wp
))
2057 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2058 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2059 ' ', ' ', hl_attr(HLF_FC
));
2064 if (draw_signcolumn(wp
))
2068 /* draw the sign column after the fold column */
2069 if (nn
> W_WIDTH(wp
))
2071 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2072 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2073 ' ', ' ', hl_attr(HLF_SC
));
2077 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2078 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2079 c1
, c2
, hl_attr(hl
));
2081 set_empty_rows(wp
, row
);
2086 * Display one folded line.
2089 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2092 foldinfo_T
*foldinfo
;
2098 linenr_T lnume
= lnum
+ fold_count
- 1;
2104 int off
= (int)(current_ScreenLine
- ScreenLines
);
2107 /* Build the fold line:
2108 * 1. Add the cmdwin_type for the command-line window
2109 * 2. Add the 'foldcolumn'
2110 * 3. Add the 'number' column
2111 * 4. Compose the text
2113 * 6. set highlighting for the Visual area an other text
2118 * 1. Add the cmdwin_type for the command-line window
2119 * Ignores 'rightleft', this window is never right-left.
2122 if (cmdwin_type
!= 0 && wp
== curwin
)
2124 ScreenLines
[off
] = cmdwin_type
;
2125 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2128 ScreenLinesUC
[off
] = 0;
2135 * 2. Add the 'foldcolumn'
2138 if (fdc
> W_WIDTH(wp
) - col
)
2139 fdc
= W_WIDTH(wp
) - col
;
2142 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2143 #ifdef FEAT_RIGHTLEFT
2148 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2150 /* reverse the fold column */
2151 for (i
= 0; i
< fdc
; ++i
)
2152 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2156 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2160 #ifdef FEAT_RIGHTLEFT
2161 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2162 for (ri = 0; ri < l; ++ri) \
2163 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2165 for (ri = 0; ri < l; ++ri) \
2166 ScreenAttrs[off + (p) + ri] = v
2168 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2169 ScreenAttrs[off + (p) + ri] = v
2172 /* Set all attributes of the 'number' column and the text */
2173 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2176 /* If signs are being displayed, add two spaces. */
2177 if (draw_signcolumn(wp
))
2179 len
= W_WIDTH(wp
) - col
;
2184 # ifdef FEAT_RIGHTLEFT
2186 /* the line number isn't reversed */
2187 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2188 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2191 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2198 * 3. Add the 'number' column
2202 len
= W_WIDTH(wp
) - col
;
2205 int w
= number_width(wp
);
2209 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2210 #ifdef FEAT_RIGHTLEFT
2212 /* the line number isn't reversed */
2213 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2217 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2223 * 4. Compose the folded-line string with 'foldtext', if set.
2225 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2227 txtcol
= col
; /* remember where text starts */
2230 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2231 * Right-left text is put in columns 0 - number-col, normal text is put
2232 * in columns number-col - window-width.
2238 int u8c
, u8cc
[MAX_MCO
];
2244 int prev_c
= 0; /* previous Arabic character */
2245 int prev_c1
= 0; /* first composing char for prev_c */
2248 # ifdef FEAT_RIGHTLEFT
2255 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2256 for (p
= text
; *p
!= NUL
; )
2258 cells
= (*mb_ptr2cells
)(p
);
2259 c_len
= (*mb_ptr2len
)(p
);
2260 if (col
+ cells
> W_WIDTH(wp
)
2261 # ifdef FEAT_RIGHTLEFT
2262 - (wp
->w_p_rl
? col
: 0)
2266 ScreenLines
[idx
] = *p
;
2269 u8c
= utfc_ptr2char(p
, u8cc
);
2270 if (*p
< 0x80 && u8cc
[0] == 0)
2272 ScreenLinesUC
[idx
] = 0;
2280 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2282 /* Do Arabic shaping. */
2287 /* The idea of what is the previous and next
2288 * character depends on 'rightleft'. */
2293 nc
= utf_ptr2char(p
+ c_len
);
2298 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2304 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2306 ScreenLines
[idx
] = firstbyte
;
2311 /* Non-BMP character: display as ? or fullwidth ?. */
2314 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2317 ScreenLinesUC
[idx
] = u8c
;
2318 for (i
= 0; i
< Screen_mco
; ++i
)
2320 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2326 ScreenLines
[idx
+ 1] = 0;
2328 else if (cells
> 1) /* double-byte character */
2330 if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2331 ScreenLines2
[idx
] = p
[1];
2333 ScreenLines
[idx
+ 1] = p
[1];
2343 len
= (int)STRLEN(text
);
2344 if (len
> W_WIDTH(wp
) - col
)
2345 len
= W_WIDTH(wp
) - col
;
2348 #ifdef FEAT_RIGHTLEFT
2350 STRNCPY(current_ScreenLine
, text
, len
);
2353 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2358 /* Fill the rest of the line with the fold filler */
2359 #ifdef FEAT_RIGHTLEFT
2363 while (col
< W_WIDTH(wp
)
2364 #ifdef FEAT_RIGHTLEFT
2365 - (wp
->w_p_rl
? txtcol
: 0)
2372 if (fill_fold
>= 0x80)
2374 ScreenLinesUC
[off
+ col
] = fill_fold
;
2375 ScreenLinesC
[0][off
+ col
] = 0;
2378 ScreenLinesUC
[off
+ col
] = 0;
2381 ScreenLines
[off
+ col
++] = fill_fold
;
2388 * 6. set highlighting for the Visual area an other text.
2389 * If all folded lines are in the Visual area, highlight the line.
2392 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2394 if (ltoreq(curwin
->w_cursor
, VIsual
))
2396 /* Visual is after curwin->w_cursor */
2397 top
= &curwin
->w_cursor
;
2402 /* Visual is before curwin->w_cursor */
2404 bot
= &curwin
->w_cursor
;
2406 if (lnum
>= top
->lnum
2407 && lnume
<= bot
->lnum
2408 && (VIsual_mode
!= 'v'
2409 || ((lnum
> top
->lnum
2410 || (lnum
== top
->lnum
2412 && (lnume
< bot
->lnum
2413 || (lnume
== bot
->lnum
2414 && (bot
->col
- (*p_sel
== 'e'))
2415 >= (colnr_T
)STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2417 if (VIsual_mode
== Ctrl_V
)
2419 /* Visual block mode: highlight the chars part of the block */
2420 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2422 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2423 len
= wp
->w_old_cursor_lcol
;
2425 len
= W_WIDTH(wp
) - txtcol
;
2426 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2427 len
- (int)wp
->w_old_cursor_fcol
);
2432 /* Set all attributes of the text */
2433 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2440 /* Show 'cursorcolumn' in the fold line. */
2443 txtcol
+= wp
->w_virtcol
;
2445 txtcol
-= wp
->w_skipcol
;
2447 txtcol
-= wp
->w_leftcol
;
2448 if (txtcol
>= 0 && txtcol
< W_WIDTH(wp
))
2449 ScreenAttrs
[off
+ txtcol
] = hl_combine_attr(
2450 ScreenAttrs
[off
+ txtcol
], hl_attr(HLF_CUC
));
2454 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2455 (int)W_WIDTH(wp
), FALSE
);
2458 * Update w_cline_height and w_cline_folded if the cursor line was
2459 * updated (saves a call to plines() later).
2462 && lnum
<= curwin
->w_cursor
.lnum
2463 && lnume
>= curwin
->w_cursor
.lnum
)
2465 curwin
->w_cline_row
= row
;
2466 curwin
->w_cline_height
= 1;
2467 curwin
->w_cline_folded
= TRUE
;
2468 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2473 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2476 copy_text_attr(off
, buf
, len
, attr
)
2484 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2487 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2489 for (i
= 0; i
< len
; ++i
)
2490 ScreenAttrs
[off
+ i
] = attr
;
2494 * Fill the foldcolumn at "p" for window "wp".
2495 * Only to be called when 'foldcolumn' > 0.
2498 fill_foldcolumn(p
, wp
, closed
, lnum
)
2501 int closed
; /* TRUE of FALSE */
2502 linenr_T lnum
; /* current line number */
2509 /* Init to all spaces. */
2510 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2512 level
= win_foldinfo
.fi_level
;
2515 /* If there is only one column put more info in it. */
2516 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2518 /* If the column is too narrow, we start at the lowest level that
2519 * fits and use numbers to indicated the depth. */
2520 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2521 if (first_level
< 1)
2524 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2526 if (win_foldinfo
.fi_lnum
== lnum
2527 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2529 else if (first_level
== 1)
2531 else if (first_level
+ i
<= 9)
2532 p
[i
] = '0' + first_level
+ i
;
2535 if (first_level
+ i
== level
)
2540 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2542 #endif /* FEAT_FOLDING */
2545 * Display line "lnum" of window 'wp' on the screen.
2546 * Start at row "startrow", stop when "endrow" is reached.
2547 * wp->w_virtcol needs to be valid.
2549 * Return the number of last row the line occupies.
2552 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2557 int nochange UNUSED
; /* not updating for changed text */
2559 int col
; /* visual column on screen */
2560 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2561 int c
= 0; /* init for GCC */
2562 long vcol
= 0; /* virtual column (for tabs) */
2563 long vcol_prev
= -1; /* "vcol" of previous character */
2564 char_u
*line
; /* current line */
2565 char_u
*ptr
; /* current position in "line" */
2566 int row
; /* row in the window, excl w_winrow */
2567 int screen_row
; /* row on the screen, incl w_winrow */
2569 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2570 int n_extra
= 0; /* number of extra chars */
2571 char_u
*p_extra
= NULL
; /* string of extra chars, plus NUL */
2572 int c_extra
= NUL
; /* extra chars, all the same */
2573 int extra_attr
= 0; /* attributes when n_extra != 0 */
2574 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2575 displaying lcs_eol at end-of-line */
2576 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2577 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2579 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2580 int saved_n_extra
= 0;
2581 char_u
*saved_p_extra
= NULL
;
2582 int saved_c_extra
= 0;
2583 int saved_char_attr
= 0;
2585 int n_attr
= 0; /* chars with special attr */
2586 int saved_attr2
= 0; /* char_attr saved for n_attr */
2587 int n_attr3
= 0; /* chars with overruling special attr */
2588 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2590 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2592 int fromcol
, tocol
; /* start/end of inverting */
2593 int fromcol_prev
= -2; /* start of inverting after cursor */
2594 int noinvcur
= FALSE
; /* don't invert the cursor */
2597 int lnum_in_visual_area
= FALSE
;
2602 int char_attr
= 0; /* attributes for next character */
2603 int attr_pri
= FALSE
; /* char_attr has priority */
2604 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2606 int attr
= 0; /* attributes for area highlighting */
2607 int area_attr
= 0; /* attributes desired by highlighting */
2608 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2610 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2611 int syntax_attr
= 0; /* attributes desired by syntax */
2612 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2614 int eol_hl_off
= 0; /* 1 if highlighted char after EOL */
2617 int has_spell
= FALSE
; /* this buffer has spell checking */
2618 # define SPWORDLEN 150
2619 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2620 int nextlinecol
= 0; /* column where nextline[] starts */
2621 int nextline_idx
= 0; /* index in nextline[] where next line
2623 int spell_attr
= 0; /* attributes desired by spelling */
2624 int word_end
= 0; /* last byte with same spell_attr */
2625 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2626 static int checked_col
= 0; /* column in "checked_lnum" up to which
2627 * there are no spell errors */
2628 static int cap_col
= -1; /* column to check for Cap word */
2629 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2630 int cur_checked_col
= 0; /* checked column for current line */
2632 int extra_check
; /* has syntax or linebreak */
2634 int multi_attr
= 0; /* attributes desired by multibyte */
2635 int mb_l
= 1; /* multi-byte byte length */
2636 int mb_c
= 0; /* decoded multi-byte character */
2637 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2638 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2641 int filler_lines
; /* nr of filler lines to be drawn */
2642 int filler_todo
; /* nr of filler lines still to do + 1 */
2643 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2644 int change_start
= MAXCOL
; /* first col of changed area */
2645 int change_end
= -1; /* last col of changed area */
2647 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2648 #ifdef FEAT_LINEBREAK
2649 int need_showbreak
= FALSE
;
2651 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2652 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2654 int line_attr
= 0; /* attribute for the whole line */
2656 #ifdef FEAT_SEARCH_EXTRA
2657 matchitem_T
*cur
; /* points to the match list */
2658 match_T
*shl
; /* points to search_hl or a match */
2659 int shl_flag
; /* flag to indicate whether search_hl
2660 has been processed or not */
2661 int prevcol_hl_flag
; /* flag to indicate whether prevcol
2662 equals startcol of search_hl or one
2666 int prev_c
= 0; /* previous Arabic character */
2667 int prev_c1
= 0; /* first composing char for prev_c */
2669 #if defined(LINE_ATTR)
2670 int did_line_attr
= 0;
2673 /* draw_state: items that are drawn in sequence: */
2674 #define WL_START 0 /* nothing done yet */
2676 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2678 # define WL_CMDLINE WL_START
2681 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2683 # define WL_FOLD WL_CMDLINE
2686 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2688 # define WL_SIGN WL_FOLD /* column for signs */
2690 #define WL_NR WL_SIGN + 1 /* line number */
2691 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2692 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2694 # define WL_SBR WL_NR
2696 #define WL_LINE WL_SBR + 1 /* text in the line */
2697 int draw_state
= WL_START
; /* what to draw next */
2698 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2699 int feedback_col
= 0;
2700 int feedback_old_attr
= -1;
2704 if (startrow
> endrow
) /* past the end already! */
2708 screen_row
= row
+ W_WINROW(wp
);
2711 * To speed up the loop below, set extra_check when there is linebreak,
2712 * trailing white space and/or syntax processing to be done.
2714 #ifdef FEAT_LINEBREAK
2715 extra_check
= wp
->w_p_lbr
;
2720 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2722 /* Prepare for syntax highlighting in this line. When there is an
2723 * error, stop syntax highlighting. */
2724 save_did_emsg
= did_emsg
;
2726 syntax_start(wp
, lnum
);
2728 wp
->w_buffer
->b_syn_error
= TRUE
;
2731 did_emsg
= save_did_emsg
;
2740 && *wp
->w_buffer
->b_p_spl
!= NUL
2741 && wp
->w_buffer
->b_langp
.ga_len
> 0
2742 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2744 /* Prepare for spell checking. */
2748 /* Get the start of the next line, so that words that wrap to the next
2749 * line are found too: "et<line-break>al.".
2750 * Trick: skip a few chars for C/shell/Vim comments */
2751 nextline
[SPWORDLEN
] = NUL
;
2752 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2754 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2755 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2758 /* When a word wrapped from the previous line the start of the current
2760 if (lnum
== checked_lnum
)
2761 cur_checked_col
= checked_col
;
2764 /* When there was a sentence end in the previous line may require a
2765 * word starting with capital in this line. In line 1 always check
2766 * the first word. */
2767 if (lnum
!= capcol_lnum
)
2776 * handle visual active in this window
2781 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2783 /* Visual is after curwin->w_cursor */
2784 if (ltoreq(curwin
->w_cursor
, VIsual
))
2786 top
= &curwin
->w_cursor
;
2789 else /* Visual is before curwin->w_cursor */
2792 bot
= &curwin
->w_cursor
;
2794 lnum_in_visual_area
= (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
);
2795 if (VIsual_mode
== Ctrl_V
) /* block mode */
2797 if (lnum_in_visual_area
)
2799 fromcol
= wp
->w_old_cursor_fcol
;
2800 tocol
= wp
->w_old_cursor_lcol
;
2803 else /* non-block mode */
2805 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2807 else if (lnum
== top
->lnum
)
2809 if (VIsual_mode
== 'V') /* linewise */
2813 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2814 if (gchar_pos(top
) == NUL
)
2815 tocol
= fromcol
+ 1;
2818 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2820 if (*p_sel
== 'e' && bot
->col
== 0
2821 #ifdef FEAT_VIRTUALEDIT
2829 else if (bot
->col
== MAXCOL
)
2835 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2838 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2846 /* Check if the character under the cursor should not be inverted */
2847 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2855 /* if inverting in this line set area_highlighting */
2858 area_highlighting
= TRUE
;
2859 attr
= hl_attr(HLF_V
);
2860 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2861 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2862 attr
= hl_attr(HLF_VNC
);
2868 * handle 'incsearch' and ":s///c" highlighting
2871 #endif /* FEAT_VISUAL */
2874 && lnum
>= curwin
->w_cursor
.lnum
2875 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2877 if (lnum
== curwin
->w_cursor
.lnum
)
2878 getvcol(curwin
, &(curwin
->w_cursor
),
2879 (colnr_T
*)&fromcol
, NULL
, NULL
);
2882 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2885 pos
.col
= search_match_endcol
;
2886 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2890 /* do at least one character; happens when past end of line */
2891 if (fromcol
== tocol
)
2892 tocol
= fromcol
+ 1;
2893 area_highlighting
= TRUE
;
2894 attr
= hl_attr(HLF_I
);
2898 filler_lines
= diff_check(wp
, lnum
);
2899 if (filler_lines
< 0)
2901 if (filler_lines
== -1)
2903 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2904 diff_hlf
= HLF_ADD
; /* added line */
2905 else if (change_start
== 0)
2906 diff_hlf
= HLF_TXD
; /* changed text */
2908 diff_hlf
= HLF_CHD
; /* changed line */
2911 diff_hlf
= HLF_ADD
; /* added line */
2913 area_highlighting
= TRUE
;
2915 if (lnum
== wp
->w_topline
)
2916 filler_lines
= wp
->w_topfill
;
2917 filler_todo
= filler_lines
;
2922 /* If this line has a sign with line highlighting set line_attr. */
2923 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2925 line_attr
= sign_get_attr((int)v
, TRUE
);
2927 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2928 /* Highlight the current line in the quickfix window. */
2929 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2930 line_attr
= hl_attr(HLF_L
);
2933 area_highlighting
= TRUE
;
2936 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2942 /* For checking first word with a capital skip white space. */
2944 cap_col
= (int)(skipwhite(line
) - line
);
2946 /* To be able to spell-check over line boundaries copy the end of the
2947 * current line into nextline[]. Above the start of the next line was
2948 * copied to nextline[SPWORDLEN]. */
2949 if (nextline
[SPWORDLEN
] == NUL
)
2951 /* No next line or it is empty. */
2952 nextlinecol
= MAXCOL
;
2957 v
= (long)STRLEN(line
);
2960 /* Short line, use it completely and append the start of the
2963 mch_memmove(nextline
, line
, (size_t)v
);
2964 STRMOVE(nextline
+ v
, nextline
+ SPWORDLEN
);
2965 nextline_idx
= v
+ 1;
2969 /* Long line, use only the last SPWORDLEN bytes. */
2970 nextlinecol
= v
- SPWORDLEN
;
2971 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2972 nextline_idx
= SPWORDLEN
+ 1;
2978 /* find start of trailing whitespace */
2979 if (wp
->w_p_list
&& lcs_trail
)
2981 trailcol
= (colnr_T
)STRLEN(ptr
);
2982 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
2984 trailcol
+= (colnr_T
) (ptr
- line
);
2989 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
2990 * first character to be displayed.
2999 char_u
*prev_ptr
= ptr
;
3001 while (vcol
< v
&& *ptr
!= NUL
)
3003 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
3011 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3013 * - 'cuc' is set, or
3014 * - 'virtualedit' is set, or
3015 * - the visual mode is active,
3016 * the end of the line may be before the start of the displayed part.
3021 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3025 # ifdef FEAT_VIRTUALEDIT
3032 (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
3040 /* Handle a character that's not completely on the screen: Put ptr at
3041 * that character but skip the first few screen characters. */
3054 * Adjust for when the inverted text is before the screen,
3055 * and when the start of the inverted text is before the screen.
3059 else if (fromcol
>= 0 && fromcol
< vcol
)
3062 #ifdef FEAT_LINEBREAK
3063 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3065 need_showbreak
= TRUE
;
3068 /* When spell checking a word we need to figure out the start of the
3069 * word and if it's badly spelled or not. */
3073 colnr_T linecol
= (colnr_T
)(ptr
- line
);
3074 hlf_T spell_hlf
= HLF_COUNT
;
3077 wp
->w_cursor
.lnum
= lnum
;
3078 wp
->w_cursor
.col
= linecol
;
3079 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3081 /* spell_move_to() may call ml_get() and make "line" invalid */
3082 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3083 ptr
= line
+ linecol
;
3085 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3087 /* no bad word found at line start, don't check until end of a
3089 spell_hlf
= HLF_COUNT
;
3090 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
)
3095 /* bad word found, use attributes until end of word */
3096 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3098 /* Turn index into actual attributes. */
3099 if (spell_hlf
!= HLF_COUNT
)
3100 spell_attr
= highlight_attr
[spell_hlf
];
3105 /* Need to restart syntax highlighting for this line. */
3107 syntax_start(wp
, lnum
);
3114 * Correct highlighting for cursor that can't be disabled.
3115 * Avoids having to check this for each character.
3121 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3123 /* highlighting starts at cursor, let it start just after the
3125 fromcol_prev
= fromcol
;
3128 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3129 /* restart highlighting after the cursor */
3130 fromcol_prev
= wp
->w_virtcol
;
3132 if (fromcol
>= tocol
)
3136 #ifdef FEAT_SEARCH_EXTRA
3138 * Handle highlighting the last used search pattern and matches.
3139 * Do this for both search_hl and the match list.
3141 cur
= wp
->w_match_head
;
3143 while (cur
!= NULL
|| shl_flag
== FALSE
)
3145 if (shl_flag
== FALSE
)
3152 shl
->startcol
= MAXCOL
;
3153 shl
->endcol
= MAXCOL
;
3155 if (shl
->rm
.regprog
!= NULL
)
3157 v
= (long)(ptr
- line
);
3158 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3160 /* Need to get the line again, a multi-line regexp may have made it
3162 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3165 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3167 if (shl
->lnum
== lnum
)
3168 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3171 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3172 - shl
->rm
.startpos
[0].lnum
)
3173 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3175 shl
->endcol
= MAXCOL
;
3176 /* Highlight one character for an empty match. */
3177 if (shl
->startcol
== shl
->endcol
)
3180 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3181 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3186 if ((long)shl
->startcol
< v
) /* match at leftcol */
3188 shl
->attr_cur
= shl
->attr
;
3189 search_attr
= shl
->attr
;
3191 area_highlighting
= TRUE
;
3194 if (shl
!= &search_hl
&& cur
!= NULL
)
3200 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3201 * active, because it's not clear what is selected then. */
3202 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3204 line_attr
= hl_attr(HLF_CUL
);
3205 area_highlighting
= TRUE
;
3209 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3211 #ifdef FEAT_RIGHTLEFT
3214 /* Rightleft window: process the text in the normal direction, but put
3215 * it in current_ScreenLine[] from right to left. Start at the
3216 * rightmost column of the window. */
3217 col
= W_WIDTH(wp
) - 1;
3223 * Repeat for the whole displayed line.
3227 /* Skip this quickly when working on the text. */
3228 if (draw_state
!= WL_LINE
)
3231 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3233 draw_state
= WL_CMDLINE
;
3234 if (cmdwin_type
!= 0 && wp
== curwin
)
3236 /* Draw the cmdline character. */
3238 c_extra
= cmdwin_type
;
3239 char_attr
= hl_attr(HLF_AT
);
3245 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3247 draw_state
= WL_FOLD
;
3248 if (wp
->w_p_fdc
> 0)
3250 /* Draw the 'foldcolumn'. */
3251 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3252 n_extra
= wp
->w_p_fdc
;
3254 p_extra
[n_extra
] = NUL
;
3256 char_attr
= hl_attr(HLF_FC
);
3262 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3264 draw_state
= WL_SIGN
;
3265 /* Show the sign column when there are any signs in this
3266 * buffer or when using Netbeans. */
3267 if (draw_signcolumn(wp
)
3274 # ifdef FEAT_SIGN_ICONS
3278 /* Draw two cells with the sign value or blank. */
3280 char_attr
= hl_attr(HLF_SC
);
3283 if (row
== startrow
)
3285 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3287 # ifdef FEAT_SIGN_ICONS
3288 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3290 if (gui
.in_use
&& icon_sign
!= 0)
3292 /* Use the image in this position. */
3293 c_extra
= SIGN_BYTE
;
3294 # ifdef FEAT_NETBEANS_INTG
3295 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3296 c_extra
= MULTISIGN_BYTE
;
3298 char_attr
= icon_sign
;
3304 p_extra
= sign_get_text(text_sign
);
3305 if (p_extra
!= NULL
)
3308 n_extra
= (int)STRLEN(p_extra
);
3310 char_attr
= sign_get_attr(text_sign
, FALSE
);
3317 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3320 /* Display the line number. After the first fill with blanks
3321 * when the 'n' flag isn't in 'cpo' */
3327 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3329 /* Draw the line number (empty space after wrapping). */
3336 sprintf((char *)extra
, "%*ld ",
3337 number_width(wp
), (long)lnum
);
3338 if (wp
->w_skipcol
> 0)
3339 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3341 #ifdef FEAT_RIGHTLEFT
3342 if (wp
->w_p_rl
) /* reverse line numbers */
3350 n_extra
= number_width(wp
) + 1;
3351 char_attr
= hl_attr(HLF_N
);
3353 /* When 'cursorline' is set highlight the line number of
3354 * the current line differently. */
3355 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3356 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3361 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3362 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3364 draw_state
= WL_SBR
;
3366 if (filler_todo
> 0)
3368 /* Draw "deleted" diff line(s). */
3369 if (char2cells(fill_diff
) > 1)
3372 c_extra
= fill_diff
;
3373 # ifdef FEAT_RIGHTLEFT
3378 n_extra
= W_WIDTH(wp
) - col
;
3379 char_attr
= hl_attr(HLF_DED
);
3382 # ifdef FEAT_LINEBREAK
3383 if (*p_sbr
!= NUL
&& need_showbreak
)
3385 /* Draw 'showbreak' at the start of each broken line. */
3388 n_extra
= (int)STRLEN(p_sbr
);
3389 char_attr
= hl_attr(HLF_AT
);
3390 need_showbreak
= FALSE
;
3391 /* Correct end of highlighted area for 'showbreak',
3392 * required when 'linebreak' is also set. */
3400 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3402 draw_state
= WL_LINE
;
3405 /* Continue item from end of wrapped line. */
3406 n_extra
= saved_n_extra
;
3407 c_extra
= saved_c_extra
;
3408 p_extra
= saved_p_extra
;
3409 char_attr
= saved_char_attr
;
3416 /* When still displaying '$' of change command, stop at cursor */
3417 if (dollar_vcol
!= 0 && wp
== curwin
3418 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3424 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3426 /* Pretend we have finished updating the window. Except when
3427 * 'cursorcolumn' is set. */
3430 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3437 if (draw_state
== WL_LINE
&& area_highlighting
)
3439 /* handle Visual or match highlighting in this line */
3442 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3443 && (*mb_ptr2cells
)(ptr
) > 1)
3445 || ((int)vcol_prev
== fromcol_prev
3446 && vcol_prev
< vcol
/* not at margin */
3448 area_attr
= attr
; /* start highlighting */
3449 else if (area_attr
!= 0
3451 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3452 area_attr
= 0; /* stop highlighting */
3454 #ifdef FEAT_SEARCH_EXTRA
3458 * Check for start/end of search pattern match.
3459 * After end, check for start/end of next match.
3460 * When another match, have to check for start again.
3461 * Watch out for matching an empty string!
3462 * Do this for 'search_hl' and the match list (ordered by
3465 v
= (long)(ptr
- line
);
3466 cur
= wp
->w_match_head
;
3468 while (cur
!= NULL
|| shl_flag
== FALSE
)
3470 if (shl_flag
== FALSE
3472 && cur
->priority
> SEARCH_HL_PRIORITY
)
3480 while (shl
->rm
.regprog
!= NULL
)
3482 if (shl
->startcol
!= MAXCOL
3483 && v
>= (long)shl
->startcol
3484 && v
< (long)shl
->endcol
)
3486 shl
->attr_cur
= shl
->attr
;
3488 else if (v
== (long)shl
->endcol
)
3492 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3494 /* Need to get the line again, a multi-line regexp
3495 * may have made it invalid. */
3496 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3499 if (shl
->lnum
== lnum
)
3501 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3502 if (shl
->rm
.endpos
[0].lnum
== 0)
3503 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3505 shl
->endcol
= MAXCOL
;
3507 if (shl
->startcol
== shl
->endcol
)
3509 /* highlight empty match, try again after
3513 shl
->endcol
+= (*mb_ptr2len
)(line
3520 /* Loop to check if the match starts at the
3521 * current position */
3527 if (shl
!= &search_hl
&& cur
!= NULL
)
3531 /* Use attributes from match with highest priority among
3532 * 'search_hl' and the match list. */
3533 search_attr
= search_hl
.attr_cur
;
3534 cur
= wp
->w_match_head
;
3536 while (cur
!= NULL
|| shl_flag
== FALSE
)
3538 if (shl_flag
== FALSE
3540 && cur
->priority
> SEARCH_HL_PRIORITY
)
3548 if (shl
->attr_cur
!= 0)
3549 search_attr
= shl
->attr_cur
;
3550 if (shl
!= &search_hl
&& cur
!= NULL
)
3557 if (diff_hlf
!= (hlf_T
)0)
3559 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
3561 diff_hlf
= HLF_TXD
; /* changed text */
3562 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
3564 diff_hlf
= HLF_CHD
; /* changed line */
3565 line_attr
= hl_attr(diff_hlf
);
3569 /* Decide which of the highlight attributes to use. */
3572 char_attr
= area_attr
;
3573 else if (search_attr
!= 0)
3574 char_attr
= search_attr
;
3576 /* Use line_attr when not in the Visual or 'incsearch' area
3577 * (area_attr may be 0 when "noinvcur" is set). */
3578 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3579 || vcol
< fromcol
|| vcol_prev
< fromcol_prev
3581 char_attr
= line_attr
;
3588 char_attr
= syntax_attr
;
3596 * Get the next character to put on the screen.
3599 * The "p_extra" points to the extra stuff that is inserted to
3600 * represent special characters (non-printable stuff) and other
3601 * things. When all characters are the same, c_extra is used.
3602 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3603 * "p_extra[n_extra]".
3604 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3612 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3613 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3632 /* If the UTF-8 character is more than one byte:
3633 * Decode it into "mb_c". */
3634 mb_l
= (*mb_ptr2len
)(p_extra
);
3640 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3647 /* if this is a DBCS character, put it in "mb_c" */
3648 mb_l
= MB_BYTE2LEN(c
);
3649 if (mb_l
>= n_extra
)
3652 mb_c
= (c
<< 8) + p_extra
[1];
3654 if (mb_l
== 0) /* at the NUL at end-of-line */
3657 /* If a double-width char doesn't fit display a '>' in the
3660 # ifdef FEAT_RIGHTLEFT
3661 wp
->w_p_rl
? (col
<= 0) :
3663 (col
>= W_WIDTH(wp
) - 1))
3664 && (*mb_char2cells
)(mb_c
) == 2)
3670 multi_attr
= hl_attr(HLF_AT
);
3671 /* put the pointer back to output the double-width
3672 * character at the start of the next line. */
3678 n_extra
-= mb_l
- 1;
3679 p_extra
+= mb_l
- 1;
3690 * Get a character from the line itself.
3699 /* If the UTF-8 character is more than one byte: Decode it
3701 mb_l
= (*mb_ptr2len
)(ptr
);
3705 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3706 /* Overlong encoded ASCII or ASCII with composing char
3707 * is displayed normally, except a NUL. */
3712 /* At start of the line we can have a composing char.
3713 * Draw it as a space with a composing char. */
3714 if (utf_iscomposing(mb_c
))
3718 for (i
= Screen_mco
- 1; i
> 0; --i
)
3719 u8cc
[i
] = u8cc
[i
- 1];
3725 if ((mb_l
== 1 && c
>= 0x80)
3726 || (mb_l
>= 1 && mb_c
== 0)
3727 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3734 * Illegal UTF-8 byte: display as <xx>.
3735 * Non-BMP character : display as ? or fullwidth ?.
3741 transchar_hex(extra
, mb_c
);
3742 # ifdef FEAT_RIGHTLEFT
3743 if (wp
->w_p_rl
) /* reverse */
3748 else if (utf_char2cells(mb_c
) != 2)
3751 /* 0xff1f in UTF-8: full-width '?' */
3752 STRCPY(extra
, "\357\274\237");
3757 mb_c
= mb_ptr2char_adv(&p_extra
);
3758 mb_utf8
= (c
>= 0x80);
3759 n_extra
= (int)STRLEN(p_extra
);
3761 if (area_attr
== 0 && search_attr
== 0)
3763 n_attr
= n_extra
+ 1;
3764 extra_attr
= hl_attr(HLF_8
);
3765 saved_attr2
= char_attr
; /* save current attr */
3768 else if (mb_l
== 0) /* at the NUL at end-of-line */
3771 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3773 /* Do Arabic shaping. */
3777 /* The idea of what is the previous and next
3778 * character depends on 'rightleft'. */
3783 nc
= utf_ptr2char(ptr
+ mb_l
);
3788 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3794 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3802 mb_l
= MB_BYTE2LEN(c
);
3803 if (mb_l
== 0) /* at the NUL at end-of-line */
3807 /* We assume a second byte below 32 is illegal.
3808 * Hopefully this is OK for all double-byte encodings!
3811 mb_c
= (c
<< 8) + ptr
[1];
3816 /* head byte at end of line */
3818 transchar_nonprint(extra
, c
);
3822 /* illegal tail byte */
3824 STRCPY(extra
, "XX");
3827 n_extra
= (int)STRLEN(extra
) - 1;
3830 if (area_attr
== 0 && search_attr
== 0)
3832 n_attr
= n_extra
+ 1;
3833 extra_attr
= hl_attr(HLF_8
);
3834 saved_attr2
= char_attr
; /* save current attr */
3840 /* If a double-width char doesn't fit display a '>' in the
3841 * last column; the character is displayed at the start of the
3844 # ifdef FEAT_RIGHTLEFT
3845 wp
->w_p_rl
? (col
<= 0) :
3847 (col
>= W_WIDTH(wp
) - 1))
3848 && (*mb_char2cells
)(mb_c
) == 2)
3854 multi_attr
= hl_attr(HLF_AT
);
3855 /* Put pointer back so that the character will be
3856 * displayed at the start of the next line. */
3859 else if (*ptr
!= NUL
)
3862 /* If a double-width char doesn't fit at the left side display
3863 * a '<' in the first column. */
3864 if (n_skip
> 0 && mb_l
> 1)
3869 if (area_attr
== 0 && search_attr
== 0)
3871 n_attr
= n_extra
+ 1;
3872 extra_attr
= hl_attr(HLF_AT
);
3873 saved_attr2
= char_attr
; /* save current attr */
3884 /* 'list' : change char 160 to lcs_nbsp. */
3885 if (wp
->w_p_list
&& (c
== 160
3887 || (mb_utf8
&& mb_c
== 160)
3892 if (area_attr
== 0 && search_attr
== 0)
3895 extra_attr
= hl_attr(HLF_8
);
3896 saved_attr2
= char_attr
; /* save current attr */
3900 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3914 int can_spell
= TRUE
;
3918 /* Get syntax attribute, unless still at the start of the line
3919 * (double-wide char that doesn't fit). */
3920 v
= (long)(ptr
- line
);
3921 if (has_syntax
&& v
> 0)
3923 /* Get the syntax attribute for the character. If there
3924 * is an error, disable syntax highlighting. */
3925 save_did_emsg
= did_emsg
;
3928 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3930 has_spell
? &can_spell
:
3936 wp
->w_buffer
->b_syn_error
= TRUE
;
3940 did_emsg
= save_did_emsg
;
3942 /* Need to get the line again, a multi-line regexp may
3943 * have made it invalid. */
3944 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3948 char_attr
= syntax_attr
;
3950 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3955 /* Check spelling (unless at the end of the line).
3956 * Only do this when there is no syntax highlighting, the
3957 * @Spell cluster is not used or the current syntax item
3958 * contains the @Spell cluster. */
3959 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3964 char_attr
= syntax_attr
;
3972 char_u
*prev_ptr
, *p
;
3974 hlf_T spell_hlf
= HLF_COUNT
;
3978 prev_ptr
= ptr
- mb_l
;
3985 /* Use nextline[] if possible, it has the start of the
3986 * next line concatenated. */
3987 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3988 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
3991 cap_col
-= (int)(prev_ptr
- line
);
3992 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
3996 /* In Insert mode only highlight a word that
3997 * doesn't touch the cursor. */
3998 if (spell_hlf
!= HLF_COUNT
3999 && (State
& INSERT
) != 0
4000 && wp
->w_cursor
.lnum
== lnum
4001 && wp
->w_cursor
.col
>=
4002 (colnr_T
)(prev_ptr
- line
)
4003 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
4005 spell_hlf
= HLF_COUNT
;
4006 spell_redraw_lnum
= lnum
;
4009 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
4010 && (p
- nextline
) + len
> nextline_idx
)
4012 /* Remember that the good word continues at the
4013 * start of the next line. */
4014 checked_lnum
= lnum
+ 1;
4015 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
4018 /* Turn index into actual attributes. */
4019 if (spell_hlf
!= HLF_COUNT
)
4020 spell_attr
= highlight_attr
[spell_hlf
];
4025 && (p
- nextline
) + cap_col
>= nextline_idx
)
4027 /* Remember that the word in the next line
4028 * must start with a capital. */
4029 capcol_lnum
= lnum
+ 1;
4030 cap_col
= (int)((p
- nextline
) + cap_col
4034 /* Compute the actual column. */
4035 cap_col
+= (int)(prev_ptr
- line
);
4039 if (spell_attr
!= 0)
4042 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
4044 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
4047 #ifdef FEAT_LINEBREAK
4049 * Found last space before word: check for line break.
4051 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
4054 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
4058 1), (colnr_T
)vcol
, NULL
) - 1;
4065 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
4071 extra_attr
= hl_attr(HLF_8
);
4072 saved_attr2
= char_attr
; /* save current attr */
4076 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4089 * Handling of non-printable characters.
4091 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
4094 * when getting a character from the file, we may have to
4095 * turn it into something else on the way to putting it
4096 * into "ScreenLines".
4098 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
4100 /* tab amount depends on current column */
4101 n_extra
= (int)wp
->w_buffer
->b_p_ts
4102 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
4104 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4110 n_attr
= n_extra
+ 1;
4111 extra_attr
= hl_attr(HLF_8
);
4112 saved_attr2
= char_attr
; /* save current attr */
4115 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4130 && ((wp
->w_p_list
&& lcs_eol
> 0)
4131 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4134 && VIsual_mode
!= Ctrl_V
4137 # ifdef FEAT_RIGHTLEFT
4138 wp
->w_p_rl
? (col
>= 0) :
4140 (col
< W_WIDTH(wp
)))
4142 && lnum
== wp
->w_cursor
.lnum
4143 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4144 && lcs_eol_one
>= 0)
4146 /* Display a '$' after the line or highlight an extra
4147 * character if the line break is included. */
4148 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4149 /* For a diff line the highlighting continues after the
4153 diff_hlf
== (hlf_T
)0
4164 #ifdef FEAT_VIRTUALEDIT
4165 /* In virtualedit, visual selections may extend
4166 * beyond end of line. */
4167 if (area_highlighting
&& virtual_active()
4168 && tocol
!= MAXCOL
&& vcol
< tocol
)
4173 p_extra
= at_end_str
;
4183 --ptr
; /* put it back at the NUL */
4186 extra_attr
= hl_attr(HLF_AT
);
4191 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4198 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4203 p_extra
= transchar(c
);
4204 #ifdef FEAT_RIGHTLEFT
4205 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4206 rl_mirror(p_extra
); /* reverse "<12>" */
4208 n_extra
= byte2cells(c
) - 1;
4213 n_attr
= n_extra
+ 1;
4214 extra_attr
= hl_attr(HLF_8
);
4215 saved_attr2
= char_attr
; /* save current attr */
4218 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4221 #ifdef FEAT_VIRTUALEDIT
4222 else if (VIsual_active
4223 && (VIsual_mode
== Ctrl_V
4224 || VIsual_mode
== 'v')
4229 # ifdef FEAT_RIGHTLEFT
4230 wp
->w_p_rl
? (col
>= 0) :
4232 (col
< W_WIDTH(wp
))))
4235 --ptr
; /* put it back at the NUL */
4238 #if defined(LINE_ATTR)
4241 diff_hlf
!= (hlf_T
)0 ||
4245 # ifdef FEAT_RIGHTLEFT
4246 wp
->w_p_rl
? (col
>= 0) :
4248 (col
< W_WIDTH(wp
))))
4250 /* Highlight until the right side of the window */
4252 --ptr
; /* put it back at the NUL */
4254 /* Remember we do the char for line highlighting. */
4257 /* don't do search HL for the rest of the line */
4258 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4259 char_attr
= line_attr
;
4261 if (diff_hlf
== HLF_TXD
)
4264 if (attr
== 0 || char_attr
!= attr
)
4265 char_attr
= hl_attr(diff_hlf
);
4273 /* Don't override visual selection highlighting. */
4275 && draw_state
== WL_LINE
4277 char_attr
= extra_attr
;
4279 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4280 /* XIM don't send preedit_start and preedit_end, but they send
4281 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4282 * im_is_preediting() here. */
4284 && lnum
== wp
->w_cursor
.lnum
4287 && im_is_preediting()
4288 && draw_state
== WL_LINE
)
4292 if (preedit_end_col
== MAXCOL
)
4293 getvcol(curwin
, &(wp
->w_cursor
), &tcol
, NULL
, NULL
);
4295 tcol
= preedit_end_col
;
4296 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4298 if (feedback_old_attr
< 0)
4301 feedback_old_attr
= char_attr
;
4303 char_attr
= im_get_feedback_attr(feedback_col
);
4305 char_attr
= feedback_old_attr
;
4308 else if (feedback_old_attr
>= 0)
4310 char_attr
= feedback_old_attr
;
4311 feedback_old_attr
= -1;
4317 * Handle the case where we are in column 0 but not on the first
4318 * character of the line and the user wants us to show us a
4319 * special character (via 'listchars' option "precedes:<char>".
4321 if (lcs_prec_todo
!= NUL
4322 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4326 && draw_state
> WL_NR
4330 lcs_prec_todo
= NUL
;
4333 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4340 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4344 saved_attr3
= char_attr
; /* save current attr */
4345 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4351 * At end of the text line or just after the last character.
4354 #if defined(LINE_ATTR)
4355 || did_line_attr
== 1
4359 #ifdef FEAT_SEARCH_EXTRA
4360 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4362 /* we're not really at that column when skipping some text */
4363 if ((long)(wp
->w_p_wrap
? wp
->w_skipcol
: wp
->w_leftcol
) > prevcol
)
4367 /* invert at least one char, used for Visual and empty line or
4368 * highlight match at end of line. If it's beyond the last
4369 * char on the screen, just overwrite that one (tricky!) Not
4370 * needed when a '$' was displayed for 'list'. */
4371 #ifdef FEAT_SEARCH_EXTRA
4372 prevcol_hl_flag
= FALSE
;
4373 if (prevcol
== (long)search_hl
.startcol
)
4374 prevcol_hl_flag
= TRUE
;
4377 cur
= wp
->w_match_head
;
4380 if (prevcol
== (long)cur
->hl
.startcol
)
4382 prevcol_hl_flag
= TRUE
;
4389 if (lcs_eol
== lcs_eol_one
4390 && ((area_attr
!= 0 && vcol
== fromcol
4392 && (VIsual_mode
!= Ctrl_V
4393 || lnum
== VIsual
.lnum
4394 || lnum
== curwin
->w_cursor
.lnum
)
4397 #ifdef FEAT_SEARCH_EXTRA
4398 /* highlight 'hlsearch' match at end of line */
4399 || (prevcol_hl_flag
== TRUE
4400 # if defined(LINE_ATTR)
4401 && did_line_attr
<= 1
4409 #ifdef FEAT_RIGHTLEFT
4418 if (col
>= W_WIDTH(wp
))
4423 /* At the window boundary, highlight the last character
4424 * instead (better than nothing). */
4430 /* Add a blank character to highlight. */
4431 ScreenLines
[off
] = ' ';
4434 ScreenLinesUC
[off
] = 0;
4437 #ifdef FEAT_SEARCH_EXTRA
4440 /* Use attributes from match with highest priority among
4441 * 'search_hl' and the match list. */
4442 char_attr
= search_hl
.attr
;
4443 cur
= wp
->w_match_head
;
4445 while (cur
!= NULL
|| shl_flag
== FALSE
)
4447 if (shl_flag
== FALSE
4449 && cur
->priority
> SEARCH_HL_PRIORITY
)
4457 if ((ptr
- line
) - 1 == (long)shl
->startcol
)
4458 char_attr
= shl
->attr
;
4459 if (shl
!= &search_hl
&& cur
!= NULL
)
4464 ScreenAttrs
[off
] = char_attr
;
4465 #ifdef FEAT_RIGHTLEFT
4485 * At end of the text line.
4490 if (eol_hl_off
> 0 && vcol
- eol_hl_off
== (long)wp
->w_virtcol
4491 && lnum
== wp
->w_cursor
.lnum
)
4493 /* highlight last char after line */
4499 /* Highlight 'cursorcolumn' past end of the line. */
4504 /* check if line ends before left margin */
4505 if (vcol
< v
+ col
- win_col_off(wp
))
4507 vcol
= v
+ col
- win_col_off(wp
);
4509 && (int)wp
->w_virtcol
>= vcol
- eol_hl_off
4510 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4512 && lnum
!= wp
->w_cursor
.lnum
4513 # ifdef FEAT_RIGHTLEFT
4518 while (col
< W_WIDTH(wp
))
4520 ScreenLines
[off
] = ' ';
4523 ScreenLinesUC
[off
] = 0;
4526 if (vcol
== (long)wp
->w_virtcol
)
4528 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4531 ScreenAttrs
[off
++] = 0;
4537 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4542 * Update w_cline_height and w_cline_folded if the cursor line was
4543 * updated (saves a call to plines() later).
4545 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4547 curwin
->w_cline_row
= startrow
;
4548 curwin
->w_cline_height
= row
- startrow
;
4550 curwin
->w_cline_folded
= FALSE
;
4552 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4558 /* line continues beyond line end */
4565 #ifdef FEAT_RIGHTLEFT
4566 wp
->w_p_rl
? col
== 0 :
4568 col
== W_WIDTH(wp
) - 1)
4570 || (wp
->w_p_list
&& lcs_eol_one
> 0)
4571 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4574 char_attr
= hl_attr(HLF_AT
);
4577 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4589 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4590 * highlight the cursor position itself. */
4591 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4592 && lnum
!= wp
->w_cursor
.lnum
4593 && draw_state
== WL_LINE
4594 && !lnum_in_visual_area
)
4596 vcol_save_attr
= char_attr
;
4597 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4600 vcol_save_attr
= -1;
4604 * Store character to be displayed.
4605 * Skip characters that are left of the screen for 'nowrap'.
4608 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4611 * Store the character.
4613 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4614 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4616 /* A double-wide character is: put first halve in left cell. */
4621 ScreenLines
[off
] = c
;
4623 if (enc_dbcs
== DBCS_JPNU
)
4624 ScreenLines2
[off
] = mb_c
& 0xff;
4631 ScreenLinesUC
[off
] = mb_c
;
4632 if ((c
& 0xff) == 0)
4633 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4634 for (i
= 0; i
< Screen_mco
; ++i
)
4636 ScreenLinesC
[i
][off
] = u8cc
[i
];
4642 ScreenLinesUC
[off
] = 0;
4646 ScreenAttrs
[off
] = multi_attr
;
4651 ScreenAttrs
[off
] = char_attr
;
4654 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4656 /* Need to fill two screen columns. */
4660 /* UTF-8: Put a 0 in the second screen char. */
4661 ScreenLines
[off
] = 0;
4663 /* DBCS: Put second byte in the second screen char. */
4664 ScreenLines
[off
] = mb_c
& 0xff;
4666 /* When "tocol" is halfway a character, set it to the end of
4667 * the character, otherwise highlighting won't stop. */
4670 #ifdef FEAT_RIGHTLEFT
4673 /* now it's time to backup one cell */
4680 #ifdef FEAT_RIGHTLEFT
4696 /* Only advance the "vcol" when after the 'number' column. */
4697 if (draw_state
> WL_NR
4705 if (vcol_save_attr
>= 0)
4706 char_attr
= vcol_save_attr
;
4709 /* restore attributes after "predeces" in 'listchars' */
4710 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4711 char_attr
= saved_attr3
;
4713 /* restore attributes after last 'listchars' or 'number' char */
4714 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4715 char_attr
= saved_attr2
;
4718 * At end of screen line and there is more to come: Display the line
4719 * so far. If there is no more to display it is caught above.
4722 #ifdef FEAT_RIGHTLEFT
4723 wp
->w_p_rl
? (col
< 0) :
4725 (col
>= W_WIDTH(wp
)))
4730 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4731 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4734 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4739 /* When not wrapping and finished diff lines, or when displayed
4740 * '$' and highlighting until last column, break here. */
4745 ) || lcs_eol_one
== -1)
4748 /* When the window is too narrow draw all "@" lines. */
4749 if (draw_state
!= WL_LINE
4755 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4756 #ifdef FEAT_VERTSPLIT
4757 draw_vsep_win(wp
, row
);
4762 /* When line got too long for screen break here. */
4769 if (screen_cur_row
== screen_row
- 1
4773 && W_WIDTH(wp
) == Columns
)
4775 /* Remember that the line wraps, used for modeless copy. */
4776 LineWraps
[screen_row
- 1] = TRUE
;
4779 * Special trick to make copy/paste of wrapped lines work with
4780 * xterm/screen: write an extra character beyond the end of
4781 * the line. This will work with all terminal types
4782 * (regardless of the xn,am settings).
4783 * Only do this on a fast tty.
4784 * Only do this if the cursor is on the current line
4785 * (something has been written in it).
4786 * Don't do this for the GUI.
4787 * Don't do this for double-width characters.
4788 * Don't do this for a window not at the right screen border.
4796 && ((*mb_off2cells
)(LineOffset
[screen_row
],
4797 LineOffset
[screen_row
] + screen_Columns
)
4799 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4801 LineOffset
[screen_row
] + screen_Columns
)
4806 /* First make sure we are at the end of the screen line,
4807 * then output the same character again to let the
4808 * terminal know about the wrap. If the terminal doesn't
4809 * auto-wrap, we overwrite the character. */
4810 if (screen_cur_col
!= W_WIDTH(wp
))
4811 screen_char(LineOffset
[screen_row
- 1]
4812 + (unsigned)Columns
- 1,
4813 screen_row
- 1, (int)(Columns
- 1));
4816 /* When there is a multi-byte character, just output a
4817 * space to keep it simple. */
4818 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4819 screen_row
- 1] + (Columns
- 1)]) > 1)
4823 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4825 /* force a redraw of the first char on the next line */
4826 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4827 screen_start(); /* don't know where cursor is now */
4832 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4833 #ifdef FEAT_RIGHTLEFT
4836 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4841 /* reset the drawing state for the start of a wrapped line */
4842 draw_state
= WL_START
;
4843 saved_n_extra
= n_extra
;
4844 saved_p_extra
= p_extra
;
4845 saved_c_extra
= c_extra
;
4846 saved_char_attr
= char_attr
;
4848 lcs_prec_todo
= lcs_prec
;
4849 #ifdef FEAT_LINEBREAK
4851 if (filler_todo
<= 0)
4853 need_showbreak
= TRUE
;
4857 /* When the filler lines are actually below the last line of the
4858 * file, don't draw the line itself, break here. */
4859 if (filler_todo
== 0 && wp
->w_botfill
)
4864 } /* for every character in the line */
4867 /* After an empty line check first word for capital. */
4868 if (*skipwhite(line
) == NUL
)
4870 capcol_lnum
= lnum
+ 1;
4879 static int comp_char_differs
__ARGS((int, int));
4882 * Return if the composing characters at "off_from" and "off_to" differ.
4885 comp_char_differs(off_from
, off_to
)
4891 for (i
= 0; i
< Screen_mco
; ++i
)
4893 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4895 if (ScreenLinesC
[i
][off_from
] == 0)
4903 * Check whether the given character needs redrawing:
4904 * - the (first byte of the) character is different
4905 * - the attributes are different
4906 * - the character is multi-byte and the next byte is different
4907 * - the character is two cells wide and the second cell differs.
4910 char_needs_redraw(off_from
, off_to
, cols
)
4916 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4917 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4921 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4922 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4923 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4924 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4925 != ScreenLines
[off_to
+ 1])))
4927 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4928 || (ScreenLinesUC
[off_from
] != 0
4929 && comp_char_differs(off_from
, off_to
))
4930 || (cols
> 1 && ScreenLines
[off_from
+ 1]
4931 != ScreenLines
[off_to
+ 1])))
4939 * Move one "cooked" screen line to the screen, but only the characters that
4940 * have actually changed. Handle insert/delete character.
4941 * "coloff" gives the first column on the screen for this line.
4942 * "endcol" gives the columns where valid characters are.
4943 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4944 * needs to be cleared, negative otherwise.
4945 * "rlflag" is TRUE in a rightleft window:
4946 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4947 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4950 screen_line(row
, coloff
, endcol
, clear_width
4951 #ifdef FEAT_RIGHTLEFT
4959 #ifdef FEAT_RIGHTLEFT
4966 unsigned max_off_from
;
4967 unsigned max_off_to
;
4970 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4973 int force
= FALSE
; /* force update rest of the line */
4974 int redraw_this
/* bool: does character need redraw? */
4976 = TRUE
/* For GUI when while-loop empty */
4979 int redraw_next
; /* redraw_this for next character */
4981 int clear_next
= FALSE
;
4982 int char_cells
; /* 1: normal char */
4983 /* 2: occupies two display cells */
4984 # define CHAR_CELLS char_cells
4986 # define CHAR_CELLS 1
4989 # ifdef FEAT_CLIPBOARD
4990 clip_may_clear_selection(row
, row
);
4993 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
4994 off_to
= LineOffset
[row
] + coloff
;
4996 max_off_from
= off_from
+ screen_Columns
;
4997 max_off_to
= LineOffset
[row
] + screen_Columns
;
5000 #ifdef FEAT_RIGHTLEFT
5003 /* Clear rest first, because it's left of the text. */
5004 if (clear_width
> 0)
5006 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
5007 && ScreenAttrs
[off_to
] == 0
5009 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5017 screen_fill(row
, row
+ 1, col
+ coloff
,
5018 endcol
+ coloff
+ 1, ' ', ' ', 0);
5021 off_to
= LineOffset
[row
] + col
+ coloff
;
5023 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
5025 #endif /* FEAT_RIGHTLEFT */
5027 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
5029 while (col
< endcol
)
5032 if (has_mbyte
&& (col
+ 1 < endcol
))
5033 char_cells
= (*mb_off2cells
)(off_from
, max_off_from
);
5038 redraw_this
= redraw_next
;
5039 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
5040 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
5043 /* If the next character was bold, then redraw the current character to
5044 * remove any pixels that might have spilt over into us. This only
5045 * happens in the GUI.
5047 if (redraw_next
&& gui
.in_use
)
5049 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
5051 hl
= syn_attr2attr(hl
);
5060 * Special handling when 'xs' termcap flag set (hpterm):
5061 * Attributes for characters are stored at the position where the
5062 * cursor is when writing the highlighting code. The
5063 * start-highlighting code must be written with the cursor on the
5064 * first highlighted character. The stop-highlighting code must
5065 * be written with the cursor just after the last highlighted
5067 * Overwriting a character doesn't remove it's highlighting. Need
5068 * to clear the rest of the line, and force redrawing it
5076 && ScreenAttrs
[off_to
] != 0
5077 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
5080 * Need to remove highlighting attributes here.
5082 windgoto(row
, col
+ coloff
);
5083 out_str(T_CE
); /* clear rest of this screen line */
5084 screen_start(); /* don't know where cursor is now */
5085 force
= TRUE
; /* force redraw of rest of the line */
5086 redraw_next
= TRUE
; /* or else next char would miss out */
5089 * If the previous character was highlighted, need to stop
5090 * highlighting at this character.
5092 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
5094 screen_attr
= ScreenAttrs
[off_to
- 1];
5095 term_windgoto(row
, col
+ coloff
);
5096 screen_stop_highlight();
5099 screen_attr
= 0; /* highlighting has stopped */
5104 /* Check if overwriting a double-byte with a single-byte or
5105 * the other way around requires another character to be
5106 * redrawn. For UTF-8 this isn't needed, because comparing
5107 * ScreenLinesUC[] is sufficient. */
5110 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5112 /* Writing a single-cell character over a double-cell
5113 * character: need to redraw the next cell. */
5114 ScreenLines
[off_to
+ 1] = 0;
5117 else if (char_cells
== 2
5119 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5120 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)
5122 /* Writing the second half of a double-cell character over
5123 * a double-cell character: need to redraw the second
5125 ScreenLines
[off_to
+ 2] = 0;
5129 if (enc_dbcs
== DBCS_JPNU
)
5130 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
5132 /* When writing a single-width character over a double-width
5133 * character and at the end of the redrawn text, need to clear out
5134 * the right halve of the old character.
5135 * Also required when writing the right halve of a double-width
5136 * char over the left halve of an existing one. */
5137 if (has_mbyte
&& col
+ char_cells
== endcol
5138 && ((char_cells
== 1
5139 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5141 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5142 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)))
5146 ScreenLines
[off_to
] = ScreenLines
[off_from
];
5150 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
5151 if (ScreenLinesUC
[off_from
] != 0)
5155 for (i
= 0; i
< Screen_mco
; ++i
)
5156 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
5159 if (char_cells
== 2)
5160 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
5163 #if defined(FEAT_GUI) || defined(UNIX)
5164 /* The bold trick makes a single column of pixels appear in the
5165 * next character. When a bold character is removed, the next
5166 * character should be redrawn too. This happens for our own GUI
5167 * and for some xterms. */
5172 # if defined(FEAT_GUI) && defined(UNIX)
5180 hl
= ScreenAttrs
[off_to
];
5182 hl
= syn_attr2attr(hl
);
5187 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5189 /* For simplicity set the attributes of second half of a
5190 * double-wide character equal to the first half. */
5191 if (char_cells
== 2)
5192 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5194 if (enc_dbcs
!= 0 && char_cells
== 2)
5195 screen_char_2(off_to
, row
, col
+ coloff
);
5198 screen_char(off_to
, row
, col
+ coloff
);
5204 && col
+ coloff
> 0)
5206 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5209 * Don't output stop-highlight when moving the cursor, it will
5210 * stop the highlighting when it should continue.
5214 else if (screen_attr
!= 0)
5215 screen_stop_highlight();
5218 off_to
+= CHAR_CELLS
;
5219 off_from
+= CHAR_CELLS
;
5226 /* Clear the second half of a double-wide character of which the left
5227 * half was overwritten with a single-wide character. */
5228 ScreenLines
[off_to
] = ' ';
5230 ScreenLinesUC
[off_to
] = 0;
5231 screen_char(off_to
, row
, col
+ coloff
);
5236 #ifdef FEAT_RIGHTLEFT
5245 /* blank out the rest of the line */
5246 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5247 && ScreenAttrs
[off_to
] == 0
5249 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5256 if (col
< clear_width
)
5260 * In the GUI, clearing the rest of the line may leave pixels
5261 * behind if the first character cleared was bold. Some bold
5262 * fonts spill over the left. In this case we redraw the previous
5263 * character too. If we didn't skip any blanks above, then we
5264 * only redraw if the character wasn't already redrawn anyway.
5266 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5268 hl
= ScreenAttrs
[off_to
];
5269 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5274 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5275 * that its width is 2. */
5276 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5277 else if (enc_dbcs
!= 0)
5279 /* find previous character by counting from first
5280 * column and get its width. */
5281 unsigned off
= LineOffset
[row
];
5282 unsigned max_off
= LineOffset
[row
] + screen_Columns
;
5284 while (off
< off_to
)
5286 prev_cells
= (*mb_off2cells
)(off
, max_off
);
5291 if (enc_dbcs
!= 0 && prev_cells
> 1)
5292 screen_char_2(off_to
- prev_cells
, row
,
5293 col
+ coloff
- prev_cells
);
5296 screen_char(off_to
- prev_cells
, row
,
5297 col
+ coloff
- prev_cells
);
5301 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5303 #ifdef FEAT_VERTSPLIT
5304 off_to
+= clear_width
- col
;
5310 if (clear_width
> 0)
5312 #ifdef FEAT_VERTSPLIT
5313 /* For a window that's left of another, draw the separator char. */
5314 if (col
+ coloff
< Columns
)
5318 c
= fillchar_vsep(&hl
);
5319 if (ScreenLines
[off_to
] != c
5321 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5322 != (c
>= 0x80 ? c
: 0))
5324 || ScreenAttrs
[off_to
] != hl
)
5326 ScreenLines
[off_to
] = c
;
5327 ScreenAttrs
[off_to
] = hl
;
5333 ScreenLinesUC
[off_to
] = c
;
5334 ScreenLinesC
[0][off_to
] = 0;
5337 ScreenLinesUC
[off_to
] = 0;
5340 screen_char(off_to
, row
, col
+ coloff
);
5345 LineWraps
[row
] = FALSE
;
5349 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5351 * Mirror text "str" for right-left displaying.
5352 * Only works for single-byte characters (e.g., numbers).
5361 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5370 #if defined(FEAT_WINDOWS) || defined(PROTO)
5372 * mark all status lines for redraw; used after first :cd
5379 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5380 if (wp
->w_status_height
)
5382 wp
->w_redr_status
= TRUE
;
5383 redraw_later(VALID
);
5388 * mark all status lines of the current buffer for redraw
5391 status_redraw_curbuf()
5395 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5396 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5398 wp
->w_redr_status
= TRUE
;
5399 redraw_later(VALID
);
5404 * Redraw all status lines that need to be redrawn.
5407 redraw_statuslines()
5411 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5412 if (wp
->w_redr_status
)
5413 win_redr_status(wp
);
5419 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5421 * Redraw all status lines at the bottom of frame "frp".
5424 win_redraw_last_status(frp
)
5427 if (frp
->fr_layout
== FR_LEAF
)
5428 frp
->fr_win
->w_redr_status
= TRUE
;
5429 else if (frp
->fr_layout
== FR_ROW
)
5431 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5432 win_redraw_last_status(frp
);
5434 else /* frp->fr_layout == FR_COL */
5436 frp
= frp
->fr_child
;
5437 while (frp
->fr_next
!= NULL
)
5439 win_redraw_last_status(frp
);
5444 #ifdef FEAT_VERTSPLIT
5446 * Draw the verticap separator right of window "wp" starting with line "row".
5449 draw_vsep_win(wp
, row
)
5456 if (wp
->w_vsep_width
)
5458 /* draw the vertical separator right of this window */
5459 c
= fillchar_vsep(&hl
);
5460 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5461 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5467 #ifdef FEAT_WILDMENU
5468 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5469 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5472 * Get the length of an item as it will be shown in the status line.
5475 status_match_len(xp
, s
)
5482 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5483 || xp
->xp_context
== EXPAND_MENUNAMES
);
5485 /* Check for menu separators - replace with '|'. */
5486 if (emenu
&& menu_is_separator(s
))
5492 s
+= skip_status_match_char(xp
, s
);
5493 len
+= ptr2cells(s
);
5501 * Return the number of characters that should be skipped in a status match.
5502 * These are backslashes used for escaping. Do show backslashes in help tags.
5505 skip_status_match_char(xp
, s
)
5509 if ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5511 || ((xp
->xp_context
== EXPAND_MENUS
5512 || xp
->xp_context
== EXPAND_MENUNAMES
)
5513 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5517 #ifndef BACKSLASH_IN_FILENAME
5518 if (xp
->xp_shell
&& csh_like_shell() && s
[1] == '\\' && s
[2] == '!')
5527 * Show wildchar matches in the status line.
5528 * Show at least the "match" item.
5529 * We start at item 'first_match' in the list and show all matches that fit.
5531 * If inversion is possible we use it. Else '=' characters are used.
5534 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5537 char_u
**matches
; /* list of matches */
5541 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5545 int clen
; /* length in screen cells */
5549 int highlight
= TRUE
;
5550 char_u
*selstart
= NULL
;
5551 int selstart_col
= 0;
5552 char_u
*selend
= NULL
;
5553 static int first_match
= 0;
5554 int add_left
= FALSE
;
5559 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5563 if (matches
== NULL
) /* interrupted completion? */
5568 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5571 buf
= alloc((unsigned)Columns
+ 1);
5575 if (match
== -1) /* don't show match but original text */
5580 /* count 1 for the ending ">" */
5581 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5584 else if (match
< first_match
)
5586 /* jumping left, as far as we can go */
5587 first_match
= match
;
5592 /* check if match fits on the screen */
5593 for (i
= first_match
; i
< match
; ++i
)
5594 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5595 if (first_match
> 0)
5597 /* jumping right, put match at the left */
5598 if ((long)clen
> Columns
)
5600 first_match
= match
;
5601 /* if showing the last match, we can add some on the left */
5603 for (i
= match
; i
< num_matches
; ++i
)
5605 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5606 if ((long)clen
>= Columns
)
5609 if (i
== num_matches
)
5614 while (first_match
> 0)
5616 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5617 if ((long)clen
>= Columns
)
5622 fillchar
= fillchar_status(&attr
, TRUE
);
5624 if (first_match
== 0)
5637 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5641 selstart
= buf
+ len
;
5642 selstart_col
= clen
;
5646 /* Check for menu separators - replace with '|' */
5648 emenu
= (xp
->xp_context
== EXPAND_MENUS
5649 || xp
->xp_context
== EXPAND_MENUNAMES
);
5650 if (emenu
&& menu_is_separator(s
))
5652 STRCPY(buf
+ len
, transchar('|'));
5653 l
= (int)STRLEN(buf
+ len
);
5659 for ( ; *s
!= NUL
; ++s
)
5661 s
+= skip_status_match_char(xp
, s
);
5662 clen
+= ptr2cells(s
);
5664 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5666 STRNCPY(buf
+ len
, s
, l
);
5673 STRCPY(buf
+ len
, transchar_byte(*s
));
5674 len
+= (int)STRLEN(buf
+ len
);
5680 *(buf
+ len
++) = ' ';
5681 *(buf
+ len
++) = ' ';
5683 if (++i
== num_matches
)
5687 if (i
!= num_matches
)
5689 *(buf
+ len
++) = '>';
5695 row
= cmdline_row
- 1;
5698 if (wild_menu_showing
== 0)
5700 if (msg_scrolled
> 0)
5702 /* Put the wildmenu just above the command line. If there is
5703 * no room, scroll the screen one line up. */
5704 if (cmdline_row
== Rows
- 1)
5706 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5714 wild_menu_showing
= WM_SCROLLED
;
5718 /* Create status line if needed by setting 'laststatus' to 2.
5719 * Set 'winminheight' to zero to avoid that the window is
5721 if (lastwin
->w_status_height
== 0)
5729 wild_menu_showing
= WM_SHOWN
;
5733 screen_puts(buf
, row
, 0, attr
);
5734 if (selstart
!= NULL
&& highlight
)
5737 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5740 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5743 #ifdef FEAT_VERTSPLIT
5744 win_redraw_last_status(topframe
);
5746 lastwin
->w_redr_status
= TRUE
;
5752 #if defined(FEAT_WINDOWS) || defined(PROTO)
5754 * Redraw the status line of window wp.
5756 * If inversion is possible we use it. Else '=' characters are used.
5768 static int busy
= FALSE
;
5770 /* It's possible to get here recursively when 'statusline' (indirectly)
5771 * invokes ":redrawstatus". Simply ignore the call then. */
5776 wp
->w_redr_status
= FALSE
;
5777 if (wp
->w_status_height
== 0)
5779 /* no status line, can only be last window */
5780 redraw_cmdline
= TRUE
;
5782 else if (!redrawing()
5783 #ifdef FEAT_INS_EXPAND
5784 /* don't update status line when popup menu is visible and may be
5790 /* Don't redraw right now, do it later. */
5791 wp
->w_redr_status
= TRUE
;
5794 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5796 /* redraw custom status line */
5797 redraw_custom_statusline(wp
);
5802 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5804 get_trans_bufname(wp
->w_buffer
);
5806 len
= (int)STRLEN(p
);
5808 if (wp
->w_buffer
->b_help
5809 #ifdef FEAT_QUICKFIX
5812 || bufIsChanged(wp
->w_buffer
)
5813 || wp
->w_buffer
->b_p_ro
)
5815 if (wp
->w_buffer
->b_help
)
5817 STRCPY(p
+ len
, _("[Help]"));
5818 len
+= (int)STRLEN(p
+ len
);
5820 #ifdef FEAT_QUICKFIX
5823 STRCPY(p
+ len
, _("[Preview]"));
5824 len
+= (int)STRLEN(p
+ len
);
5827 if (bufIsChanged(wp
->w_buffer
))
5829 STRCPY(p
+ len
, "[+]");
5832 if (wp
->w_buffer
->b_p_ro
)
5834 STRCPY(p
+ len
, "[RO]");
5838 #ifndef FEAT_VERTSPLIT
5839 this_ru_col
= ru_col
;
5840 if (this_ru_col
< (Columns
+ 1) / 2)
5841 this_ru_col
= (Columns
+ 1) / 2;
5843 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5844 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5845 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5846 if (this_ru_col
<= 1)
5848 p
= (char_u
*)"<"; /* No room for file name! */
5858 /* Count total number of display cells. */
5859 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5860 clen
+= (*mb_ptr2cells
)(p
+ i
);
5861 /* Find first character that will fit.
5862 * Going from start to end is much faster for DBCS. */
5863 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5864 i
+= (*mb_ptr2len
)(p
+ i
))
5865 clen
-= (*mb_ptr2cells
)(p
+ i
);
5877 if (len
> this_ru_col
- 1)
5879 p
+= len
- (this_ru_col
- 1);
5881 len
= this_ru_col
- 1;
5884 row
= W_WINROW(wp
) + wp
->w_height
;
5885 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5886 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5887 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5889 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5890 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5891 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5892 - 1 + W_WINCOL(wp
)), attr
);
5894 #ifdef FEAT_CMDL_INFO
5895 win_redr_ruler(wp
, TRUE
);
5899 #ifdef FEAT_VERTSPLIT
5901 * May need to draw the character below the vertical separator.
5903 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5905 if (stl_connected(wp
))
5906 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5908 fillchar
= fillchar_vsep(&attr
);
5909 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5918 * Redraw the status line according to 'statusline' and take care of any
5919 * errors encountered.
5922 redraw_custom_statusline(wp
)
5925 static int entered
= FALSE
;
5926 int save_called_emsg
= called_emsg
;
5928 /* When called recursively return. This can happen when the statusline
5929 * contains an expression that triggers a redraw. */
5934 called_emsg
= FALSE
;
5935 win_redr_custom(wp
, FALSE
);
5938 /* When there is an error disable the statusline, otherwise the
5939 * display is messed up with errors and a redraw triggers the problem
5940 * again and again. */
5941 set_string_option_direct((char_u
*)"statusline", -1,
5942 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5943 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5945 called_emsg
|= save_called_emsg
;
5950 # ifdef FEAT_VERTSPLIT
5952 * Return TRUE if the status line of window "wp" is connected to the status
5953 * line of the window right of it. If not, then it's a vertical separator.
5954 * Only call if (wp->w_vsep_width != 0).
5963 while (fr
->fr_parent
!= NULL
)
5965 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5967 if (fr
->fr_next
!= NULL
)
5972 if (fr
->fr_next
!= NULL
)
5981 #endif /* FEAT_WINDOWS */
5983 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
5985 * Get the value to show for the language mappings, active 'keymap'.
5988 get_keymap_str(wp
, buf
, len
)
5990 char_u
*buf
; /* buffer for the result */
5991 int len
; /* length of buffer */
5995 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
6000 buf_T
*old_curbuf
= curbuf
;
6001 win_T
*old_curwin
= curwin
;
6004 curbuf
= wp
->w_buffer
;
6006 STRCPY(buf
, "b:keymap_name"); /* must be writable */
6008 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
6010 curbuf
= old_curbuf
;
6011 curwin
= old_curwin
;
6012 if (p
== NULL
|| *p
== NUL
)
6016 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
6017 p
= wp
->w_buffer
->b_p_keymap
;
6020 p
= (char_u
*)"lang";
6022 if ((int)(STRLEN(p
) + 3) < len
)
6023 sprintf((char *)buf
, "<%s>", p
);
6030 return buf
[0] != NUL
;
6034 #if defined(FEAT_STL_OPT) || defined(PROTO)
6036 * Redraw the status line or ruler of window "wp".
6037 * When "wp" is NULL redraw the tab pages line from 'tabline'.
6040 win_redr_custom(wp
, draw_ruler
)
6042 int draw_ruler
; /* TRUE or FALSE */
6053 char_u buf
[MAXPATHL
];
6056 struct stl_hlrec hltab
[STL_MAX_ITEM
];
6057 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
6058 int use_sandbox
= FALSE
;
6060 /* setup environment for the task at hand */
6063 /* Use 'tabline'. Always at the first line of the screen. */
6067 attr
= hl_attr(HLF_TPF
);
6070 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
6075 row
= W_WINROW(wp
) + wp
->w_height
;
6076 fillchar
= fillchar_status(&attr
, wp
== curwin
);
6077 maxwidth
= W_WIDTH(wp
);
6082 /* advance past any leading group spec - implicit in ru_col */
6087 if (atoi((char *)stl
))
6088 while (VIM_ISDIGIT(*stl
))
6093 #ifdef FEAT_VERTSPLIT
6094 col
= ru_col
- (Columns
- W_WIDTH(wp
));
6095 if (col
< (W_WIDTH(wp
) + 1) / 2)
6096 col
= (W_WIDTH(wp
) + 1) / 2;
6099 if (col
> (Columns
+ 1) / 2)
6100 col
= (Columns
+ 1) / 2;
6102 maxwidth
= W_WIDTH(wp
) - col
;
6104 if (!wp
->w_status_height
)
6108 --maxwidth
; /* writing in last column may cause scrolling */
6114 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
6119 if (*wp
->w_p_stl
!= NUL
)
6124 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
6125 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
6129 #ifdef FEAT_VERTSPLIT
6130 col
+= W_WINCOL(wp
);
6137 /* Make a copy, because the statusline may include a function call that
6138 * might change the option value and free the memory. */
6139 stl
= vim_strsave(stl
);
6140 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
6143 fillchar
, maxwidth
, hltab
, tabtab
);
6145 len
= (int)STRLEN(buf
);
6147 while (width
< maxwidth
&& len
< (int)sizeof(buf
) - 1)
6150 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
6152 buf
[len
++] = fillchar
;
6159 * Draw each snippet with the specified highlighting.
6163 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
6165 len
= (int)(hltab
[n
].start
- p
);
6166 screen_puts_len(p
, len
, row
, col
, curattr
);
6167 col
+= vim_strnsize(p
, len
);
6170 if (hltab
[n
].userhl
== 0)
6172 else if (hltab
[n
].userhl
< 0)
6173 curattr
= syn_id2attr(-hltab
[n
].userhl
);
6175 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
6176 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
6179 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
6181 screen_puts(p
, row
, col
, curattr
);
6185 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6190 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
6192 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
6194 TabPageIdxs
[col
++] = fillchar
;
6195 p
= tabtab
[n
].start
;
6196 fillchar
= tabtab
[n
].userhl
;
6198 while (col
< Columns
)
6199 TabPageIdxs
[col
++] = fillchar
;
6203 #endif /* FEAT_STL_OPT */
6206 * Output a single character directly to the screen and update ScreenLines.
6209 screen_putchar(c
, row
, col
, attr
)
6215 char_u buf
[MB_MAXBYTES
+ 1];
6217 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6224 screen_puts(buf
, row
, col
, attr
);
6228 * Get a single character directly from ScreenLines into "bytes[]".
6229 * Also return its attribute in *attrp;
6232 screen_getbytes(row
, col
, bytes
, attrp
)
6240 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6242 off
= LineOffset
[row
] + col
;
6243 *attrp
= ScreenAttrs
[off
];
6244 bytes
[0] = ScreenLines
[off
];
6248 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6249 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6250 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6252 bytes
[0] = ScreenLines
[off
];
6253 bytes
[1] = ScreenLines2
[off
];
6256 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6258 bytes
[1] = ScreenLines
[off
+ 1];
6266 static int screen_comp_differs
__ARGS((int, int*));
6269 * Return TRUE if composing characters for screen posn "off" differs from
6270 * composing characters in "u8cc".
6273 screen_comp_differs(off
, u8cc
)
6279 for (i
= 0; i
< Screen_mco
; ++i
)
6281 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6291 * Put string '*text' on the screen at position 'row' and 'col', with
6292 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6293 * Note: only outputs within one row, message is truncated at screen boundary!
6294 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6297 screen_puts(text
, row
, col
, attr
)
6303 screen_puts_len(text
, -1, row
, col
, attr
);
6307 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6311 screen_puts_len(text
, len
, row
, col
, attr
)
6324 int mbyte_cells
= 1;
6327 int clear_next_cell
= FALSE
;
6329 int prev_c
= 0; /* previous Arabic character */
6334 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6335 int force_redraw_this
;
6336 int force_redraw_next
= FALSE
;
6340 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6342 off
= LineOffset
[row
] + col
;
6345 /* When drawing over the right halve of a double-wide char clear out the
6346 * left halve. Only needed in a terminal. */
6347 if (has_mbyte
&& col
> 0 && col
< screen_Columns
6351 && mb_fix_col(col
, row
) != col
)
6353 ScreenLines
[off
- 1] = ' ';
6354 ScreenAttrs
[off
- 1] = 0;
6357 ScreenLinesUC
[off
- 1] = 0;
6358 ScreenLinesC
[0][off
- 1] = 0;
6360 /* redraw the previous cell, make it empty */
6361 screen_char(off
- 1, row
, col
- 1);
6362 /* force the cell at "col" to be redrawn */
6363 force_redraw_next
= TRUE
;
6368 max_off
= LineOffset
[row
] + screen_Columns
;
6370 while (col
< screen_Columns
6371 && (len
< 0 || (int)(ptr
- text
) < len
)
6376 /* check if this is the first byte of a multibyte */
6379 if (enc_utf8
&& len
> 0)
6380 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6382 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6383 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6385 else if (enc_dbcs
!= 0)
6386 mbyte_cells
= mbyte_blen
;
6390 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6391 (int)((text
+ len
) - ptr
));
6393 u8c
= utfc_ptr2char(ptr
, u8cc
);
6394 mbyte_cells
= utf_char2cells(u8c
);
6396 /* Non-BMP character: display as ? or fullwidth ?. */
6399 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6401 attr
= hl_attr(HLF_8
);
6405 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6407 /* Do Arabic shaping. */
6408 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6410 /* Past end of string to be displayed. */
6416 nc
= utfc_ptr2char_len(ptr
+ mbyte_blen
, pcc
,
6417 (int)((text
+ len
) - ptr
- mbyte_blen
));
6422 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6431 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6432 force_redraw_this
= force_redraw_next
;
6433 force_redraw_next
= FALSE
;
6436 need_redraw
= ScreenLines
[off
] != c
6438 || (mbyte_cells
== 2
6439 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6440 || (enc_dbcs
== DBCS_JPNU
6442 && ScreenLines2
[off
] != ptr
[1])
6444 && (ScreenLinesUC
[off
] != (u8char_T
)(c
>= 0x80 ? u8c
: 0)
6445 || screen_comp_differs(off
, u8cc
)))
6447 || ScreenAttrs
[off
] != attr
6451 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6452 || force_redraw_this
6456 #if defined(FEAT_GUI) || defined(UNIX)
6457 /* The bold trick makes a single row of pixels appear in the next
6458 * character. When a bold character is removed, the next
6459 * character should be redrawn too. This happens for our own GUI
6460 * and for some xterms. */
6461 if (need_redraw
&& ScreenLines
[off
] != ' ' && (
6465 # if defined(FEAT_GUI) && defined(UNIX)
6473 int n
= ScreenAttrs
[off
];
6476 n
= syn_attr2attr(n
);
6478 force_redraw_next
= TRUE
;
6482 /* When at the end of the text and overwriting a two-cell
6483 * character with a one-cell character, need to clear the next
6484 * cell. Also when overwriting the left halve of a two-cell char
6485 * with the right halve of a two-cell char. Do this only once
6486 * (mb_off2cells() may return 2 on the right halve). */
6487 if (clear_next_cell
)
6488 clear_next_cell
= FALSE
;
6490 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6491 : ptr
+ mbyte_blen
>= text
+ len
)
6492 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6493 || (mbyte_cells
== 2
6494 && (*mb_off2cells
)(off
, max_off
) == 1
6495 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6496 clear_next_cell
= TRUE
;
6498 /* Make sure we never leave a second byte of a double-byte behind,
6499 * it confuses mb_off2cells(). */
6501 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6502 || (mbyte_cells
== 2
6503 && (*mb_off2cells
)(off
, max_off
) == 1
6504 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6505 ScreenLines
[off
+ mbyte_blen
] = 0;
6507 ScreenLines
[off
] = c
;
6508 ScreenAttrs
[off
] = attr
;
6512 if (c
< 0x80 && u8cc
[0] == 0)
6513 ScreenLinesUC
[off
] = 0;
6518 ScreenLinesUC
[off
] = u8c
;
6519 for (i
= 0; i
< Screen_mco
; ++i
)
6521 ScreenLinesC
[i
][off
] = u8cc
[i
];
6526 if (mbyte_cells
== 2)
6528 ScreenLines
[off
+ 1] = 0;
6529 ScreenAttrs
[off
+ 1] = attr
;
6531 screen_char(off
, row
, col
);
6533 else if (mbyte_cells
== 2)
6535 ScreenLines
[off
+ 1] = ptr
[1];
6536 ScreenAttrs
[off
+ 1] = attr
;
6537 screen_char_2(off
, row
, col
);
6539 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6541 ScreenLines2
[off
] = ptr
[1];
6542 screen_char(off
, row
, col
);
6546 screen_char(off
, row
, col
);
6554 if (clear_next_cell
)
6555 ptr
= (char_u
*)" ";
6566 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6567 /* If we detected the next character needs to be redrawn, but the text
6568 * doesn't extend up to there, update the character here. */
6569 if (force_redraw_next
&& col
< screen_Columns
)
6572 if (enc_dbcs
!= 0 && dbcs_off2cells(off
, max_off
) > 1)
6573 screen_char_2(off
, row
, col
);
6576 screen_char(off
, row
, col
);
6581 #ifdef FEAT_SEARCH_EXTRA
6583 * Prepare for 'hlsearch' highlighting.
6588 if (p_hls
&& !no_hlsearch
)
6590 last_pat_prog(&search_hl
.rm
);
6591 search_hl
.attr
= hl_attr(HLF_L
);
6592 # ifdef FEAT_RELTIME
6593 /* Set the time limit to 'redrawtime'. */
6594 profile_setlimit(p_rdt
, &search_hl
.tm
);
6600 * Clean up for 'hlsearch' highlighting.
6605 if (search_hl
.rm
.regprog
!= NULL
)
6607 vim_free(search_hl
.rm
.regprog
);
6608 search_hl
.rm
.regprog
= NULL
;
6613 * Advance to the match in window "wp" line "lnum" or past it.
6616 prepare_search_hl(wp
, lnum
)
6620 matchitem_T
*cur
; /* points to the match list */
6621 match_T
*shl
; /* points to search_hl or a match */
6622 int shl_flag
; /* flag to indicate whether search_hl
6623 has been processed or not */
6627 * When using a multi-line pattern, start searching at the top
6628 * of the window or just after a closed fold.
6629 * Do this both for search_hl and the match list.
6631 cur
= wp
->w_match_head
;
6633 while (cur
!= NULL
|| shl_flag
== FALSE
)
6635 if (shl_flag
== FALSE
)
6642 if (shl
->rm
.regprog
!= NULL
6644 && re_multiline(shl
->rm
.regprog
))
6646 if (shl
->first_lnum
== 0)
6648 # ifdef FEAT_FOLDING
6649 for (shl
->first_lnum
= lnum
;
6650 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6651 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6652 NULL
, NULL
, TRUE
, NULL
))
6655 shl
->first_lnum
= wp
->w_topline
;
6659 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6661 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6664 shl
->first_lnum
= shl
->lnum
6665 + shl
->rm
.endpos
[0].lnum
6666 - shl
->rm
.startpos
[0].lnum
;
6667 n
= shl
->rm
.endpos
[0].col
;
6676 if (shl
!= &search_hl
&& cur
!= NULL
)
6682 * Search for a next 'hlsearch' or match.
6684 * Sets shl->lnum and shl->rm contents.
6685 * Note: Assumes a previous match is always before "lnum", unless
6686 * shl->lnum is zero.
6687 * Careful: Any pointers for buffer lines will become invalid.
6690 next_search_hl(win
, shl
, lnum
, mincol
)
6692 match_T
*shl
; /* points to search_hl or a match */
6694 colnr_T mincol
; /* minimal column for a match */
6702 /* Check for three situations:
6703 * 1. If the "lnum" is below a previous match, start a new search.
6704 * 2. If the previous match includes "mincol", use it.
6705 * 3. Continue after the previous match.
6707 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6710 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6715 * Repeat searching for a match until one is found that includes "mincol"
6716 * or none is found in this line.
6718 called_emsg
= FALSE
;
6722 /* Stop searching after passing the time limit. */
6723 if (profile_passed_limit(&(shl
->tm
)))
6725 shl
->lnum
= 0; /* no match found in time */
6729 /* Three situations:
6730 * 1. No useful previous match: search from start of line.
6731 * 2. Not Vi compatible or empty match: continue at next character.
6732 * Break the loop if this is beyond the end of the line.
6733 * 3. Vi compatible searching: continue at end of previous match.
6737 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6738 || (shl
->rm
.endpos
[0].lnum
== 0
6739 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6743 matchcol
= shl
->rm
.startpos
[0].col
;
6744 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6753 matchcol
+= mb_ptr2len(ml
);
6759 matchcol
= shl
->rm
.endpos
[0].col
;
6762 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
,
6771 /* Error while handling regexp: stop using this regexp. */
6772 if (shl
== &search_hl
)
6774 /* don't free regprog in the match list, it's a copy */
6775 vim_free(shl
->rm
.regprog
);
6778 shl
->rm
.regprog
= NULL
;
6780 got_int
= FALSE
; /* avoid the "Type :quit to exit Vim" message */
6785 shl
->lnum
= 0; /* no match found */
6788 if (shl
->rm
.startpos
[0].lnum
> 0
6789 || shl
->rm
.startpos
[0].col
>= mincol
6791 || shl
->rm
.endpos
[0].col
> mincol
)
6793 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6794 break; /* useful match found */
6801 screen_start_highlight(attr
)
6804 attrentry_T
*aep
= NULL
;
6818 /* The GUI handles this internally. */
6819 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6825 if (attr
> HL_ALL
) /* special HL attr. */
6828 aep
= syn_cterm_attr2entry(attr
);
6830 aep
= syn_term_attr2entry(attr
);
6831 if (aep
== NULL
) /* did ":syntax clear" */
6834 attr
= aep
->ae_attr
;
6836 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6838 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6839 && cterm_normal_fg_bold
)
6840 /* If the Normal FG color has BOLD attribute and the new HL
6841 * has a FG color defined, clear BOLD. */
6843 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6845 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6846 /* underline or undercurl */
6848 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6850 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6854 * Output the color or start string after bold etc., in case the
6855 * bold etc. override the color setting.
6861 if (aep
->ae_u
.cterm
.fg_color
)
6862 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6863 if (aep
->ae_u
.cterm
.bg_color
)
6864 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6868 if (aep
->ae_u
.term
.start
!= NULL
)
6869 out_str(aep
->ae_u
.term
.start
);
6877 screen_stop_highlight()
6879 int do_ME
= FALSE
; /* output T_ME code */
6881 if (screen_attr
!= 0
6892 /* use internal GUI code */
6893 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6899 if (screen_attr
> HL_ALL
) /* special HL attr. */
6906 * Assume that t_me restores the original colors!
6908 aep
= syn_cterm_attr2entry(screen_attr
);
6909 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6910 || aep
->ae_u
.cterm
.bg_color
))
6915 aep
= syn_term_attr2entry(screen_attr
);
6916 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6918 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6921 out_str(aep
->ae_u
.term
.stop
);
6924 if (aep
== NULL
) /* did ":syntax clear" */
6927 screen_attr
= aep
->ae_attr
;
6931 * Often all ending-codes are equal to T_ME. Avoid outputting the
6932 * same sequence several times.
6934 if (screen_attr
& HL_STANDOUT
)
6936 if (STRCMP(T_SE
, T_ME
) == 0)
6941 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6943 if (STRCMP(T_UE
, T_ME
) == 0)
6948 if (screen_attr
& HL_ITALIC
)
6950 if (STRCMP(T_CZR
, T_ME
) == 0)
6955 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6960 /* set Normal cterm colors */
6961 if (cterm_normal_fg_color
!= 0)
6962 term_fg_color(cterm_normal_fg_color
- 1);
6963 if (cterm_normal_bg_color
!= 0)
6964 term_bg_color(cterm_normal_bg_color
- 1);
6965 if (cterm_normal_fg_bold
)
6974 * Reset the colors for a cterm. Used when leaving Vim.
6975 * The machine specific code may override this again.
6978 reset_cterm_colors()
6982 /* set Normal cterm colors */
6983 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
6988 if (cterm_normal_fg_bold
)
6997 * Put character ScreenLines["off"] on the screen at position "row" and "col",
6998 * using the attributes from ScreenAttrs["off"].
7001 screen_char(off
, row
, col
)
7008 /* Check for illegal values, just in case (could happen just after
7010 if (row
>= screen_Rows
|| col
>= screen_Columns
)
7013 /* Outputting the last character on the screen may scrollup the screen.
7014 * Don't to it! Mark the character invalid (update it when scrolled up) */
7015 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
7016 #ifdef FEAT_RIGHTLEFT
7017 /* account for first command-line character in rightleft mode */
7022 ScreenAttrs
[off
] = (sattr_T
)-1;
7027 * Stop highlighting first, so it's easier to move the cursor.
7029 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
7030 if (screen_char_attr
!= 0)
7031 attr
= screen_char_attr
;
7034 attr
= ScreenAttrs
[off
];
7035 if (screen_attr
!= attr
)
7036 screen_stop_highlight();
7040 if (screen_attr
!= attr
)
7041 screen_start_highlight(attr
);
7044 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
7046 char_u buf
[MB_MAXBYTES
+ 1];
7048 /* Convert UTF-8 character to bytes and write it. */
7050 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
7053 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
7062 out_char(ScreenLines
[off
]);
7064 /* double-byte character in single-width cell */
7065 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
7066 out_char(ScreenLines2
[off
]);
7076 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
7077 * on the screen at position 'row' and 'col'.
7078 * The attributes of the first byte is used for all. This is required to
7079 * output the two bytes of a double-byte character with nothing in between.
7082 screen_char_2(off
, row
, col
)
7087 /* Check for illegal values (could be wrong when screen was resized). */
7088 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
7091 /* Outputting the last character on the screen may scrollup the screen.
7092 * Don't to it! Mark the character invalid (update it when scrolled up) */
7093 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
7095 ScreenAttrs
[off
] = (sattr_T
)-1;
7099 /* Output the first byte normally (positions the cursor), then write the
7100 * second byte directly. */
7101 screen_char(off
, row
, col
);
7102 out_char(ScreenLines
[off
+ 1]);
7107 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
7109 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
7110 * This uses the contents of ScreenLines[] and doesn't change it.
7113 screen_draw_rectangle(row
, col
, height
, width
, invert
)
7126 /* Can't use ScreenLines unless initialized */
7127 if (ScreenLines
== NULL
)
7131 screen_char_attr
= HL_INVERSE
;
7132 for (r
= row
; r
< row
+ height
; ++r
)
7134 off
= LineOffset
[r
];
7136 max_off
= off
+ screen_Columns
;
7138 for (c
= col
; c
< col
+ width
; ++c
)
7141 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
, max_off
) > 1)
7143 screen_char_2(off
+ c
, r
, c
);
7149 screen_char(off
+ c
, r
, c
);
7151 if (utf_off2cells(off
+ c
, max_off
) > 1)
7157 screen_char_attr
= 0;
7161 #ifdef FEAT_VERTSPLIT
7163 * Redraw the characters for a vertically split window.
7166 redraw_block(row
, end
, wp
)
7174 # ifdef FEAT_CLIPBOARD
7175 clip_may_clear_selection(row
, end
- 1);
7186 width
= wp
->w_width
;
7188 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
7193 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7194 * with character 'c1' in first column followed by 'c2' in the other columns.
7195 * Use attributes 'attr'.
7198 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
7199 int start_row
, end_row
;
7200 int start_col
, end_col
;
7211 #if defined(FEAT_GUI) || defined(UNIX)
7212 int force_next
= FALSE
;
7215 if (end_row
> screen_Rows
) /* safety check */
7216 end_row
= screen_Rows
;
7217 if (end_col
> screen_Columns
) /* safety check */
7218 end_col
= screen_Columns
;
7219 if (ScreenLines
== NULL
7220 || start_row
>= end_row
7221 || start_col
>= end_col
) /* nothing to do */
7224 /* it's a "normal" terminal when not in a GUI or cterm */
7230 for (row
= start_row
; row
< end_row
; ++row
)
7239 /* When drawing over the right halve of a double-wide char clear
7240 * out the left halve. When drawing over the left halve of a
7241 * double wide-char clear out the right halve. Only needed in a
7243 if (start_col
> 0 && mb_fix_col(start_col
, row
) != start_col
)
7244 screen_puts_len((char_u
*)" ", 1, row
, start_col
- 1, 0);
7245 if (end_col
< screen_Columns
&& mb_fix_col(end_col
, row
) != end_col
)
7246 screen_puts_len((char_u
*)" ", 1, row
, end_col
, 0);
7250 * Try to use delete-line termcap code, when no attributes or in a
7251 * "normal" terminal, where a bold/italic space is just a
7256 && end_col
== Columns
7261 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
7264 * check if we really need to clear something
7267 if (c1
!= ' ') /* don't clear first char */
7270 off
= LineOffset
[row
] + col
;
7271 end_off
= LineOffset
[row
] + end_col
;
7273 /* skip blanks (used often, keep it fast!) */
7276 while (off
< end_off
&& ScreenLines
[off
] == ' '
7277 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
7281 while (off
< end_off
&& ScreenLines
[off
] == ' '
7282 && ScreenAttrs
[off
] == 0)
7284 if (off
< end_off
) /* something to be cleared */
7286 col
= off
- LineOffset
[row
];
7287 screen_stop_highlight();
7288 term_windgoto(row
, col
);/* clear rest of this screen line */
7290 screen_start(); /* don't know where cursor is now */
7291 col
= end_col
- col
;
7292 while (col
--) /* clear chars in ScreenLines */
7294 ScreenLines
[off
] = ' ';
7297 ScreenLinesUC
[off
] = 0;
7299 ScreenAttrs
[off
] = 0;
7303 did_delete
= TRUE
; /* the chars are cleared now */
7306 off
= LineOffset
[row
] + start_col
;
7308 for (col
= start_col
; col
< end_col
; ++col
)
7310 if (ScreenLines
[off
] != c
7312 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
7313 != (c
>= 0x80 ? c
: 0))
7315 || ScreenAttrs
[off
] != attr
7316 #if defined(FEAT_GUI) || defined(UNIX)
7321 #if defined(FEAT_GUI) || defined(UNIX)
7322 /* The bold trick may make a single row of pixels appear in
7323 * the next character. When a bold character is removed, the
7324 * next character should be redrawn too. This happens for our
7325 * own GUI and for some xterms. */
7330 # if defined(FEAT_GUI) && defined(UNIX)
7338 if (ScreenLines
[off
] != ' '
7339 && (ScreenAttrs
[off
] > HL_ALL
7340 || ScreenAttrs
[off
] & HL_BOLD
))
7346 ScreenLines
[off
] = c
;
7352 ScreenLinesUC
[off
] = c
;
7353 ScreenLinesC
[0][off
] = 0;
7356 ScreenLinesUC
[off
] = 0;
7359 ScreenAttrs
[off
] = attr
;
7360 if (!did_delete
|| c
!= ' ')
7361 screen_char(off
, row
, col
);
7364 if (col
== start_col
)
7371 if (end_col
== Columns
)
7372 LineWraps
[row
] = FALSE
;
7373 if (row
== Rows
- 1) /* overwritten the command line */
7375 redraw_cmdline
= TRUE
;
7376 if (c1
== ' ' && c2
== ' ')
7377 clear_cmdline
= FALSE
; /* command line has been cleared */
7379 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7385 * Check if there should be a delay. Used before clearing or redrawing the
7386 * screen or the command line.
7389 check_for_delay(check_msg_scroll
)
7390 int check_msg_scroll
;
7392 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7394 && emsg_silent
== 0)
7397 ui_delay(1000L, TRUE
);
7398 emsg_on_display
= FALSE
;
7399 if (check_msg_scroll
)
7405 * screen_valid - allocate screen buffers if size changed
7406 * If "clear" is TRUE: clear screen if it has been resized.
7407 * Returns TRUE if there is a valid screen to write to.
7408 * Returns FALSE when starting up and screen not initialized yet.
7414 screenalloc(clear
); /* allocate screen buffers if size changed */
7415 return (ScreenLines
!= NULL
);
7419 * Resize the shell to Rows and Columns.
7420 * Allocate ScreenLines[] and associated items.
7422 * There may be some time between setting Rows and Columns and (re)allocating
7423 * ScreenLines[]. This happens when starting up and when (manually) changing
7424 * the shell size. Always use screen_Rows and screen_Columns to access items
7425 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7426 * final size of the shell is needed.
7432 int new_row
, old_row
;
7437 int outofmem
= FALSE
;
7439 schar_T
*new_ScreenLines
;
7441 u8char_T
*new_ScreenLinesUC
= NULL
;
7442 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7443 schar_T
*new_ScreenLines2
= NULL
;
7446 sattr_T
*new_ScreenAttrs
;
7447 unsigned *new_LineOffset
;
7448 char_u
*new_LineWraps
;
7450 short *new_TabPageIdxs
;
7453 static int entered
= FALSE
; /* avoid recursiveness */
7454 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7456 int retry_count
= 0;
7461 * Allocation of the screen buffers is done only when the size changes and
7462 * when Rows and Columns have been set and we have started doing full
7465 if ((ScreenLines
!= NULL
7466 && Rows
== screen_Rows
7467 && Columns
== screen_Columns
7469 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7470 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7471 && p_mco
== Screen_mco
7476 || (!full_screen
&& ScreenLines
== NULL
))
7480 * It's possible that we produce an out-of-memory message below, which
7481 * will cause this function to be called again. To break the loop, just
7489 * Note that the window sizes are updated before reallocating the arrays,
7490 * thus we must not redraw here!
7492 ++RedrawingDisabled
;
7494 win_new_shellsize(); /* fit the windows in the new sized shell */
7496 comp_col(); /* recompute columns for shown command and ruler */
7499 * We're changing the size of the screen.
7500 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7501 * - Move lines from the old arrays into the new arrays, clear extra
7502 * lines (unless the screen is going to be cleared).
7503 * - Free the old arrays.
7505 * If anything fails, make ScreenLines NULL, so we don't do anything!
7506 * Continuing with the old ScreenLines may result in a crash, because the
7509 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7512 if (aucmd_win
!= NULL
)
7513 win_free_lsize(aucmd_win
);
7516 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7517 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7519 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
) * MAX_MCO
);
7522 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7523 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7524 for (i
= 0; i
< p_mco
; ++i
)
7525 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc((long_u
)(
7526 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7528 if (enc_dbcs
== DBCS_JPNU
)
7529 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7530 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7532 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7533 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7534 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7535 Rows
* sizeof(unsigned)), FALSE
);
7536 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7538 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7541 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7543 if (win_alloc_lines(wp
) == FAIL
)
7552 if (aucmd_win
!= NULL
&& aucmd_win
->w_lines
== NULL
7553 && win_alloc_lines(aucmd_win
) == FAIL
)
7561 for (i
= 0; i
< p_mco
; ++i
)
7562 if (new_ScreenLinesC
[i
] == NULL
)
7565 if (new_ScreenLines
== NULL
7567 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7568 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7570 || new_ScreenAttrs
== NULL
7571 || new_LineOffset
== NULL
7572 || new_LineWraps
== NULL
7574 || new_TabPageIdxs
== NULL
7578 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7580 /* guess the size */
7581 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7583 /* Remember we did this to avoid getting outofmem messages over
7584 * and over again. */
7585 done_outofmem_msg
= TRUE
;
7587 vim_free(new_ScreenLines
);
7588 new_ScreenLines
= NULL
;
7590 vim_free(new_ScreenLinesUC
);
7591 new_ScreenLinesUC
= NULL
;
7592 for (i
= 0; i
< p_mco
; ++i
)
7594 vim_free(new_ScreenLinesC
[i
]);
7595 new_ScreenLinesC
[i
] = NULL
;
7597 vim_free(new_ScreenLines2
);
7598 new_ScreenLines2
= NULL
;
7600 vim_free(new_ScreenAttrs
);
7601 new_ScreenAttrs
= NULL
;
7602 vim_free(new_LineOffset
);
7603 new_LineOffset
= NULL
;
7604 vim_free(new_LineWraps
);
7605 new_LineWraps
= NULL
;
7607 vim_free(new_TabPageIdxs
);
7608 new_TabPageIdxs
= NULL
;
7613 done_outofmem_msg
= FALSE
;
7615 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7617 new_LineOffset
[new_row
] = new_row
* Columns
;
7618 new_LineWraps
[new_row
] = FALSE
;
7621 * If the screen is not going to be cleared, copy as much as
7622 * possible from the old screen to the new one and clear the rest
7623 * (used when resizing the window at the "--more--" prompt or when
7624 * executing an external command, for the GUI).
7628 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7629 ' ', (size_t)Columns
* sizeof(schar_T
));
7633 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7634 0, (size_t)Columns
* sizeof(u8char_T
));
7635 for (i
= 0; i
< p_mco
; ++i
)
7636 (void)vim_memset(new_ScreenLinesC
[i
]
7637 + new_row
* Columns
,
7638 0, (size_t)Columns
* sizeof(u8char_T
));
7640 if (enc_dbcs
== DBCS_JPNU
)
7641 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7642 0, (size_t)Columns
* sizeof(schar_T
));
7644 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7645 0, (size_t)Columns
* sizeof(sattr_T
));
7646 old_row
= new_row
+ (screen_Rows
- Rows
);
7647 if (old_row
>= 0 && ScreenLines
!= NULL
)
7649 if (screen_Columns
< Columns
)
7650 len
= screen_Columns
;
7654 /* When switching to utf-8 don't copy characters, they
7655 * may be invalid now. Also when p_mco changes. */
7656 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7657 && p_mco
== Screen_mco
)
7659 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7660 ScreenLines
+ LineOffset
[old_row
],
7661 (size_t)len
* sizeof(schar_T
));
7663 if (enc_utf8
&& ScreenLinesUC
!= NULL
7664 && p_mco
== Screen_mco
)
7666 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7667 ScreenLinesUC
+ LineOffset
[old_row
],
7668 (size_t)len
* sizeof(u8char_T
));
7669 for (i
= 0; i
< p_mco
; ++i
)
7670 mch_memmove(new_ScreenLinesC
[i
]
7671 + new_LineOffset
[new_row
],
7672 ScreenLinesC
[i
] + LineOffset
[old_row
],
7673 (size_t)len
* sizeof(u8char_T
));
7675 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7676 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7677 ScreenLines2
+ LineOffset
[old_row
],
7678 (size_t)len
* sizeof(schar_T
));
7680 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7681 ScreenAttrs
+ LineOffset
[old_row
],
7682 (size_t)len
* sizeof(sattr_T
));
7686 /* Use the last line of the screen for the current line. */
7687 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7692 ScreenLines
= new_ScreenLines
;
7694 ScreenLinesUC
= new_ScreenLinesUC
;
7695 for (i
= 0; i
< p_mco
; ++i
)
7696 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7698 ScreenLines2
= new_ScreenLines2
;
7700 ScreenAttrs
= new_ScreenAttrs
;
7701 LineOffset
= new_LineOffset
;
7702 LineWraps
= new_LineWraps
;
7704 TabPageIdxs
= new_TabPageIdxs
;
7707 /* It's important that screen_Rows and screen_Columns reflect the actual
7708 * size of ScreenLines[]. Set them before calling anything. */
7710 old_Rows
= screen_Rows
;
7713 screen_Columns
= Columns
;
7715 must_redraw
= CLEAR
; /* need to clear the screen later */
7722 && ScreenLines
!= NULL
7723 && old_Rows
!= Rows
)
7725 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7727 * Adjust the position of the cursor, for when executing an external
7730 if (msg_row
>= Rows
) /* Rows got smaller */
7731 msg_row
= Rows
- 1; /* put cursor at last row */
7732 else if (Rows
> old_Rows
) /* Rows got bigger */
7733 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7734 if (msg_col
>= Columns
) /* Columns got smaller */
7735 msg_col
= Columns
- 1; /* put cursor at last column */
7740 --RedrawingDisabled
;
7744 * Do not apply autocommands more than 3 times to avoid an endless loop
7745 * in case applying autocommands always changes Rows or Columns.
7747 if (starting
== 0 && ++retry_count
<= 3)
7749 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7750 /* In rare cases, autocommands may have altered Rows or Columns,
7751 * jump back to check if we need to allocate the screen again. */
7763 vim_free(ScreenLinesUC
);
7764 for (i
= 0; i
< Screen_mco
; ++i
)
7765 vim_free(ScreenLinesC
[i
]);
7766 vim_free(ScreenLines2
);
7768 vim_free(ScreenLines
);
7769 vim_free(ScreenAttrs
);
7770 vim_free(LineOffset
);
7771 vim_free(LineWraps
);
7773 vim_free(TabPageIdxs
);
7780 check_for_delay(FALSE
);
7781 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7782 screenclear2(); /* clear the screen */
7790 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7792 || (gui
.in_use
&& gui
.starting
)
7800 screen_attr
= -1; /* force setting the Normal colors */
7801 screen_stop_highlight(); /* don't want highlighting here */
7803 #ifdef FEAT_CLIPBOARD
7804 /* disable selection without redrawing it */
7805 clip_scroll_selection(9999);
7808 /* blank out ScreenLines */
7809 for (i
= 0; i
< Rows
; ++i
)
7811 lineclear(LineOffset
[i
], (int)Columns
);
7812 LineWraps
[i
] = FALSE
;
7815 if (can_clear(T_CL
))
7817 out_str(T_CL
); /* clear the display */
7818 clear_cmdline
= FALSE
;
7819 mode_displayed
= FALSE
;
7823 /* can't clear the screen, mark all chars with invalid attributes */
7824 for (i
= 0; i
< Rows
; ++i
)
7825 lineinvalid(LineOffset
[i
], (int)Columns
);
7826 clear_cmdline
= TRUE
;
7829 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7831 win_rest_invalid(firstwin
);
7832 redraw_cmdline
= TRUE
;
7834 redraw_tabline
= TRUE
;
7836 if (must_redraw
== CLEAR
) /* no need to clear again */
7837 must_redraw
= NOT_VALID
;
7839 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7841 screen_start(); /* don't know where cursor is now */
7842 msg_scrolled
= 0; /* can't scroll back */
7848 * Clear one line in ScreenLines.
7851 lineclear(off
, width
)
7855 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7858 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7859 (size_t)width
* sizeof(u8char_T
));
7861 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7865 * Mark one line in ScreenLines invalid by setting the attributes to an
7869 lineinvalid(off
, width
)
7873 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7876 #ifdef FEAT_VERTSPLIT
7878 * Copy part of a Screenline for vertically split window "wp".
7881 linecopy(to
, from
, wp
)
7886 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7887 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7889 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7890 wp
->w_width
* sizeof(schar_T
));
7896 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7897 wp
->w_width
* sizeof(u8char_T
));
7898 for (i
= 0; i
< p_mco
; ++i
)
7899 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7900 wp
->w_width
* sizeof(u8char_T
));
7902 if (enc_dbcs
== DBCS_JPNU
)
7903 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7904 wp
->w_width
* sizeof(schar_T
));
7906 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7907 wp
->w_width
* sizeof(sattr_T
));
7912 * Return TRUE if clearing with term string "p" would work.
7913 * It can't work when the string is empty or it won't set the right background.
7919 return (*p
!= NUL
&& (t_colors
<= 1
7923 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7927 * Reset cursor position. Use whenever cursor was moved because of outputting
7928 * something directly to the screen (shell commands) or a terminal control
7934 screen_cur_row
= screen_cur_col
= 9999;
7938 * Move the cursor to position "row","col" in the screen.
7939 * This tries to find the most efficient way to move, minimizing the number of
7940 * characters sent to the terminal.
7957 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
7958 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7963 #define PLAN_WRITE 4
7964 /* Can't use ScreenLines unless initialized */
7965 if (ScreenLines
== NULL
)
7968 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7970 /* Check for valid position. */
7971 if (row
< 0) /* window without text lines? */
7973 if (row
>= screen_Rows
)
7974 row
= screen_Rows
- 1;
7975 if (col
>= screen_Columns
)
7976 col
= screen_Columns
- 1;
7978 /* check if no cursor movement is allowed in highlight mode */
7979 if (screen_attr
&& *T_MS
== NUL
)
7980 noinvcurs
= HIGHL_COST
;
7983 goto_cost
= GOTO_COST
+ noinvcurs
;
7986 * Plan how to do the positioning:
7987 * 1. Use CR to move it to column 0, same row.
7988 * 2. Use T_LE to move it a few columns to the left.
7989 * 3. Use NL to move a few lines down, column 0.
7990 * 4. Move a few columns to the right with T_ND or by writing chars.
7992 * Don't do this if the cursor went beyond the last column, the cursor
7993 * position is unknown then (some terminals wrap, some don't )
7995 * First check if the highlighting attributes allow us to write
7996 * characters to move the cursor to the right.
7998 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
8001 * If the cursor is in the same row, bigger col, we can use CR
8004 bs
= NULL
; /* init for GCC */
8006 if (row
== screen_cur_row
&& col
< screen_cur_col
)
8008 /* "le" is preferred over "bc", because "bc" is obsolete */
8010 bs
= T_LE
; /* "cursor left" */
8012 bs
= T_BC
; /* "backspace character (old) */
8014 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
8017 if (col
+ 1 < cost
) /* using CR is less characters */
8021 cost
= 1; /* CR is just one character */
8028 if (noinvcurs
) /* will stop highlighting */
8036 * If the cursor is above where we want to be, we can use CR LF.
8038 else if (row
> screen_cur_row
)
8042 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
8043 if (noinvcurs
) /* will stop highlighting */
8051 * If the cursor is in the same row, smaller col, just use write.
8056 wouldbe_col
= screen_cur_col
;
8061 * Check if any characters that need to be written have the
8062 * correct attributes. Also avoid UTF-8 characters.
8064 i
= col
- wouldbe_col
;
8067 if (cost
< goto_cost
&& i
> 0)
8070 * Check if the attributes are correct without additionally
8071 * stopping highlighting.
8073 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
8074 while (i
&& *p
++ == attr
)
8079 * Try if it works when highlighting is stopped here.
8084 while (i
&& *p
++ == 0)
8088 cost
= 999; /* different attributes, don't do it */
8093 /* Don't use an UTF-8 char for positioning, it's slow. */
8094 for (i
= wouldbe_col
; i
< col
; ++i
)
8095 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
8105 * We can do it without term_windgoto()!
8107 if (cost
< goto_cost
)
8109 if (plan
== PLAN_LE
)
8112 screen_stop_highlight();
8113 while (screen_cur_col
> col
)
8119 else if (plan
== PLAN_CR
)
8122 screen_stop_highlight();
8126 else if (plan
== PLAN_NL
)
8129 screen_stop_highlight();
8130 while (screen_cur_row
< row
)
8138 i
= col
- screen_cur_col
;
8142 * Use cursor-right if it's one character only. Avoids
8143 * removing a line of pixels from the last bold char, when
8144 * using the bold trick in the GUI.
8146 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
8155 off
= LineOffset
[row
] + screen_cur_col
;
8158 if (ScreenAttrs
[off
] != screen_attr
)
8159 screen_stop_highlight();
8163 out_char(ScreenLines
[off
]);
8165 if (enc_dbcs
== DBCS_JPNU
8166 && ScreenLines
[off
] == 0x8e)
8167 out_char(ScreenLines2
[off
]);
8178 if (cost
>= goto_cost
)
8181 screen_stop_highlight();
8182 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
8184 term_cursor_right(col
- screen_cur_col
);
8186 term_windgoto(row
, col
);
8188 screen_cur_row
= row
;
8189 screen_cur_col
= col
;
8194 * Set cursor to its position in the current window.
8202 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
8203 W_WINCOL(curwin
) + (
8204 #ifdef FEAT_RIGHTLEFT
8205 /* With 'rightleft' set and the cursor on a double-wide
8206 * character, position it on the leftmost column. */
8207 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
8210 && (*mb_ptr2cells
)(ml_get_cursor()) == 2
8211 && vim_isprintc(gchar_cursor())) ? 2 :
8221 * insert 'line_count' lines at 'row' in window 'wp'
8222 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8223 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8225 * Returns FAIL if the lines are not inserted, OK for success.
8228 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
8241 wp
->w_lines_valid
= 0;
8243 if (wp
->w_height
< 5)
8246 if (line_count
> wp
->w_height
- row
)
8247 line_count
= wp
->w_height
- row
;
8249 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
8250 if (retval
!= MAYBE
)
8254 * If there is a next window or a status line, we first try to delete the
8255 * lines at the bottom to avoid messing what is after the window.
8256 * If this fails and there are following windows, don't do anything to avoid
8257 * messing up those windows, better just redraw.
8261 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
8263 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8264 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
8266 else if (wp
->w_next
)
8271 * if no lines deleted, blank the lines that will end up below the window
8276 wp
->w_redr_status
= TRUE
;
8278 redraw_cmdline
= TRUE
;
8279 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
8280 lastrow
= nextrow
+ line_count
;
8283 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
8284 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8288 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
8291 /* deletion will have messed up other windows */
8295 wp
->w_redr_status
= TRUE
;
8297 win_rest_invalid(W_NEXT(wp
));
8306 * delete "line_count" window lines at "row" in window "wp"
8307 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8308 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8310 * Return OK for success, FAIL if the lines are not deleted.
8313 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
8323 wp
->w_lines_valid
= 0;
8325 if (line_count
> wp
->w_height
- row
)
8326 line_count
= wp
->w_height
- row
;
8328 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
8329 if (retval
!= MAYBE
)
8332 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
8333 (int)Rows
, FALSE
, NULL
) == FAIL
)
8338 * If there are windows or status lines below, try to put them at the
8339 * correct place. If we can't do that, they have to be redrawn.
8341 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
8343 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8344 line_count
, (int)Rows
, NULL
) == FAIL
)
8346 wp
->w_redr_status
= TRUE
;
8347 win_rest_invalid(wp
->w_next
);
8351 * If this is the last window and there is no status line, redraw the
8352 * command line later.
8356 redraw_cmdline
= TRUE
;
8361 * Common code for win_ins_lines() and win_del_lines().
8362 * Returns OK or FAIL when the work has been done.
8363 * Returns MAYBE when not finished yet.
8366 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8375 if (!redrawing() || line_count
<= 0)
8378 /* only a few lines left: redraw is faster */
8379 if (mayclear
&& Rows
- line_count
< 5
8380 #ifdef FEAT_VERTSPLIT
8381 && wp
->w_width
== Columns
8385 screenclear(); /* will set wp->w_lines_valid to 0 */
8390 * Delete all remaining lines
8392 if (row
+ line_count
>= wp
->w_height
)
8394 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8395 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8401 * when scrolling, the message on the command line should be cleared,
8402 * otherwise it will stay there forever.
8404 clear_cmdline
= TRUE
;
8407 * If the terminal can set a scroll region, use that.
8408 * Always do this in a vertically split window. This will redraw from
8409 * ScreenLines[] when t_CV isn't defined. That's faster than using
8411 * Don't use a scroll region when we are going to redraw the text, writing
8412 * a character in the lower right corner of the scroll region causes a
8413 * scroll-up in the DJGPP version.
8416 #ifdef FEAT_VERTSPLIT
8417 || W_WIDTH(wp
) != Columns
8421 #ifdef FEAT_VERTSPLIT
8422 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8424 scroll_region_set(wp
, row
);
8426 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8427 wp
->w_height
- row
, FALSE
, wp
);
8429 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8430 wp
->w_height
- row
, wp
);
8431 #ifdef FEAT_VERTSPLIT
8432 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8434 scroll_region_reset();
8439 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8447 * window 'wp' and everything after it is messed up, mark it for redraw
8450 win_rest_invalid(wp
)
8459 redraw_win_later(wp
, NOT_VALID
);
8461 wp
->w_redr_status
= TRUE
;
8465 redraw_cmdline
= TRUE
;
8469 * The rest of the routines in this file perform screen manipulations. The
8470 * given operation is performed physically on the screen. The corresponding
8471 * change is also made to the internal screen image. In this way, the editor
8472 * anticipates the effect of editing changes on the appearance of the screen.
8473 * That way, when we call screenupdate a complete redraw isn't usually
8474 * necessary. Another advantage is that we can keep adding code to anticipate
8475 * screen changes, and in the meantime, everything still works.
8479 * types for inserting or deleting lines
8489 #define USE_REDRAW 9
8492 * insert lines on the screen and update ScreenLines[]
8493 * 'end' is the line after the scrolled part. Normally it is Rows.
8494 * When scrolling region used 'off' is the offset from the top for the region.
8495 * 'row' and 'end' are relative to the start of the region.
8497 * return FAIL for failure, OK for success.
8500 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8505 win_T
*wp
; /* NULL or window to use width from */
8513 int can_ce
= can_clear(T_CE
);
8517 * - there is no valid screen
8518 * - the screen has to be redrawn completely
8519 * - the line count is less than one
8520 * - the line count is more than 'ttyscroll'
8522 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8526 * There are seven ways to insert lines:
8527 * 0. When in a vertically split window and t_CV isn't set, redraw the
8528 * characters from ScreenLines[].
8529 * 1. Use T_CD (clear to end of display) if it exists and the result of
8530 * the insert is just empty lines
8531 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8532 * present or line_count > 1. It looks better if we do all the inserts
8534 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8535 * insert is just empty lines and T_CE is not present or line_count >
8537 * 4. Use T_AL (insert line) if it exists.
8538 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8540 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8542 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8543 * the 'da' flag is not set or we have clear line capability.
8544 * 8. redraw the characters from ScreenLines[].
8546 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8547 * the scrollbar for the window. It does have insert line, use that if it
8550 result_empty
= (row
+ line_count
>= end
);
8551 #ifdef FEAT_VERTSPLIT
8552 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8556 if (can_clear(T_CD
) && result_empty
)
8558 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8560 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8562 else if (*T_AL
!= NUL
)
8564 else if (can_ce
&& result_empty
)
8566 else if (*T_DL
!= NUL
&& result_empty
)
8568 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8574 * For clearing the lines screen_del_lines() is used. This will also take
8575 * care of t_db if necessary.
8577 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8578 type
== USE_T_CE
|| type
== USE_T_DL
)
8579 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8582 * If text is retained below the screen, first clear or delete as many
8583 * lines at the bottom of the window as are about to be inserted so that
8584 * the deleted lines won't later surface during a screen_del_lines.
8587 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8589 #ifdef FEAT_CLIPBOARD
8590 /* Remove a modeless selection when inserting lines halfway the screen
8591 * or not the full width of the screen. */
8593 # ifdef FEAT_VERTSPLIT
8594 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8597 clip_clear_selection();
8599 clip_scroll_selection(-line_count
);
8603 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8604 * scrolling is actually carried out. */
8605 gui_dont_update_cursor();
8608 if (*T_CCS
!= NUL
) /* cursor relative to region */
8611 cursor_row
= row
+ off
;
8614 * Shift LineOffset[] line_count down to reflect the inserted lines.
8615 * Clear the inserted lines in ScreenLines[].
8619 for (i
= 0; i
< line_count
; ++i
)
8621 #ifdef FEAT_VERTSPLIT
8622 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8624 /* need to copy part of a line */
8626 while ((j
-= line_count
) >= row
)
8627 linecopy(j
+ line_count
, j
, wp
);
8629 if (can_clear((char_u
*)" "))
8630 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8632 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8633 LineWraps
[j
] = FALSE
;
8639 temp
= LineOffset
[j
];
8640 while ((j
-= line_count
) >= row
)
8642 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8643 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8645 LineOffset
[j
+ line_count
] = temp
;
8646 LineWraps
[j
+ line_count
] = FALSE
;
8647 if (can_clear((char_u
*)" "))
8648 lineclear(temp
, (int)Columns
);
8650 lineinvalid(temp
, (int)Columns
);
8654 screen_stop_highlight();
8655 windgoto(cursor_row
, 0);
8657 #ifdef FEAT_VERTSPLIT
8658 /* redraw the characters */
8659 if (type
== USE_REDRAW
)
8660 redraw_block(row
, end
, wp
);
8663 if (type
== USE_T_CAL
)
8665 term_append_lines(line_count
);
8666 screen_start(); /* don't know where cursor is now */
8670 for (i
= 0; i
< line_count
; i
++)
8672 if (type
== USE_T_AL
)
8674 if (i
&& cursor_row
!= 0)
8675 windgoto(cursor_row
, 0);
8678 else /* type == USE_T_SR */
8680 screen_start(); /* don't know where cursor is now */
8685 * With scroll-reverse and 'da' flag set we need to clear the lines that
8686 * have been scrolled down into the region.
8688 if (type
== USE_T_SR
&& *T_DA
)
8690 for (i
= 0; i
< line_count
; ++i
)
8692 windgoto(off
+ i
, 0);
8694 screen_start(); /* don't know where cursor is now */
8699 gui_can_update_cursor();
8701 out_flush(); /* always flush after a scroll */
8707 * delete lines on the screen and update ScreenLines[]
8708 * 'end' is the line after the scrolled part. Normally it is Rows.
8709 * When scrolling region used 'off' is the offset from the top for the region.
8710 * 'row' and 'end' are relative to the start of the region.
8712 * Return OK for success, FAIL if the lines are not deleted.
8715 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8720 int force
; /* even when line_count > p_ttyscroll */
8721 win_T
*wp UNUSED
; /* NULL or window to use width from */
8728 int result_empty
; /* result is empty until end of region */
8729 int can_delete
; /* deleting line codes can be used */
8734 * - there is no valid screen
8735 * - the screen has to be redrawn completely
8736 * - the line count is less than one
8737 * - the line count is more than 'ttyscroll'
8739 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8740 (!force
&& line_count
> p_ttyscroll
))
8744 * Check if the rest of the current region will become empty.
8746 result_empty
= row
+ line_count
>= end
;
8749 * We can delete lines only when 'db' flag not set or when 'ce' option
8752 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8755 * There are six ways to delete lines:
8756 * 0. When in a vertically split window and t_CV isn't set, redraw the
8757 * characters from ScreenLines[].
8758 * 1. Use T_CD if it exists and the result is empty.
8759 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8760 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8761 * none of the other ways work.
8762 * 4. Use T_CE (erase line) if the result is empty.
8763 * 5. Use T_DL (delete line) if it exists.
8764 * 6. redraw the characters from ScreenLines[].
8766 #ifdef FEAT_VERTSPLIT
8767 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8771 if (can_clear(T_CD
) && result_empty
)
8773 #if defined(__BEOS__) && defined(BEOS_DR8)
8775 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8776 * its internal termcap... this works okay for tests which test *T_DB !=
8777 * NUL. It has the disadvantage that the user cannot use any :set t_*
8778 * command to get T_DB (back) to empty_option, only :set term=... will do
8780 * Anyway, this hack will hopefully go away with the next OS release.
8783 else if (row
== 0 && T_DB
== empty_option
8784 && (line_count
== 1 || *T_CDL
== NUL
))
8786 else if (row
== 0 && (
8788 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8789 * up, so use delete-line command */
8795 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8797 else if (can_clear(T_CE
) && result_empty
8798 #ifdef FEAT_VERTSPLIT
8799 && (wp
== NULL
|| wp
->w_width
== Columns
)
8803 else if (*T_DL
!= NUL
&& can_delete
)
8805 else if (*T_CDL
!= NUL
&& can_delete
)
8810 #ifdef FEAT_CLIPBOARD
8811 /* Remove a modeless selection when deleting lines halfway the screen or
8812 * not the full width of the screen. */
8814 # ifdef FEAT_VERTSPLIT
8815 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8818 clip_clear_selection();
8820 clip_scroll_selection(line_count
);
8824 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8825 * scrolling is actually carried out. */
8826 gui_dont_update_cursor();
8829 if (*T_CCS
!= NUL
) /* cursor relative to region */
8836 cursor_row
= row
+ off
;
8837 cursor_end
= end
+ off
;
8841 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8842 * Clear the inserted lines in ScreenLines[].
8846 for (i
= 0; i
< line_count
; ++i
)
8848 #ifdef FEAT_VERTSPLIT
8849 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8851 /* need to copy part of a line */
8853 while ((j
+= line_count
) <= end
- 1)
8854 linecopy(j
- line_count
, j
, wp
);
8856 if (can_clear((char_u
*)" "))
8857 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8859 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8860 LineWraps
[j
] = FALSE
;
8865 /* whole width, moving the line pointers is faster */
8867 temp
= LineOffset
[j
];
8868 while ((j
+= line_count
) <= end
- 1)
8870 LineOffset
[j
- line_count
] = LineOffset
[j
];
8871 LineWraps
[j
- line_count
] = LineWraps
[j
];
8873 LineOffset
[j
- line_count
] = temp
;
8874 LineWraps
[j
- line_count
] = FALSE
;
8875 if (can_clear((char_u
*)" "))
8876 lineclear(temp
, (int)Columns
);
8878 lineinvalid(temp
, (int)Columns
);
8882 screen_stop_highlight();
8884 #ifdef FEAT_VERTSPLIT
8885 /* redraw the characters */
8886 if (type
== USE_REDRAW
)
8887 redraw_block(row
, end
, wp
);
8890 if (type
== USE_T_CD
) /* delete the lines */
8892 windgoto(cursor_row
, 0);
8894 screen_start(); /* don't know where cursor is now */
8896 else if (type
== USE_T_CDL
)
8898 windgoto(cursor_row
, 0);
8899 term_delete_lines(line_count
);
8900 screen_start(); /* don't know where cursor is now */
8903 * Deleting lines at top of the screen or scroll region: Just scroll
8904 * the whole screen (scroll region) up by outputting newlines on the
8907 else if (type
== USE_NL
)
8909 windgoto(cursor_end
- 1, 0);
8910 for (i
= line_count
; --i
>= 0; )
8911 out_char('\n'); /* cursor will remain on same line */
8915 for (i
= line_count
; --i
>= 0; )
8917 if (type
== USE_T_DL
)
8919 windgoto(cursor_row
, 0);
8920 out_str(T_DL
); /* delete a line */
8922 else /* type == USE_T_CE */
8924 windgoto(cursor_row
+ i
, 0);
8925 out_str(T_CE
); /* erase a line */
8927 screen_start(); /* don't know where cursor is now */
8932 * If the 'db' flag is set, we need to clear the lines that have been
8933 * scrolled up at the bottom of the region.
8935 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8937 for (i
= line_count
; i
> 0; --i
)
8939 windgoto(cursor_end
- i
, 0);
8940 out_str(T_CE
); /* erase a line */
8941 screen_start(); /* don't know where cursor is now */
8946 gui_can_update_cursor();
8948 out_flush(); /* always flush after a scroll */
8955 * show the current mode and ruler
8957 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8958 * If clear_cmdline is FALSE there may be a message there that needs to be
8959 * cleared only if a mode is shown.
8960 * Return the length of the message (0 if no message).
8970 #ifdef FEAT_INS_EXPAND
8974 do_mode
= ((p_smd
&& msg_silent
== 0)
8975 && ((State
& INSERT
)
8981 if (do_mode
|| Recording
)
8984 * Don't show mode right now, when not redrawing or inside a mapping.
8985 * Call char_avail() only when we are going to show something, because
8986 * it takes a bit of time.
8988 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
8990 redraw_cmdline
= TRUE
; /* show mode later */
8994 nwr_save
= need_wait_return
;
8996 /* wait a bit before overwriting an important message */
8997 check_for_delay(FALSE
);
8999 /* if the cmdline is more than one line high, erase top lines */
9000 need_clear
= clear_cmdline
;
9001 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
9002 msg_clr_cmdline(); /* will reset clear_cmdline */
9004 /* Position on the last line in the window, column 0 */
9007 attr
= hl_attr(HLF_CM
); /* Highlight mode */
9010 MSG_PUTS_ATTR("--", attr
);
9011 #if defined(FEAT_XIM)
9012 # if 0 /* old version, changed by SungHyun Nam July 2008 */
9013 if (xic
!= NULL
&& im_get_status() && !p_imdisable
9014 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
9018 preedit_get_status()
9024 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
9025 MSG_PUTS_ATTR(" IM", attr
);
9027 MSG_PUTS_ATTR(" XIM", attr
);
9030 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
9033 if (hangul_input_state_get())
9034 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
9037 #ifdef FEAT_INS_EXPAND
9038 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
9040 /* These messages can get long, avoid a wrap in a narrow
9041 * window. Prefer showing edit_submode_extra. */
9042 length
= (Rows
- msg_row
) * Columns
- 3;
9043 if (edit_submode_extra
!= NULL
)
9044 length
-= vim_strsize(edit_submode_extra
);
9047 if (edit_submode_pre
!= NULL
)
9048 length
-= vim_strsize(edit_submode_pre
);
9049 if (length
- vim_strsize(edit_submode
) > 0)
9051 if (edit_submode_pre
!= NULL
)
9052 msg_puts_attr(edit_submode_pre
, attr
);
9053 msg_puts_attr(edit_submode
, attr
);
9055 if (edit_submode_extra
!= NULL
)
9057 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
9058 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
9059 sub_attr
= hl_attr(edit_submode_highl
);
9062 msg_puts_attr(edit_submode_extra
, sub_attr
);
9070 #ifdef FEAT_VREPLACE
9071 if (State
& VREPLACE_FLAG
)
9072 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
9075 if (State
& REPLACE_FLAG
)
9076 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
9077 else if (State
& INSERT
)
9079 #ifdef FEAT_RIGHTLEFT
9081 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
9083 MSG_PUTS_ATTR(_(" INSERT"), attr
);
9085 else if (restart_edit
== 'I')
9086 MSG_PUTS_ATTR(_(" (insert)"), attr
);
9087 else if (restart_edit
== 'R')
9088 MSG_PUTS_ATTR(_(" (replace)"), attr
);
9089 else if (restart_edit
== 'V')
9090 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
9091 #ifdef FEAT_RIGHTLEFT
9093 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
9096 MSG_PUTS_ATTR(farsi_text_5
, attr
);
9100 if (State
& LANGMAP
)
9103 if (curwin
->w_p_arab
)
9104 MSG_PUTS_ATTR(_(" Arabic"), attr
);
9107 MSG_PUTS_ATTR(_(" (lang)"), attr
);
9110 if ((State
& INSERT
) && p_paste
)
9111 MSG_PUTS_ATTR(_(" (paste)"), attr
);
9118 /* Don't concatenate separate words to avoid translation
9120 switch ((VIsual_select
? 4 : 0)
9121 + (VIsual_mode
== Ctrl_V
) * 2
9122 + (VIsual_mode
== 'V'))
9124 case 0: p
= N_(" VISUAL"); break;
9125 case 1: p
= N_(" VISUAL LINE"); break;
9126 case 2: p
= N_(" VISUAL BLOCK"); break;
9127 case 4: p
= N_(" SELECT"); break;
9128 case 5: p
= N_(" SELECT LINE"); break;
9129 default: p
= N_(" SELECT BLOCK"); break;
9131 MSG_PUTS_ATTR(_(p
), attr
);
9134 MSG_PUTS_ATTR(" --", attr
);
9140 #ifdef FEAT_INS_EXPAND
9141 && edit_submode
== NULL
/* otherwise it gets too long */
9145 MSG_PUTS_ATTR(_("recording"), attr
);
9149 mode_displayed
= TRUE
;
9150 if (need_clear
|| clear_cmdline
)
9152 msg_didout
= FALSE
; /* overwrite this message */
9155 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
9157 else if (clear_cmdline
&& msg_silent
== 0)
9158 /* Clear the whole command line. Will reset "clear_cmdline". */
9161 #ifdef FEAT_CMDL_INFO
9163 /* In Visual mode the size of the selected area must be redrawn. */
9168 /* If the last window has no status line, the ruler is after the mode
9169 * message and must be redrawn */
9171 # ifdef FEAT_WINDOWS
9172 && lastwin
->w_status_height
== 0
9175 win_redr_ruler(lastwin
, TRUE
);
9177 redraw_cmdline
= FALSE
;
9178 clear_cmdline
= FALSE
;
9184 * Position for a mode message.
9194 * Delete mode message. Used when ESC is typed which is expected to end
9195 * Insert mode (but Insert mode didn't end yet!).
9196 * Caller should check "mode_displayed".
9203 * Don't delete it right now, when not redrawing or insided a mapping.
9205 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
9206 redraw_cmdline
= TRUE
; /* delete mode later */
9211 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
9216 #if defined(FEAT_WINDOWS)
9218 * Draw the tab pages line at the top of the Vim window.
9235 int attr_sel
= hl_attr(HLF_TPS
);
9236 int attr_nosel
= hl_attr(HLF_TP
);
9237 int attr_fill
= hl_attr(HLF_TPF
);
9240 int use_sep_chars
= (t_colors
< 8
9246 redraw_tabline
= FALSE
;
9248 #ifdef FEAT_GUI_TABLINE
9249 /* Take care of a GUI tabline. */
9250 if (gui_use_tabline())
9252 gui_update_tabline();
9257 if (tabline_height() < 1)
9260 #if defined(FEAT_STL_OPT)
9262 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9263 for (scol
= 0; scol
< Columns
; ++scol
)
9264 TabPageIdxs
[scol
] = 0;
9266 /* Use the 'tabline' option if it's set. */
9269 int save_called_emsg
= called_emsg
;
9271 /* Check for an error. If there is one we would loop in redrawing the
9272 * screen. Avoid that by making 'tabline' empty. */
9273 called_emsg
= FALSE
;
9274 win_redr_custom(NULL
, FALSE
);
9276 set_string_option_direct((char_u
*)"tabline", -1,
9277 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9278 called_emsg
|= save_called_emsg
;
9283 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
9286 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
9293 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
9298 if (tp
->tp_topframe
== topframe
)
9300 if (use_sep_chars
&& col
> 0)
9301 screen_putchar('|', 0, col
++, attr
);
9303 if (tp
->tp_topframe
!= topframe
)
9306 screen_putchar(' ', 0, col
++, attr
);
9315 cwp
= tp
->tp_curwin
;
9316 wp
= tp
->tp_firstwin
;
9320 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
9321 if (bufIsChanged(wp
->w_buffer
))
9323 if (modified
|| wincount
> 1)
9327 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
9328 len
= (int)STRLEN(NameBuff
);
9329 if (col
+ len
>= Columns
- 3)
9331 screen_puts_len(NameBuff
, len
, 0, col
,
9332 #if defined(FEAT_SYN_HL)
9333 hl_combine_attr(attr
, hl_attr(HLF_T
))
9341 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
9342 screen_putchar(' ', 0, col
++, attr
);
9345 room
= scol
- col
+ tabwidth
- 1;
9348 /* Get buffer name in NameBuff[] */
9349 get_trans_bufname(cwp
->w_buffer
);
9350 shorten_dir(NameBuff
);
9351 len
= vim_strsize(NameBuff
);
9357 len
-= ptr2cells(p
);
9367 if (len
> Columns
- col
- 1)
9368 len
= Columns
- col
- 1;
9370 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9373 screen_putchar(' ', 0, col
++, attr
);
9375 /* Store the tab page number in TabPageIdxs[], so that
9376 * jump_to_mouse() knows where each one is. */
9379 TabPageIdxs
[scol
++] = tabcount
;
9386 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9388 /* Put an "X" for closing the current tab if there are several. */
9389 if (first_tabpage
->tp_next
!= NULL
)
9391 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9392 TabPageIdxs
[Columns
- 1] = -999;
9396 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9398 redraw_tabline
= FALSE
;
9402 * Get buffer name for "buf" into NameBuff[].
9403 * Takes care of special buffer names and translates special characters.
9406 get_trans_bufname(buf
)
9409 if (buf_spname(buf
) != NULL
)
9410 STRCPY(NameBuff
, buf_spname(buf
));
9412 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9413 trans_characters(NameBuff
, MAXPATHL
);
9417 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9419 * Get the character to use in a status line. Get its attributes in "*attr".
9422 fillchar_status(attr
, is_curwin
)
9429 *attr
= hl_attr(HLF_S
);
9434 *attr
= hl_attr(HLF_SNC
);
9437 /* Use fill when there is highlighting, and highlighting of current
9438 * window differs, or the fillchars differ, or this is not the
9440 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9441 || !is_curwin
|| firstwin
== lastwin
)
9442 || (fill_stl
!= fill_stlnc
)))
9450 #ifdef FEAT_VERTSPLIT
9452 * Get the character to use in a separator between vertically split windows.
9453 * Get its attributes in "*attr".
9459 *attr
= hl_attr(HLF_C
);
9460 if (*attr
== 0 && fill_vert
== ' ')
9468 * Return TRUE if redrawing should currently be done.
9473 return (!RedrawingDisabled
9474 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9478 * Return TRUE if printing messages should currently be done.
9483 return (!(p_lz
&& char_avail() && !KeyTyped
));
9487 * Show current status info in ruler and various other places
9488 * If always is FALSE, only show ruler if position has changed.
9494 if (!always
&& !redrawing())
9496 #ifdef FEAT_INS_EXPAND
9499 # ifdef FEAT_WINDOWS
9500 /* Don't redraw right now, do it later. */
9501 curwin
->w_redr_status
= TRUE
;
9506 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9507 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9509 redraw_custom_statusline(curwin
);
9513 #ifdef FEAT_CMDL_INFO
9514 win_redr_ruler(curwin
, always
);
9519 # ifdef FEAT_STL_OPT
9520 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9521 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9527 /* Redraw the tab pages line if needed. */
9533 #ifdef FEAT_CMDL_INFO
9535 win_redr_ruler(wp
, always
)
9539 #define RULER_BUF_LEN 70
9540 char_u buffer
[RULER_BUF_LEN
];
9544 int empty_line
= FALSE
;
9549 #ifdef FEAT_VERTSPLIT
9552 int width
= Columns
;
9553 # define WITH_OFF(x) x
9554 # define WITH_WIDTH(x) x
9556 # define WITH_OFF(x) 0
9557 # define WITH_WIDTH(x) Columns
9558 # define this_ru_col ru_col
9561 /* If 'ruler' off or redrawing disabled, don't do anything */
9566 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9567 * after deleting lines, before cursor.lnum is corrected.
9569 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9572 #ifdef FEAT_INS_EXPAND
9573 /* Don't draw the ruler while doing insert-completion, it might overwrite
9574 * the (long) mode message. */
9575 # ifdef FEAT_WINDOWS
9576 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9578 if (edit_submode
!= NULL
)
9580 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9588 int save_called_emsg
= called_emsg
;
9590 called_emsg
= FALSE
;
9591 win_redr_custom(wp
, TRUE
);
9593 set_string_option_direct((char_u
*)"rulerformat", -1,
9594 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9595 called_emsg
|= save_called_emsg
;
9601 * Check if not in Insert mode and the line is empty (will show "0-1").
9603 if (!(State
& INSERT
)
9604 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9608 * Only draw the ruler when something changed.
9610 validate_virtcol_win(wp
);
9613 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9614 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9615 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9616 #ifdef FEAT_VIRTUALEDIT
9617 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9619 || wp
->w_topline
!= wp
->w_ru_topline
9620 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9622 || wp
->w_topfill
!= wp
->w_ru_topfill
9624 || empty_line
!= wp
->w_ru_empty
)
9628 if (wp
->w_status_height
)
9630 row
= W_WINROW(wp
) + wp
->w_height
;
9631 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9632 # ifdef FEAT_VERTSPLIT
9634 width
= W_WIDTH(wp
);
9643 #ifdef FEAT_VERTSPLIT
9649 /* In list mode virtcol needs to be recomputed */
9650 virtcol
= wp
->w_virtcol
;
9651 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9653 wp
->w_p_list
= FALSE
;
9654 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9655 wp
->w_p_list
= TRUE
;
9659 * Some sprintfs return the length, some return a pointer.
9660 * To avoid portability problems we use strlen() here.
9662 vim_snprintf((char *)buffer
, RULER_BUF_LEN
, "%ld,",
9663 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9665 : (long)(wp
->w_cursor
.lnum
));
9666 len
= STRLEN(buffer
);
9667 col_print(buffer
+ len
, RULER_BUF_LEN
- len
,
9668 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9672 * Add a "50%" if there is room for it.
9673 * On the last line, don't print in the last column (scrolls the
9674 * screen up on some terminals).
9676 i
= (int)STRLEN(buffer
);
9677 get_rel_pos(wp
, buffer
+ i
+ 1, RULER_BUF_LEN
- i
- 1);
9678 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9680 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9683 #ifdef FEAT_VERTSPLIT
9684 this_ru_col
= ru_col
- (Columns
- width
);
9685 if (this_ru_col
< 0)
9688 /* Never use more than half the window/screen width, leave the other
9689 * half for the filename. */
9690 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9691 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9692 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9694 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9698 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9701 buffer
[i
++] = fillchar
;
9704 get_rel_pos(wp
, buffer
+ i
, RULER_BUF_LEN
- i
);
9706 /* Truncate at window boundary. */
9711 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9713 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9714 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9723 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9724 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9726 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9728 screen_fill(row
, row
+ 1,
9729 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9730 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9731 fillchar
, fillchar
, attr
);
9732 /* don't redraw the cmdline because of showing the ruler */
9734 wp
->w_ru_cursor
= wp
->w_cursor
;
9735 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9736 wp
->w_ru_empty
= empty_line
;
9737 wp
->w_ru_topline
= wp
->w_topline
;
9738 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9740 wp
->w_ru_topfill
= wp
->w_topfill
;
9746 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9748 * Return the width of the 'number' column.
9749 * Caller may need to check if 'number' is set.
9750 * Otherwise it depends on 'numberwidth' and the line count.
9759 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9760 if (lnum
== wp
->w_nrwidth_line_count
)
9761 return wp
->w_nrwidth_width
;
9762 wp
->w_nrwidth_line_count
= lnum
;
9771 /* 'numberwidth' gives the minimal width plus one */
9772 if (n
< wp
->w_p_nuw
- 1)
9773 n
= wp
->w_p_nuw
- 1;
9775 wp
->w_nrwidth_width
= n
;