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 immediated 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
104 * Struct used for highlighting 'hlsearch' matches for the last use search
105 * pattern or a ":match" item.
106 * For 'hlsearch' there is one pattern for all windows. For ":match" there is
107 * a different pattern for each window.
111 regmmatch_T rm
; /* points to the regexp program; contains last found
112 match (may continue in next line) */
113 buf_T
*buf
; /* the buffer to search for a match */
114 linenr_T lnum
; /* the line to search for a match */
115 int attr
; /* attributes to be used for a match */
116 int attr_cur
; /* attributes currently active in win_line() */
117 linenr_T first_lnum
; /* first lnum to search for multi-line pat */
118 colnr_T startcol
; /* in win_line() points to char where HL starts */
119 colnr_T endcol
; /* in win_line() points to char where HL ends */
122 static match_T search_hl
; /* used for 'hlsearch' highlight matching */
123 static match_T match_hl
[3]; /* used for ":match" highlight matching */
127 static foldinfo_T win_foldinfo
; /* info for 'foldcolumn' */
131 * Buffer for one screen line (characters and attributes).
133 static schar_T
*current_ScreenLine
;
135 static void win_update
__ARGS((win_T
*wp
));
136 static void win_draw_end
__ARGS((win_T
*wp
, int c1
, int c2
, int row
, int endrow
, hlf_T hl
));
138 static void fold_line
__ARGS((win_T
*wp
, long fold_count
, foldinfo_T
*foldinfo
, linenr_T lnum
, int row
));
139 static void fill_foldcolumn
__ARGS((char_u
*p
, win_T
*wp
, int closed
, linenr_T lnum
));
140 static void copy_text_attr
__ARGS((int off
, char_u
*buf
, int len
, int attr
));
142 static int win_line
__ARGS((win_T
*, linenr_T
, int, int, int nochange
));
143 static int char_needs_redraw
__ARGS((int off_from
, int off_to
, int cols
));
144 #ifdef FEAT_RIGHTLEFT
145 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
, int rlflag
));
146 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl))
148 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
));
149 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c))
151 #ifdef FEAT_VERTSPLIT
152 static void draw_vsep_win
__ARGS((win_T
*wp
, int row
));
155 static void redraw_custum_statusline
__ARGS((win_T
*wp
));
157 #ifdef FEAT_SEARCH_EXTRA
158 static void start_search_hl
__ARGS((void));
159 static void end_search_hl
__ARGS((void));
160 static void prepare_search_hl
__ARGS((win_T
*wp
, linenr_T lnum
));
161 static void next_search_hl
__ARGS((win_T
*win
, match_T
*shl
, linenr_T lnum
, colnr_T mincol
));
163 static void screen_start_highlight
__ARGS((int attr
));
164 static void screen_char
__ARGS((unsigned off
, int row
, int col
));
166 static void screen_char_2
__ARGS((unsigned off
, int row
, int col
));
168 static void screenclear2
__ARGS((void));
169 static void lineclear
__ARGS((unsigned off
, int width
));
170 static void lineinvalid
__ARGS((unsigned off
, int width
));
171 #ifdef FEAT_VERTSPLIT
172 static void linecopy
__ARGS((int to
, int from
, win_T
*wp
));
173 static void redraw_block
__ARGS((int row
, int end
, win_T
*wp
));
175 static int win_do_lines
__ARGS((win_T
*wp
, int row
, int line_count
, int mayclear
, int del
));
176 static void win_rest_invalid
__ARGS((win_T
*wp
));
177 static void msg_pos_mode
__ARGS((void));
178 #if defined(FEAT_WINDOWS)
179 static void draw_tabline
__ARGS((void));
181 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
182 static int fillchar_status
__ARGS((int *attr
, int is_curwin
));
184 #ifdef FEAT_VERTSPLIT
185 static int fillchar_vsep
__ARGS((int *attr
));
188 static void win_redr_custom
__ARGS((win_T
*wp
, int draw_ruler
));
190 #ifdef FEAT_CMDL_INFO
191 static void win_redr_ruler
__ARGS((win_T
*wp
, int always
));
194 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
195 /* Ugly global: overrule attribute used by screen_char() */
196 static int screen_char_attr
= 0;
200 * Redraw the current window later, with update_screen(type).
201 * Set must_redraw only if not already set to a higher value.
202 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
208 redraw_win_later(curwin
, type
);
212 redraw_win_later(wp
, type
)
216 if (wp
->w_redr_type
< type
)
218 wp
->w_redr_type
= type
;
219 if (type
>= NOT_VALID
)
220 wp
->w_lines_valid
= 0;
221 if (must_redraw
< type
) /* must_redraw is the maximum of all windows */
227 * Force a complete redraw later. Also resets the highlighting. To be used
228 * after executing a shell command that messes up the screen.
233 redraw_all_later(CLEAR
);
236 /* Use a code that will reset gui.highlight_mask in
237 * gui_stop_highlight(). */
238 screen_attr
= HL_ALL
+ 1;
241 /* Use attributes that is very unlikely to appear in text. */
242 screen_attr
= HL_BOLD
| HL_UNDERLINE
| HL_INVERSE
;
246 * Mark all windows to be redrawn later.
249 redraw_all_later(type
)
256 redraw_win_later(wp
, type
);
261 * Mark all windows that are editing the current buffer to be updated later.
264 redraw_curbuf_later(type
)
267 redraw_buf_later(curbuf
, type
);
271 redraw_buf_later(buf
, type
)
279 if (wp
->w_buffer
== buf
)
280 redraw_win_later(wp
, type
);
285 * Changed something in the current window, at buffer line "lnum", that
286 * requires that line and possibly other lines to be redrawn.
287 * Used when entering/leaving Insert mode with the cursor on a folded line.
288 * Used to remove the "$" from a change command.
289 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
290 * may become invalid and the whole window will have to be redrawn.
294 redrawWinline(lnum
, invalid
)
296 int invalid
; /* window line height is invalid now */
302 if (curwin
->w_redraw_top
== 0 || curwin
->w_redraw_top
> lnum
)
303 curwin
->w_redraw_top
= lnum
;
304 if (curwin
->w_redraw_bot
== 0 || curwin
->w_redraw_bot
< lnum
)
305 curwin
->w_redraw_bot
= lnum
;
311 /* A w_lines[] entry for this lnum has become invalid. */
312 i
= find_wl_entry(curwin
, lnum
);
314 curwin
->w_lines
[i
].wl_valid
= FALSE
;
320 * update all windows that are editing the current buffer
326 redraw_curbuf_later(type
);
333 * Based on the current value of curwin->w_topline, transfer a screenfull
334 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
341 static int did_intro
= FALSE
;
342 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
346 if (!screen_valid(TRUE
))
351 if (type
< must_redraw
) /* use maximal type */
356 /* Need to update w_lines[]. */
357 if (curwin
->w_lines_valid
== 0 && type
< NOT_VALID
)
362 redraw_later(type
); /* remember type for next time */
364 if (type
> INVERTED_ALL
)
365 curwin
->w_lines_valid
= 0; /* don't use w_lines[].wl_size now */
369 updating_screen
= TRUE
;
371 ++display_tick
; /* let syntax code know we're in a next round of
372 * display updating */
376 * if the screen was scrolled up when displaying a message, scroll it down
380 clear_cmdline
= TRUE
;
381 if (msg_scrolled
> Rows
- 5) /* clearing is faster */
383 else if (type
!= CLEAR
)
385 check_for_delay(FALSE
);
386 if (screen_ins_lines(0, 0, msg_scrolled
, (int)Rows
, NULL
) == FAIL
)
390 if (W_WINROW(wp
) < msg_scrolled
)
392 if (W_WINROW(wp
) + wp
->w_height
> msg_scrolled
393 && wp
->w_redr_type
< REDRAW_TOP
394 && wp
->w_lines_valid
> 0
395 && wp
->w_topline
== wp
->w_lines
[0].wl_lnum
)
397 wp
->w_upd_rows
= msg_scrolled
- W_WINROW(wp
);
398 wp
->w_redr_type
= REDRAW_TOP
;
402 wp
->w_redr_type
= NOT_VALID
;
404 if (W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
)
406 wp
->w_redr_status
= TRUE
;
411 redraw_cmdline
= TRUE
;
413 redraw_tabline
= TRUE
;
417 need_wait_return
= FALSE
;
420 /* reset cmdline_row now (may have been changed temporarily) */
423 /* Check for changed highlighting */
424 if (need_highlight_changed
)
427 if (type
== CLEAR
) /* first clear screen */
429 screenclear(); /* will reset clear_cmdline */
433 if (clear_cmdline
) /* going to clear cmdline (done below) */
434 check_for_delay(FALSE
);
436 #ifdef FEAT_LINEBREAK
437 /* Force redraw when width of 'number' column changes. */
438 if (curwin
->w_redr_type
< NOT_VALID
439 && curwin
->w_nrwidth
!= (curwin
->w_p_nu
? number_width(curwin
) : 0))
440 curwin
->w_redr_type
= NOT_VALID
;
444 * Only start redrawing if there is really something to do.
446 if (type
== INVERTED
)
448 if (curwin
->w_redr_type
< type
450 && curwin
->w_lines
[0].wl_valid
452 && curwin
->w_topfill
== curwin
->w_old_topfill
453 && curwin
->w_botfill
== curwin
->w_old_botfill
455 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
458 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
459 && curwin
->w_old_visual_mode
== VIsual_mode
460 && (curwin
->w_valid
& VALID_VIRTCOL
)
461 && curwin
->w_old_curswant
== curwin
->w_curswant
)
464 curwin
->w_redr_type
= type
;
467 /* Redraw the tab pages line if needed. */
468 if (redraw_tabline
|| type
>= NOT_VALID
)
474 * Correct stored syntax highlighting info for changes in each displayed
475 * buffer. Each buffer must only be done once.
479 if (wp
->w_buffer
->b_mod_set
)
484 /* Check if we already did this buffer. */
485 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
486 if (wwp
->w_buffer
== wp
->w_buffer
)
493 syntax_present(wp
->w_buffer
))
494 syn_stack_apply_changes(wp
->w_buffer
);
500 * Go from top to bottom through the windows, redrawing the ones that need
503 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
506 #ifdef FEAT_SEARCH_EXTRA
507 search_hl
.rm
.regprog
= NULL
;
511 if (wp
->w_redr_type
!= 0)
514 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
518 # ifdef FEAT_SEARCH_EXTRA
521 # ifdef FEAT_CLIPBOARD
522 /* When Visual area changed, may have to update selection. */
523 if (clip_star
.available
&& clip_isautosel())
524 clip_update_selection();
527 /* Remove the cursor before starting to do anything, because
528 * scrolling may make it difficult to redraw the text under
539 /* redraw status line after the window to minimize cursor movement */
540 if (wp
->w_redr_status
)
547 #if defined(FEAT_SEARCH_EXTRA)
552 /* Reset b_mod_set flags. Going through all windows is probably faster
553 * than going through all buffers (there could be many buffers). */
554 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
555 wp
->w_buffer
->b_mod_set
= FALSE
;
557 curbuf
->b_mod_set
= FALSE
;
560 updating_screen
= FALSE
;
562 gui_may_resize_shell();
565 /* Clear or redraw the command line. Done last, because scrolling may
566 * mess up the command line. */
567 if (clear_cmdline
|| redraw_cmdline
)
570 /* May put up an introductory message when not editing a file */
571 if (!did_intro
&& bufempty()
572 && curbuf
->b_fname
== NULL
574 && firstwin
->w_next
== NULL
576 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
577 intro_message(FALSE
);
581 /* Redraw the cursor and update the scrollbars when all screen updating is
585 out_flush(); /* required before updating the cursor */
587 gui_update_cursor(FALSE
, FALSE
);
588 gui_update_scrollbars(FALSE
);
593 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
594 static void update_prepare
__ARGS((void));
595 static void update_finish
__ARGS((void));
598 * Prepare for updating one or more windows.
604 updating_screen
= TRUE
;
606 /* Remove the cursor before starting to do anything, because scrolling may
607 * make it difficult to redraw the text under it. */
611 #ifdef FEAT_SEARCH_EXTRA
617 * Finish updating one or more windows.
625 # ifdef FEAT_SEARCH_EXTRA
629 updating_screen
= FALSE
;
632 gui_may_resize_shell();
634 /* Redraw the cursor and update the scrollbars when all screen updating is
638 out_flush(); /* required before updating the cursor */
639 gui_update_cursor(FALSE
, FALSE
);
640 gui_update_scrollbars(FALSE
);
646 #if defined(FEAT_SIGNS) || defined(PROTO)
648 update_debug_sign(buf
, lnum
)
656 win_foldinfo
.fi_level
= 0;
659 /* update/delete a specific mark */
662 if (buf
!= NULL
&& lnum
> 0)
664 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
665 && lnum
< wp
->w_botline
)
667 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
668 wp
->w_redraw_top
= lnum
;
669 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
670 wp
->w_redraw_bot
= lnum
;
671 redraw_win_later(wp
, VALID
);
675 redraw_win_later(wp
, VALID
);
676 if (wp
->w_redr_type
!= 0)
683 /* update all windows that need updating */
687 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
689 if (wp
->w_redr_type
!= 0)
691 if (wp
->w_redr_status
)
695 if (curwin
->w_redr_type
!= 0)
704 #if defined(FEAT_GUI) || defined(PROTO)
706 * Update a single window, its status line and maybe the command line msg.
707 * Used for the GUI scrollbar.
715 #ifdef FEAT_CLIPBOARD
716 /* When Visual area changed, may have to update selection. */
717 if (clip_star
.available
&& clip_isautosel())
718 clip_update_selection();
724 /* When the screen was cleared redraw the tab pages line. */
728 if (wp
->w_redr_status
729 # ifdef FEAT_CMDL_INFO
733 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
744 * Update a single window.
746 * This may cause the windows below it also to be redrawn (when clearing the
747 * screen or scrolling lines).
749 * How the window is redrawn depends on wp->w_redr_type. Each type also
750 * implies the one below it.
751 * NOT_VALID redraw the whole window
752 * SOME_VALID redraw the whole window but do scroll when possible
753 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
754 * INVERTED redraw the changed part of the Visual area
755 * INVERTED_ALL redraw the whole Visual area
756 * VALID 1. scroll up/down to adjust for a changed w_topline
757 * 2. update lines at the top when scrolled down
758 * 3. redraw changed text:
759 * - if wp->w_buffer->b_mod_set set, update lines between
760 * b_mod_top and b_mod_bot.
761 * - if wp->w_redraw_top non-zero, redraw lines between
762 * wp->w_redraw_top and wp->w_redr_bot.
763 * - continue redrawing when syntax status is invalid.
764 * 4. if scrolled up, update lines at the bottom.
765 * This results in three areas that may need updating:
766 * top: from first row to top_end (when scrolled down)
767 * mid: from mid_start to mid_end (update inversion or changed text)
768 * bot: from bot_start to last row (when scrolled up)
774 buf_T
*buf
= wp
->w_buffer
;
776 int top_end
= 0; /* Below last row of the top area that needs
777 updating. 0 when no top area updating. */
778 int mid_start
= 999;/* first row of the mid area that needs
779 updating. 999 when no mid area updating. */
780 int mid_end
= 0; /* Below last row of the mid area that needs
781 updating. 0 when no mid area updating. */
782 int bot_start
= 999;/* first row of the bot area that needs
783 updating. 999 when no bot area updating */
785 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
786 w_topline got smaller a bit */
788 #ifdef FEAT_SEARCH_EXTRA
789 int top_to_mod
= FALSE
; /* redraw above mod_top */
792 int row
; /* current window row to display */
793 linenr_T lnum
; /* current buffer lnum to display */
794 int idx
; /* current index in w_lines[] */
795 int srow
; /* starting row of the current line */
797 int eof
= FALSE
; /* if TRUE, we hit the end of the file */
798 int didline
= FALSE
; /* if TRUE, we finished the last line */
801 static int recursive
= FALSE
; /* being called recursively */
802 int old_botline
= wp
->w_botline
;
807 /* remember what happened to the previous line, to know if
808 * check_visual_highlight() can be used */
809 #define DID_NONE 1 /* didn't update a line */
810 #define DID_LINE 2 /* updated a normal line */
811 #define DID_FOLD 3 /* updated a folded line */
812 int did_update
= DID_NONE
;
813 linenr_T syntax_last_parsed
= 0; /* last parsed text line */
815 linenr_T mod_top
= 0;
816 linenr_T mod_bot
= 0;
817 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
821 type
= wp
->w_redr_type
;
823 if (type
== NOT_VALID
)
826 wp
->w_redr_status
= TRUE
;
828 wp
->w_lines_valid
= 0;
831 /* Window is zero-height: nothing to draw. */
832 if (wp
->w_height
== 0)
838 #ifdef FEAT_VERTSPLIT
839 /* Window is zero-width: Only need to draw the separator. */
840 if (wp
->w_width
== 0)
842 /* draw the vertical separator right of this window */
843 draw_vsep_win(wp
, 0);
849 #ifdef FEAT_SEARCH_EXTRA
850 /* Setup for ":match" and 'hlsearch' highlighting. Disable any previous
852 for (i
= 0; i
< 3; ++i
)
854 match_hl
[i
].rm
= wp
->w_match
[i
];
855 if (wp
->w_match_id
[i
] == 0)
856 match_hl
[i
].attr
= 0;
858 match_hl
[i
].attr
= syn_id2attr(wp
->w_match_id
[i
]);
859 match_hl
[i
].buf
= buf
;
860 match_hl
[i
].lnum
= 0;
861 match_hl
[i
].first_lnum
= 0;
865 search_hl
.first_lnum
= 0;
868 #ifdef FEAT_LINEBREAK
869 /* Force redraw when width of 'number' column changes. */
870 i
= wp
->w_p_nu
? number_width(wp
) : 0;
871 if (wp
->w_nrwidth
!= i
)
879 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
882 * When there are both inserted/deleted lines and specific lines to be
883 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
884 * everything (only happens when redrawing is off for while).
891 * Set mod_top to the first line that needs displaying because of
892 * changes. Set mod_bot to the first line after the changes.
894 mod_top
= wp
->w_redraw_top
;
895 if (wp
->w_redraw_bot
!= 0)
896 mod_bot
= wp
->w_redraw_bot
+ 1;
899 wp
->w_redraw_top
= 0; /* reset for next time */
900 wp
->w_redraw_bot
= 0;
903 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
905 mod_top
= buf
->b_mod_top
;
907 /* Need to redraw lines above the change that may be included
908 * in a pattern match. */
909 if (syntax_present(buf
))
911 mod_top
-= buf
->b_syn_sync_linebreaks
;
917 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
918 mod_bot
= buf
->b_mod_bot
;
920 #ifdef FEAT_SEARCH_EXTRA
921 /* When 'hlsearch' is on and using a multi-line search pattern, a
922 * change in one line may make the Search highlighting in a
923 * previous line invalid. Simple solution: redraw all visible
924 * lines above the change.
925 * Same for a ":match" pattern.
927 if (search_hl
.rm
.regprog
!= NULL
928 && re_multiline(search_hl
.rm
.regprog
))
931 for (i
= 0; i
< 3; ++i
)
932 if (match_hl
[i
].rm
.regprog
!= NULL
933 && re_multiline(match_hl
[i
].rm
.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 */
1032 * If there are no changes on the screen that require a complete redraw,
1033 * handle three cases:
1034 * 1: we are off the top of the screen by a few lines: scroll down
1035 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1036 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1037 * w_lines[] that needs updating.
1039 if ((type
== VALID
|| type
== SOME_VALID
1040 || type
== INVERTED
|| type
== INVERTED_ALL
)
1042 && !wp
->w_botfill
&& !wp
->w_old_botfill
1046 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1049 * w_topline is the first changed line, the scrolling will be done
1053 else if (wp
->w_lines
[0].wl_valid
1054 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1056 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1057 && wp
->w_topfill
> wp
->w_old_topfill
)
1062 * New topline is above old topline: May scroll down.
1065 if (hasAnyFolding(wp
))
1069 /* count the number of lines we are off, counting a sequence
1070 * of folded lines as one */
1072 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1075 if (j
>= wp
->w_height
- 2)
1077 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1082 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1083 if (j
< wp
->w_height
- 2) /* not too far off */
1085 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1087 /* insert extra lines for previously invisible filler lines */
1088 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1089 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1090 - wp
->w_old_topfill
;
1092 if (i
< wp
->w_height
- 2) /* less than a screen off */
1095 * Try to insert the correct number of lines.
1096 * If not the last window, delete the lines at the bottom.
1097 * win_ins_lines may fail when the terminal can't do it.
1100 check_for_delay(FALSE
);
1101 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1103 if (wp
->w_lines_valid
!= 0)
1105 /* Need to update rows that are new, stop at the
1106 * first one that scrolled down. */
1109 scrolled_down
= TRUE
;
1112 /* Move the entries that were scrolled, disable
1113 * the entries for the lines to be redrawn. */
1114 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1115 wp
->w_lines_valid
= wp
->w_height
;
1116 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1117 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1119 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1123 mid_start
= 0; /* redraw all lines */
1126 mid_start
= 0; /* redraw all lines */
1129 mid_start
= 0; /* redraw all lines */
1134 * New topline is at or below old topline: May scroll up.
1135 * When topline didn't change, find first entry in w_lines[] that
1139 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1142 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1144 if (wp
->w_lines
[i
].wl_valid
1145 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1150 row
+= wp
->w_lines
[i
].wl_size
;
1154 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1161 * Try to delete the correct number of lines.
1162 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1165 /* If the topline didn't change, delete old filler lines,
1166 * otherwise delete filler lines of the new topline... */
1167 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1168 row
+= wp
->w_old_topfill
;
1170 row
+= diff_check_fill(wp
, wp
->w_topline
);
1171 /* ... but don't delete new filler lines. */
1172 row
-= wp
->w_topfill
;
1176 check_for_delay(FALSE
);
1177 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1178 bot_start
= wp
->w_height
- row
;
1180 mid_start
= 0; /* redraw all lines */
1182 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1185 * Skip the lines (below the deleted lines) that are still
1186 * valid and don't need redrawing. Copy their info
1187 * upwards, to compensate for the deleted lines. Set
1188 * bot_start to the first row that needs redrawing.
1194 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1195 /* stop at line that didn't fit, unless it is still
1196 * valid (no lines deleted) */
1197 if (row
> 0 && bot_start
+ row
1198 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1200 wp
->w_lines_valid
= idx
+ 1;
1203 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1205 /* stop at the last valid entry in w_lines[].wl_size */
1206 if (++j
>= wp
->w_lines_valid
)
1208 wp
->w_lines_valid
= idx
;
1213 /* Correct the first entry for filler lines at the top
1214 * when it won't get updated below. */
1215 if (wp
->w_p_diff
&& bot_start
> 0)
1216 wp
->w_lines
[0].wl_size
=
1217 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1224 /* When starting redraw in the first line, redraw all lines. When
1225 * there is only one window it's probably faster to clear the screen
1229 mid_end
= wp
->w_height
;
1230 if (lastwin
== firstwin
)
1234 /* The screen was cleared, redraw the tab pages line. */
1243 /* Not VALID or INVERTED: redraw all lines. */
1245 mid_end
= wp
->w_height
;
1248 if (type
== SOME_VALID
)
1250 /* SOME_VALID: redraw all lines. */
1252 mid_end
= wp
->w_height
;
1257 /* check if we are updating or removing the inverted part */
1258 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1259 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1266 && (VIsual_mode
!= wp
->w_old_visual_mode
1267 || type
== INVERTED_ALL
))
1270 * If the type of Visual selection changed, redraw the whole
1271 * selection. Also when the ownership of the X selection is
1274 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1276 from
= curwin
->w_cursor
.lnum
;
1282 to
= curwin
->w_cursor
.lnum
;
1284 /* redraw more when the cursor moved as well */
1285 if (wp
->w_old_cursor_lnum
< from
)
1286 from
= wp
->w_old_cursor_lnum
;
1287 if (wp
->w_old_cursor_lnum
> to
)
1288 to
= wp
->w_old_cursor_lnum
;
1289 if (wp
->w_old_visual_lnum
< from
)
1290 from
= wp
->w_old_visual_lnum
;
1291 if (wp
->w_old_visual_lnum
> to
)
1292 to
= wp
->w_old_visual_lnum
;
1297 * Find the line numbers that need to be updated: The lines
1298 * between the old cursor position and the current cursor
1299 * position. Also check if the Visual position changed.
1301 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1303 from
= curwin
->w_cursor
.lnum
;
1304 to
= wp
->w_old_cursor_lnum
;
1308 from
= wp
->w_old_cursor_lnum
;
1309 to
= curwin
->w_cursor
.lnum
;
1310 if (from
== 0) /* Visual mode just started */
1314 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1315 || VIsual
.col
!= wp
->w_old_visual_col
)
1317 if (wp
->w_old_visual_lnum
< from
1318 && wp
->w_old_visual_lnum
!= 0)
1319 from
= wp
->w_old_visual_lnum
;
1320 if (wp
->w_old_visual_lnum
> to
)
1321 to
= wp
->w_old_visual_lnum
;
1322 if (VIsual
.lnum
< from
)
1324 if (VIsual
.lnum
> to
)
1330 * If in block mode and changed column or curwin->w_curswant:
1332 * First compute the actual start and end column.
1334 if (VIsual_mode
== Ctrl_V
)
1338 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1340 if (curwin
->w_curswant
== MAXCOL
)
1343 if (fromc
!= wp
->w_old_cursor_fcol
1344 || toc
!= wp
->w_old_cursor_lcol
)
1346 if (from
> VIsual
.lnum
)
1348 if (to
< VIsual
.lnum
)
1351 wp
->w_old_cursor_fcol
= fromc
;
1352 wp
->w_old_cursor_lcol
= toc
;
1357 /* Use the line numbers of the old Visual area. */
1358 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1360 from
= wp
->w_old_cursor_lnum
;
1361 to
= wp
->w_old_visual_lnum
;
1365 from
= wp
->w_old_visual_lnum
;
1366 to
= wp
->w_old_cursor_lnum
;
1371 * There is no need to update lines above the top of the window.
1373 if (from
< wp
->w_topline
)
1374 from
= wp
->w_topline
;
1377 * If we know the value of w_botline, use it to restrict the update to
1378 * the lines that are visible in the window.
1380 if (wp
->w_valid
& VALID_BOTLINE
)
1382 if (from
>= wp
->w_botline
)
1383 from
= wp
->w_botline
- 1;
1384 if (to
>= wp
->w_botline
)
1385 to
= wp
->w_botline
- 1;
1389 * Find the minimal part to be updated.
1390 * Watch out for scrolling that made entries in w_lines[] invalid.
1391 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1392 * top_end; need to redraw from top_end to the "to" line.
1393 * A middle mouse click with a Visual selection may change the text
1394 * above the Visual area and reset wl_valid, do count these for
1395 * mid_end (in srow).
1399 lnum
= wp
->w_topline
;
1403 mid_start
= top_end
;
1406 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1408 if (wp
->w_lines
[idx
].wl_valid
)
1409 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1410 else if (!scrolled_down
)
1411 srow
+= wp
->w_lines
[idx
].wl_size
;
1413 # ifdef FEAT_FOLDING
1414 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1415 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1421 mid_end
= wp
->w_height
;
1422 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1424 if (wp
->w_lines
[idx
].wl_valid
1425 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1427 /* Only update until first row of this line */
1431 srow
+= wp
->w_lines
[idx
].wl_size
;
1436 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1438 wp
->w_old_visual_mode
= VIsual_mode
;
1439 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1440 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1441 wp
->w_old_visual_col
= VIsual
.col
;
1442 wp
->w_old_curswant
= curwin
->w_curswant
;
1446 wp
->w_old_visual_mode
= 0;
1447 wp
->w_old_cursor_lnum
= 0;
1448 wp
->w_old_visual_lnum
= 0;
1449 wp
->w_old_visual_col
= 0;
1451 #endif /* FEAT_VISUAL */
1453 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1454 /* reset got_int, otherwise regexp won't work */
1455 save_got_int
= got_int
;
1459 win_foldinfo
.fi_level
= 0;
1463 * Update all the window rows.
1465 idx
= 0; /* first entry in w_lines[].wl_size */
1468 lnum
= wp
->w_topline
; /* first line shown in window */
1471 /* stop updating when reached the end of the window (check for _past_
1472 * the end of the window is at the end of the loop) */
1473 if (row
== wp
->w_height
)
1479 /* stop updating when hit the end of the file */
1480 if (lnum
> buf
->b_ml
.ml_line_count
)
1486 /* Remember the starting row of the line that is going to be dealt
1487 * with. It is used further down when the line doesn't fit. */
1491 * Update a line when it is in an area that needs updating, when it
1492 * has changes or w_lines[idx] is invalid.
1493 * bot_start may be halfway a wrapped line after using
1494 * win_del_lines(), check if the current line includes it.
1495 * When syntax folding is being used, the saved syntax states will
1496 * already have been updated, we can't see where the syntax state is
1497 * the same again, just update until the end of the window.
1500 || (row
>= mid_start
&& row
< mid_end
)
1501 #ifdef FEAT_SEARCH_EXTRA
1504 || idx
>= wp
->w_lines_valid
1505 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1511 || did_update
== DID_FOLD
1512 || (did_update
== DID_LINE
1513 && syntax_present(buf
)
1515 # ifdef FEAT_FOLDING
1516 (foldmethodIsSyntax(wp
)
1517 && hasAnyFolding(wp
)) ||
1519 syntax_check_changed(lnum
)))
1523 #ifdef FEAT_SEARCH_EXTRA
1524 if (lnum
== mod_top
)
1529 * When at start of changed lines: May scroll following lines
1530 * up or down to minimize redrawing.
1531 * Don't do this when the change continues until the end.
1532 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1535 && mod_bot
!= MAXLNUM
1536 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1543 /* Count the old number of window rows, using w_lines[], which
1544 * should still contain the sizes for the lines as they are
1545 * currently displayed. */
1546 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1548 /* Only valid lines have a meaningful wl_lnum. Invalid
1549 * lines are part of the changed area. */
1550 if (wp
->w_lines
[i
].wl_valid
1551 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1553 old_rows
+= wp
->w_lines
[i
].wl_size
;
1555 if (wp
->w_lines
[i
].wl_valid
1556 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1558 /* Must have found the last valid entry above mod_bot.
1559 * Add following invalid entries. */
1561 while (i
< wp
->w_lines_valid
1562 && !wp
->w_lines
[i
].wl_valid
)
1563 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1569 if (i
>= wp
->w_lines_valid
)
1571 /* We can't find a valid line below the changed lines,
1572 * need to redraw until the end of the window.
1573 * Inserting/deleting lines has no use. */
1578 /* Able to count old number of rows: Count new window
1579 * rows, and may insert/delete lines */
1581 for (l
= lnum
; l
< mod_bot
; ++l
)
1584 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1589 if (l
== wp
->w_topline
)
1590 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1594 new_rows
+= plines_win(wp
, l
, TRUE
);
1596 if (new_rows
> wp
->w_height
- row
- 2)
1598 /* it's getting too much, must redraw the rest */
1603 xtra_rows
= new_rows
- old_rows
;
1606 /* May scroll text up. If there is not enough
1607 * remaining text or scrolling fails, must redraw the
1608 * rest. If scrolling works, must redraw the text
1609 * below the scrolled text. */
1610 if (row
- xtra_rows
>= wp
->w_height
- 2)
1614 check_for_delay(FALSE
);
1615 if (win_del_lines(wp
, row
,
1616 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1619 bot_start
= wp
->w_height
+ xtra_rows
;
1622 else if (xtra_rows
> 0)
1624 /* May scroll text down. If there is not enough
1625 * remaining text of scrolling fails, must redraw the
1627 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1631 check_for_delay(FALSE
);
1632 if (win_ins_lines(wp
, row
+ old_rows
,
1633 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1635 else if (top_end
> row
+ old_rows
)
1636 /* Scrolled the part at the top that requires
1638 top_end
+= xtra_rows
;
1642 /* When not updating the rest, may need to move w_lines[]
1644 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1648 int x
= row
+ new_rows
;
1650 /* move entries in w_lines[] upwards */
1653 /* stop at last valid entry in w_lines[] */
1654 if (i
>= wp
->w_lines_valid
)
1656 wp
->w_lines_valid
= j
;
1659 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1660 /* stop at a line that won't fit */
1661 if (x
+ (int)wp
->w_lines
[j
].wl_size
1664 wp
->w_lines_valid
= j
+ 1;
1667 x
+= wp
->w_lines
[j
++].wl_size
;
1675 /* move entries in w_lines[] downwards */
1677 wp
->w_lines_valid
+= j
;
1678 if (wp
->w_lines_valid
> wp
->w_height
)
1679 wp
->w_lines_valid
= wp
->w_height
;
1680 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1681 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1683 /* The w_lines[] entries for inserted lines are
1684 * now invalid, but wl_size may be used above.
1688 wp
->w_lines
[i
].wl_size
= 0;
1689 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1698 * When lines are folded, display one line for all of them.
1699 * Otherwise, display normally (can be several display lines when
1702 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1703 if (fold_count
!= 0)
1705 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1708 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1709 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1711 did_update
= DID_FOLD
;
1716 if (idx
< wp
->w_lines_valid
1717 && wp
->w_lines
[idx
].wl_valid
1718 && wp
->w_lines
[idx
].wl_lnum
== lnum
1719 && lnum
> wp
->w_topline
1720 && !(dy_flags
& DY_LASTLINE
)
1721 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1723 && diff_check_fill(wp
, lnum
) == 0
1727 /* This line is not going to fit. Don't draw anything here,
1728 * will draw "@ " lines below. */
1729 row
= wp
->w_height
+ 1;
1733 #ifdef FEAT_SEARCH_EXTRA
1734 prepare_search_hl(wp
, lnum
);
1737 /* Let the syntax stuff know we skipped a few lines. */
1738 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1739 && syntax_present(buf
))
1740 syntax_end_parsing(syntax_last_parsed
+ 1);
1746 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1749 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1750 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1753 did_update
= DID_LINE
;
1754 syntax_last_parsed
= lnum
;
1758 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1759 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1760 if (row
> wp
->w_height
) /* past end of screen */
1762 /* we may need the size of that too long line later on */
1763 if (dollar_vcol
== 0)
1764 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1768 if (dollar_vcol
== 0)
1769 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1772 lnum
+= fold_count
+ 1;
1779 /* This line does not need updating, advance to the next one */
1780 row
+= wp
->w_lines
[idx
++].wl_size
;
1781 if (row
> wp
->w_height
) /* past end of screen */
1784 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1789 did_update
= DID_NONE
;
1793 if (lnum
> buf
->b_ml
.ml_line_count
)
1800 * End of loop over all window lines.
1804 if (idx
> wp
->w_lines_valid
)
1805 wp
->w_lines_valid
= idx
;
1809 * Let the syntax stuff know we stop parsing here.
1811 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1812 syntax_end_parsing(syntax_last_parsed
+ 1);
1816 * If we didn't hit the end of the file, and we didn't finish the last
1817 * line we were working on, then the line didn't fit.
1819 wp
->w_empty_rows
= 0;
1821 wp
->w_filler_rows
= 0;
1823 if (!eof
&& !didline
)
1825 if (lnum
== wp
->w_topline
)
1828 * Single line that does not fit!
1829 * Don't overwrite it, it can be edited.
1831 wp
->w_botline
= lnum
+ 1;
1834 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1836 /* Window ends in filler lines. */
1837 wp
->w_botline
= lnum
;
1838 wp
->w_filler_rows
= wp
->w_height
- srow
;
1841 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1844 * Last line isn't finished: Display "@@@" at the end.
1846 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1847 W_WINROW(wp
) + wp
->w_height
,
1848 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1849 '@', '@', hl_attr(HLF_AT
));
1850 set_empty_rows(wp
, srow
);
1851 wp
->w_botline
= lnum
;
1855 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1856 wp
->w_botline
= lnum
;
1861 #ifdef FEAT_VERTSPLIT
1862 draw_vsep_win(wp
, row
);
1864 if (eof
) /* we hit the end of the file */
1866 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1868 j
= diff_check_fill(wp
, wp
->w_botline
);
1869 if (j
> 0 && !wp
->w_botfill
)
1872 * Display filler lines at the end of the file
1874 if (char2cells(fill_diff
) > 1)
1878 if (row
+ j
> wp
->w_height
)
1879 j
= wp
->w_height
- row
;
1880 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1885 else if (dollar_vcol
== 0)
1886 wp
->w_botline
= lnum
;
1888 /* make sure the rest of the screen is blank */
1889 /* put '~'s on rows that aren't part of the file. */
1890 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1893 /* Reset the type of redrawing required, the window has been updated. */
1894 wp
->w_redr_type
= 0;
1896 wp
->w_old_topfill
= wp
->w_topfill
;
1897 wp
->w_old_botfill
= wp
->w_botfill
;
1900 if (dollar_vcol
== 0)
1903 * There is a trick with w_botline. If we invalidate it on each
1904 * change that might modify it, this will cause a lot of expensive
1905 * calls to plines() in update_topline() each time. Therefore the
1906 * value of w_botline is often approximated, and this value is used to
1907 * compute the value of w_topline. If the value of w_botline was
1908 * wrong, check that the value of w_topline is correct (cursor is on
1909 * the visible part of the text). If it's not, we need to redraw
1910 * again. Mostly this just means scrolling up a few lines, so it
1911 * doesn't look too bad. Only do this for the current window (where
1912 * changes are relevant).
1914 wp
->w_valid
|= VALID_BOTLINE
;
1915 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1918 curwin
->w_valid
&= ~VALID_TOPLINE
;
1919 update_topline(); /* may invalidate w_botline again */
1920 if (must_redraw
!= 0)
1922 /* Don't update for changes in buffer again. */
1923 i
= curbuf
->b_mod_set
;
1924 curbuf
->b_mod_set
= FALSE
;
1927 curbuf
->b_mod_set
= i
;
1933 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1934 /* restore got_int, unless CTRL-C was hit while redrawing */
1936 got_int
= save_got_int
;
1941 static int draw_signcolumn
__ARGS((win_T
*wp
));
1944 * Return TRUE when window "wp" has a column to draw signs in.
1950 return (wp
->w_buffer
->b_signlist
!= NULL
1951 # ifdef FEAT_NETBEANS_INTG
1959 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1960 * as the filler character.
1963 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
1971 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
1978 #ifdef FEAT_RIGHTLEFT
1981 /* No check for cmdline window: should never be right-left. */
1982 # ifdef FEAT_FOLDING
1987 /* draw the fold column at the right */
1988 if (n
> W_WIDTH(wp
))
1990 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
1991 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
1992 ' ', ' ', hl_attr(HLF_FC
));
1996 if (draw_signcolumn(wp
))
2000 /* draw the sign column left of the fold column */
2001 if (nn
> W_WIDTH(wp
))
2003 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2004 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2005 ' ', ' ', hl_attr(HLF_SC
));
2009 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2010 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2011 c2
, c2
, hl_attr(hl
));
2012 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2013 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2014 c1
, c2
, hl_attr(hl
));
2020 if (cmdwin_type
!= 0 && wp
== curwin
)
2022 /* draw the cmdline character in the leftmost column */
2024 if (n
> wp
->w_width
)
2026 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2027 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2028 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2032 if (wp
->w_p_fdc
> 0)
2034 int nn
= n
+ wp
->w_p_fdc
;
2036 /* draw the fold column at the left */
2037 if (nn
> W_WIDTH(wp
))
2039 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2040 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2041 ' ', ' ', hl_attr(HLF_FC
));
2046 if (draw_signcolumn(wp
))
2050 /* draw the sign column after the fold column */
2051 if (nn
> W_WIDTH(wp
))
2053 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2054 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2055 ' ', ' ', hl_attr(HLF_SC
));
2059 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2060 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2061 c1
, c2
, hl_attr(hl
));
2063 set_empty_rows(wp
, row
);
2068 * Display one folded line.
2071 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2074 foldinfo_T
*foldinfo
;
2080 linenr_T lnume
= lnum
+ fold_count
- 1;
2086 int off
= (int)(current_ScreenLine
- ScreenLines
);
2089 /* Build the fold line:
2090 * 1. Add the cmdwin_type for the command-line window
2091 * 2. Add the 'foldcolumn'
2092 * 3. Add the 'number' column
2093 * 4. Compose the text
2095 * 6. set highlighting for the Visual area an other text
2100 * 1. Add the cmdwin_type for the command-line window
2101 * Ignores 'rightleft', this window is never right-left.
2104 if (cmdwin_type
!= 0 && wp
== curwin
)
2106 ScreenLines
[off
] = cmdwin_type
;
2107 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2110 ScreenLinesUC
[off
] = 0;
2117 * 2. Add the 'foldcolumn'
2120 if (fdc
> W_WIDTH(wp
) - col
)
2121 fdc
= W_WIDTH(wp
) - col
;
2124 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2125 #ifdef FEAT_RIGHTLEFT
2130 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2132 /* reverse the fold column */
2133 for (i
= 0; i
< fdc
; ++i
)
2134 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2138 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2142 #ifdef FEAT_RIGHTLEFT
2143 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2144 for (ri = 0; ri < l; ++ri) \
2145 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2147 for (ri = 0; ri < l; ++ri) \
2148 ScreenAttrs[off + (p) + ri] = v
2150 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2151 ScreenAttrs[off + (p) + ri] = v
2154 /* Set all attributes of the 'number' column and the text */
2155 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2158 /* If signs are being displayed, add two spaces. */
2159 if (draw_signcolumn(wp
))
2161 len
= W_WIDTH(wp
) - col
;
2166 # ifdef FEAT_RIGHTLEFT
2168 /* the line number isn't reversed */
2169 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2170 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2173 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2180 * 3. Add the 'number' column
2184 len
= W_WIDTH(wp
) - col
;
2187 int w
= number_width(wp
);
2191 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2192 #ifdef FEAT_RIGHTLEFT
2194 /* the line number isn't reversed */
2195 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2199 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2205 * 4. Compose the folded-line string with 'foldtext', if set.
2207 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2209 txtcol
= col
; /* remember where text starts */
2212 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2213 * Right-left text is put in columns 0 - number-col, normal text is put
2214 * in columns number-col - window-width.
2220 int u8c
, u8cc
[MAX_MCO
];
2226 int prev_c
= 0; /* previous Arabic character */
2227 int prev_c1
= 0; /* first composing char for prev_c */
2230 # ifdef FEAT_RIGHTLEFT
2237 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2238 for (p
= text
; *p
!= NUL
; )
2240 cells
= (*mb_ptr2cells
)(p
);
2241 c_len
= (*mb_ptr2len
)(p
);
2242 if (col
+ cells
> W_WIDTH(wp
)
2243 # ifdef FEAT_RIGHTLEFT
2244 - (wp
->w_p_rl
? col
: 0)
2248 ScreenLines
[idx
] = *p
;
2251 u8c
= utfc_ptr2char(p
, u8cc
);
2252 if (*p
< 0x80 && u8cc
[0] == 0)
2254 ScreenLinesUC
[idx
] = 0;
2262 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2264 /* Do Arabic shaping. */
2269 /* The idea of what is the previous and next
2270 * character depends on 'rightleft'. */
2275 nc
= utf_ptr2char(p
+ c_len
);
2280 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2286 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2288 ScreenLines
[idx
] = firstbyte
;
2293 /* Non-BMP character: display as ? or fullwidth ?. */
2295 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2297 ScreenLinesUC
[idx
] = u8c
;
2298 for (i
= 0; i
< Screen_mco
; ++i
)
2300 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2306 ScreenLines
[idx
+ 1] = 0;
2308 else if (cells
> 1) /* double-byte character */
2310 if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2311 ScreenLines2
[idx
] = p
[1];
2313 ScreenLines
[idx
+ 1] = p
[1];
2323 len
= (int)STRLEN(text
);
2324 if (len
> W_WIDTH(wp
) - col
)
2325 len
= W_WIDTH(wp
) - col
;
2328 #ifdef FEAT_RIGHTLEFT
2330 STRNCPY(current_ScreenLine
, text
, len
);
2333 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2338 /* Fill the rest of the line with the fold filler */
2339 #ifdef FEAT_RIGHTLEFT
2343 while (col
< W_WIDTH(wp
)
2344 #ifdef FEAT_RIGHTLEFT
2345 - (wp
->w_p_rl
? txtcol
: 0)
2352 if (fill_fold
>= 0x80)
2354 ScreenLinesUC
[off
+ col
] = fill_fold
;
2355 ScreenLinesC
[0][off
+ col
] = 0;
2358 ScreenLinesUC
[off
+ col
] = 0;
2361 ScreenLines
[off
+ col
++] = fill_fold
;
2368 * 6. set highlighting for the Visual area an other text.
2369 * If all folded lines are in the Visual area, highlight the line.
2372 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2374 if (ltoreq(curwin
->w_cursor
, VIsual
))
2376 /* Visual is after curwin->w_cursor */
2377 top
= &curwin
->w_cursor
;
2382 /* Visual is before curwin->w_cursor */
2384 bot
= &curwin
->w_cursor
;
2386 if (lnum
>= top
->lnum
2387 && lnume
<= bot
->lnum
2388 && (VIsual_mode
!= 'v'
2389 || ((lnum
> top
->lnum
2390 || (lnum
== top
->lnum
2392 && (lnume
< bot
->lnum
2393 || (lnume
== bot
->lnum
2394 && (bot
->col
- (*p_sel
== 'e'))
2395 >= STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2397 if (VIsual_mode
== Ctrl_V
)
2399 /* Visual block mode: highlight the chars part of the block */
2400 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2402 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2403 len
= wp
->w_old_cursor_lcol
;
2405 len
= W_WIDTH(wp
) - txtcol
;
2406 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2407 len
- (int)wp
->w_old_cursor_fcol
);
2412 /* Set all attributes of the text */
2413 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2420 /* Show 'cursorcolumn' in the fold line. */
2421 if (wp
->w_p_cuc
&& (int)wp
->w_virtcol
+ txtcol
< W_WIDTH(wp
))
2422 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
] = hl_combine_attr(
2423 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
], hl_attr(HLF_CUC
));
2426 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2427 (int)W_WIDTH(wp
), FALSE
);
2430 * Update w_cline_height and w_cline_folded if the cursor line was
2431 * updated (saves a call to plines() later).
2434 && lnum
<= curwin
->w_cursor
.lnum
2435 && lnume
>= curwin
->w_cursor
.lnum
)
2437 curwin
->w_cline_row
= row
;
2438 curwin
->w_cline_height
= 1;
2439 curwin
->w_cline_folded
= TRUE
;
2440 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2445 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2448 copy_text_attr(off
, buf
, len
, attr
)
2456 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2459 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2461 for (i
= 0; i
< len
; ++i
)
2462 ScreenAttrs
[off
+ i
] = attr
;
2466 * Fill the foldcolumn at "p" for window "wp".
2467 * Only to be called when 'foldcolumn' > 0.
2470 fill_foldcolumn(p
, wp
, closed
, lnum
)
2473 int closed
; /* TRUE of FALSE */
2474 linenr_T lnum
; /* current line number */
2481 /* Init to all spaces. */
2482 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2484 level
= win_foldinfo
.fi_level
;
2487 /* If there is only one column put more info in it. */
2488 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2490 /* If the column is too narrow, we start at the lowest level that
2491 * fits and use numbers to indicated the depth. */
2492 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2493 if (first_level
< 1)
2496 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2498 if (win_foldinfo
.fi_lnum
== lnum
2499 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2501 else if (first_level
== 1)
2503 else if (first_level
+ i
<= 9)
2504 p
[i
] = '0' + first_level
+ i
;
2507 if (first_level
+ i
== level
)
2512 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2514 #endif /* FEAT_FOLDING */
2517 * Display line "lnum" of window 'wp' on the screen.
2518 * Start at row "startrow", stop when "endrow" is reached.
2519 * wp->w_virtcol needs to be valid.
2521 * Return the number of last row the line occupies.
2525 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2530 int nochange
; /* not updating for changed text */
2532 int col
; /* visual column on screen */
2533 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2534 int c
= 0; /* init for GCC */
2535 long vcol
= 0; /* virtual column (for tabs) */
2536 long vcol_prev
= -1; /* "vcol" of previous character */
2537 char_u
*line
; /* current line */
2538 char_u
*ptr
; /* current position in "line" */
2539 int row
; /* row in the window, excl w_winrow */
2540 int screen_row
; /* row on the screen, incl w_winrow */
2542 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2543 int n_extra
= 0; /* number of extra chars */
2544 char_u
*p_extra
= NULL
; /* string of extra chars */
2545 int c_extra
= NUL
; /* extra chars, all the same */
2546 int extra_attr
= 0; /* attributes when n_extra != 0 */
2547 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2548 displaying lcs_eol at end-of-line */
2549 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2550 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2552 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2553 int saved_n_extra
= 0;
2554 char_u
*saved_p_extra
= NULL
;
2555 int saved_c_extra
= 0;
2556 int saved_char_attr
= 0;
2558 int n_attr
= 0; /* chars with special attr */
2559 int saved_attr2
= 0; /* char_attr saved for n_attr */
2560 int n_attr3
= 0; /* chars with overruling special attr */
2561 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2563 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2565 int fromcol
, tocol
; /* start/end of inverting */
2566 int fromcol_prev
= -2; /* start of inverting after cursor */
2567 int noinvcur
= FALSE
; /* don't invert the cursor */
2574 int char_attr
= 0; /* attributes for next character */
2575 int attr_pri
= FALSE
; /* char_attr has priority */
2576 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2578 int attr
= 0; /* attributes for area highlighting */
2579 int area_attr
= 0; /* attributes desired by highlighting */
2580 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2582 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2583 int syntax_attr
= 0; /* attributes desired by syntax */
2584 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2588 int has_spell
= FALSE
; /* this buffer has spell checking */
2589 # define SPWORDLEN 150
2590 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2591 int nextlinecol
= 0; /* column where nextline[] starts */
2592 int nextline_idx
= 0; /* index in nextline[] where next line
2594 int spell_attr
= 0; /* attributes desired by spelling */
2595 int word_end
= 0; /* last byte with same spell_attr */
2596 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2597 static int checked_col
= 0; /* column in "checked_lnum" up to which
2598 * there are no spell errors */
2599 static int cap_col
= -1; /* column to check for Cap word */
2600 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2601 int cur_checked_col
= 0; /* checked column for current line */
2603 int extra_check
; /* has syntax or linebreak */
2605 int multi_attr
= 0; /* attributes desired by multibyte */
2606 int mb_l
= 1; /* multi-byte byte length */
2607 int mb_c
= 0; /* decoded multi-byte character */
2608 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2609 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2612 int filler_lines
; /* nr of filler lines to be drawn */
2613 int filler_todo
; /* nr of filler lines still to do + 1 */
2614 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2615 int change_start
= MAXCOL
; /* first col of changed area */
2616 int change_end
= -1; /* last col of changed area */
2618 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2619 #ifdef FEAT_LINEBREAK
2620 int need_showbreak
= FALSE
;
2622 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2623 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2625 int line_attr
= 0; /* atrribute for the whole line */
2627 #ifdef FEAT_SEARCH_EXTRA
2628 match_T
*shl
; /* points to search_hl or match_hl */
2630 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_MBYTE)
2634 int prev_c
= 0; /* previous Arabic character */
2635 int prev_c1
= 0; /* first composing char for prev_c */
2637 #if defined(LINE_ATTR)
2638 int did_line_attr
= 0;
2641 /* draw_state: items that are drawn in sequence: */
2642 #define WL_START 0 /* nothing done yet */
2644 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2646 # define WL_CMDLINE WL_START
2649 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2651 # define WL_FOLD WL_CMDLINE
2654 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2656 # define WL_SIGN WL_FOLD /* column for signs */
2658 #define WL_NR WL_SIGN + 1 /* line number */
2659 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2660 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2662 # define WL_SBR WL_NR
2664 #define WL_LINE WL_SBR + 1 /* text in the line */
2665 int draw_state
= WL_START
; /* what to draw next */
2666 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2667 int feedback_col
= 0;
2668 int feedback_old_attr
= -1;
2672 if (startrow
> endrow
) /* past the end already! */
2676 screen_row
= row
+ W_WINROW(wp
);
2679 * To speed up the loop below, set extra_check when there is linebreak,
2680 * trailing white space and/or syntax processing to be done.
2682 #ifdef FEAT_LINEBREAK
2683 extra_check
= wp
->w_p_lbr
;
2688 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2690 /* Prepare for syntax highlighting in this line. When there is an
2691 * error, stop syntax highlighting. */
2692 save_did_emsg
= did_emsg
;
2694 syntax_start(wp
, lnum
);
2696 wp
->w_buffer
->b_syn_error
= TRUE
;
2699 did_emsg
= save_did_emsg
;
2708 && *wp
->w_buffer
->b_p_spl
!= NUL
2709 && wp
->w_buffer
->b_langp
.ga_len
> 0
2710 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2712 /* Prepare for spell checking. */
2716 /* Get the start of the next line, so that words that wrap to the next
2717 * line are found too: "et<line-break>al.".
2718 * Trick: skip a few chars for C/shell/Vim comments */
2719 nextline
[SPWORDLEN
] = NUL
;
2720 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2722 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2723 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2726 /* When a word wrapped from the previous line the start of the current
2728 if (lnum
== checked_lnum
)
2729 cur_checked_col
= checked_col
;
2732 /* When there was a sentence end in the previous line may require a
2733 * word starting with capital in this line. In line 1 always check
2734 * the first word. */
2735 if (lnum
!= capcol_lnum
)
2744 * handle visual active in this window
2749 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2751 /* Visual is after curwin->w_cursor */
2752 if (ltoreq(curwin
->w_cursor
, VIsual
))
2754 top
= &curwin
->w_cursor
;
2757 else /* Visual is before curwin->w_cursor */
2760 bot
= &curwin
->w_cursor
;
2762 if (VIsual_mode
== Ctrl_V
) /* block mode */
2764 if (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
)
2766 fromcol
= wp
->w_old_cursor_fcol
;
2767 tocol
= wp
->w_old_cursor_lcol
;
2770 else /* non-block mode */
2772 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2774 else if (lnum
== top
->lnum
)
2776 if (VIsual_mode
== 'V') /* linewise */
2780 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2781 if (gchar_pos(top
) == NUL
)
2782 tocol
= fromcol
+ 1;
2785 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2787 if (*p_sel
== 'e' && bot
->col
== 0
2788 #ifdef FEAT_VIRTUALEDIT
2796 else if (bot
->col
== MAXCOL
)
2802 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2805 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2813 /* Check if the character under the cursor should not be inverted */
2814 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2822 /* if inverting in this line set area_highlighting */
2825 area_highlighting
= TRUE
;
2826 attr
= hl_attr(HLF_V
);
2827 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2828 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2829 attr
= hl_attr(HLF_VNC
);
2835 * handle 'incsearch' and ":s///c" highlighting
2838 #endif /* FEAT_VISUAL */
2841 && lnum
>= curwin
->w_cursor
.lnum
2842 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2844 if (lnum
== curwin
->w_cursor
.lnum
)
2845 getvcol(curwin
, &(curwin
->w_cursor
),
2846 (colnr_T
*)&fromcol
, NULL
, NULL
);
2849 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2852 pos
.col
= search_match_endcol
;
2853 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2857 if (fromcol
== tocol
) /* do at least one character */
2858 tocol
= fromcol
+ 1; /* happens when past end of line */
2859 area_highlighting
= TRUE
;
2860 attr
= hl_attr(HLF_I
);
2864 filler_lines
= diff_check(wp
, lnum
);
2865 if (filler_lines
< 0)
2867 if (filler_lines
== -1)
2869 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2870 diff_hlf
= HLF_ADD
; /* added line */
2871 else if (change_start
== 0)
2872 diff_hlf
= HLF_TXD
; /* changed text */
2874 diff_hlf
= HLF_CHD
; /* changed line */
2877 diff_hlf
= HLF_ADD
; /* added line */
2879 area_highlighting
= TRUE
;
2881 if (lnum
== wp
->w_topline
)
2882 filler_lines
= wp
->w_topfill
;
2883 filler_todo
= filler_lines
;
2888 /* If this line has a sign with line highlighting set line_attr. */
2889 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2891 line_attr
= sign_get_attr((int)v
, TRUE
);
2893 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2894 /* Highlight the current line in the quickfix window. */
2895 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2896 line_attr
= hl_attr(HLF_L
);
2899 area_highlighting
= TRUE
;
2902 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2908 /* For checking first word with a capital skip white space. */
2910 cap_col
= (int)(skipwhite(line
) - line
);
2912 /* To be able to spell-check over line boundaries copy the end of the
2913 * current line into nextline[]. Above the start of the next line was
2914 * copied to nextline[SPWORDLEN]. */
2915 if (nextline
[SPWORDLEN
] == NUL
)
2917 /* No next line or it is empty. */
2918 nextlinecol
= MAXCOL
;
2923 v
= (long)STRLEN(line
);
2926 /* Short line, use it completely and append the start of the
2929 mch_memmove(nextline
, line
, (size_t)v
);
2930 mch_memmove(nextline
+ v
, nextline
+ SPWORDLEN
,
2931 STRLEN(nextline
+ SPWORDLEN
) + 1);
2932 nextline_idx
= v
+ 1;
2936 /* Long line, use only the last SPWORDLEN bytes. */
2937 nextlinecol
= v
- SPWORDLEN
;
2938 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2939 nextline_idx
= SPWORDLEN
+ 1;
2945 /* find start of trailing whitespace */
2946 if (wp
->w_p_list
&& lcs_trail
)
2948 trailcol
= (colnr_T
)STRLEN(ptr
);
2949 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
2951 trailcol
+= (colnr_T
) (ptr
- line
);
2956 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
2957 * first character to be displayed.
2966 char_u
*prev_ptr
= ptr
;
2968 while (vcol
< v
&& *ptr
!= NUL
)
2970 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
2978 #ifdef FEAT_VIRTUALEDIT
2979 /* When 'virtualedit' is set the end of the line may be before the
2980 * start of the displayed part. */
2981 if (vcol
< v
&& *ptr
== NUL
&& virtual_active())
2985 /* Handle a character that's not completely on the screen: Put ptr at
2986 * that character but skip the first few screen characters. */
2999 * Adjust for when the inverted text is before the screen,
3000 * and when the start of the inverted text is before the screen.
3004 else if (fromcol
>= 0 && fromcol
< vcol
)
3007 #ifdef FEAT_LINEBREAK
3008 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3010 need_showbreak
= TRUE
;
3013 /* When spell checking a word we need to figure out the start of the
3014 * word and if it's badly spelled or not. */
3018 hlf_T spell_hlf
= HLF_COUNT
;
3021 wp
->w_cursor
.lnum
= lnum
;
3022 wp
->w_cursor
.col
= (colnr_T
)(ptr
- line
);
3023 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3024 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3026 /* no bad word found at line start, don't check until end of a
3028 spell_hlf
= HLF_COUNT
;
3029 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
) - line
+ 1);
3033 /* bad word found, use attributes until end of word */
3034 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3036 /* Turn index into actual attributes. */
3037 if (spell_hlf
!= HLF_COUNT
)
3038 spell_attr
= highlight_attr
[spell_hlf
];
3043 /* Need to restart syntax highlighting for this line. */
3045 syntax_start(wp
, lnum
);
3052 * Correct highlighting for cursor that can't be disabled.
3053 * Avoids having to check this for each character.
3059 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3061 /* highlighting starts at cursor, let it start just after the
3063 fromcol_prev
= fromcol
;
3066 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3067 /* restart highlighting after the cursor */
3068 fromcol_prev
= wp
->w_virtcol
;
3070 if (fromcol
>= tocol
)
3074 #ifdef FEAT_SEARCH_EXTRA
3076 * Handle highlighting the last used search pattern and ":match".
3077 * Do this for both search_hl and match_hl[3].
3079 for (i
= 3; i
>= 0; --i
)
3081 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
3082 shl
->startcol
= MAXCOL
;
3083 shl
->endcol
= MAXCOL
;
3085 if (shl
->rm
.regprog
!= NULL
)
3087 v
= (long)(ptr
- line
);
3088 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3090 /* Need to get the line again, a multi-line regexp may have made it
3092 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3095 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3097 if (shl
->lnum
== lnum
)
3098 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3101 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3102 - shl
->rm
.startpos
[0].lnum
)
3103 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3105 shl
->endcol
= MAXCOL
;
3106 /* Highlight one character for an empty match. */
3107 if (shl
->startcol
== shl
->endcol
)
3110 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3111 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3116 if ((long)shl
->startcol
< v
) /* match at leftcol */
3118 shl
->attr_cur
= shl
->attr
;
3119 search_attr
= shl
->attr
;
3121 area_highlighting
= TRUE
;
3128 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3129 * active, because it's not clear what is selected then. */
3130 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3132 line_attr
= hl_attr(HLF_CUL
);
3133 area_highlighting
= TRUE
;
3137 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3139 #ifdef FEAT_RIGHTLEFT
3142 /* Rightleft window: process the text in the normal direction, but put
3143 * it in current_ScreenLine[] from right to left. Start at the
3144 * rightmost column of the window. */
3145 col
= W_WIDTH(wp
) - 1;
3151 * Repeat for the whole displayed line.
3155 /* Skip this quickly when working on the text. */
3156 if (draw_state
!= WL_LINE
)
3159 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3161 draw_state
= WL_CMDLINE
;
3162 if (cmdwin_type
!= 0 && wp
== curwin
)
3164 /* Draw the cmdline character. */
3165 *extra
= cmdwin_type
;
3169 char_attr
= hl_attr(HLF_AT
);
3175 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3177 draw_state
= WL_FOLD
;
3178 if (wp
->w_p_fdc
> 0)
3180 /* Draw the 'foldcolumn'. */
3181 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3182 n_extra
= wp
->w_p_fdc
;
3185 char_attr
= hl_attr(HLF_FC
);
3191 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3193 draw_state
= WL_SIGN
;
3194 /* Show the sign column when there are any signs in this
3195 * buffer or when using Netbeans. */
3196 if (draw_signcolumn(wp
)
3203 # ifdef FEAT_SIGN_ICONS
3207 /* Draw two cells with the sign value or blank. */
3209 char_attr
= hl_attr(HLF_SC
);
3212 if (row
== startrow
)
3214 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3216 # ifdef FEAT_SIGN_ICONS
3217 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3219 if (gui
.in_use
&& icon_sign
!= 0)
3221 /* Use the image in this position. */
3222 c_extra
= SIGN_BYTE
;
3223 # ifdef FEAT_NETBEANS_INTG
3224 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3225 c_extra
= MULTISIGN_BYTE
;
3227 char_attr
= icon_sign
;
3233 p_extra
= sign_get_text(text_sign
);
3234 if (p_extra
!= NULL
)
3237 n_extra
= (int)STRLEN(p_extra
);
3239 char_attr
= sign_get_attr(text_sign
, FALSE
);
3246 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3249 /* Display the line number. After the first fill with blanks
3250 * when the 'n' flag isn't in 'cpo' */
3256 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3258 /* Draw the line number (empty space after wrapping). */
3265 sprintf((char *)extra
, "%*ld ",
3266 number_width(wp
), (long)lnum
);
3267 if (wp
->w_skipcol
> 0)
3268 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3270 #ifdef FEAT_RIGHTLEFT
3271 if (wp
->w_p_rl
) /* reverse line numbers */
3279 n_extra
= number_width(wp
) + 1;
3280 char_attr
= hl_attr(HLF_N
);
3282 /* When 'cursorline' is set highlight the line number of
3283 * the current line differently. */
3284 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3285 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3290 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3291 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3293 draw_state
= WL_SBR
;
3295 if (filler_todo
> 0)
3297 /* Draw "deleted" diff line(s). */
3298 if (char2cells(fill_diff
) > 1)
3301 c_extra
= fill_diff
;
3302 # ifdef FEAT_RIGHTLEFT
3307 n_extra
= W_WIDTH(wp
) - col
;
3308 char_attr
= hl_attr(HLF_DED
);
3311 # ifdef FEAT_LINEBREAK
3312 if (*p_sbr
!= NUL
&& need_showbreak
)
3314 /* Draw 'showbreak' at the start of each broken line. */
3317 n_extra
= (int)STRLEN(p_sbr
);
3318 char_attr
= hl_attr(HLF_AT
);
3319 need_showbreak
= FALSE
;
3320 /* Correct end of highlighted area for 'showbreak',
3321 * required when 'linebreak' is also set. */
3329 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3331 draw_state
= WL_LINE
;
3334 /* Continue item from end of wrapped line. */
3335 n_extra
= saved_n_extra
;
3336 c_extra
= saved_c_extra
;
3337 p_extra
= saved_p_extra
;
3338 char_attr
= saved_char_attr
;
3345 /* When still displaying '$' of change command, stop at cursor */
3346 if (dollar_vcol
!= 0 && wp
== curwin
3347 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3353 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3355 /* Pretend we have finished updating the window. Except when
3356 * 'cursorcolumn' is set. */
3359 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3366 if (draw_state
== WL_LINE
&& area_highlighting
)
3368 /* handle Visual or match highlighting in this line */
3371 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3372 && (*mb_ptr2cells
)(ptr
) > 1)
3374 || ((int)vcol_prev
== fromcol_prev
3376 area_attr
= attr
; /* start highlighting */
3377 else if (area_attr
!= 0
3379 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3380 area_attr
= 0; /* stop highlighting */
3382 #ifdef FEAT_SEARCH_EXTRA
3386 * Check for start/end of search pattern match.
3387 * After end, check for start/end of next match.
3388 * When another match, have to check for start again.
3389 * Watch out for matching an empty string!
3390 * Do this first for search_hl, then for match_hl, so that
3391 * ":match" overrules 'hlsearch'.
3393 v
= (long)(ptr
- line
);
3394 for (i
= 3; i
>= 0; --i
)
3396 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
3397 while (shl
->rm
.regprog
!= NULL
)
3399 if (shl
->startcol
!= MAXCOL
3400 && v
>= (long)shl
->startcol
3401 && v
< (long)shl
->endcol
)
3403 shl
->attr_cur
= shl
->attr
;
3405 else if (v
== (long)shl
->endcol
)
3409 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3411 /* Need to get the line again, a multi-line regexp
3412 * may have made it invalid. */
3413 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3416 if (shl
->lnum
== lnum
)
3418 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3419 if (shl
->rm
.endpos
[0].lnum
== 0)
3420 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3422 shl
->endcol
= MAXCOL
;
3424 if (shl
->startcol
== shl
->endcol
)
3426 /* highlight empty match, try again after
3430 shl
->endcol
+= (*mb_ptr2len
)(line
3437 /* Loop to check if the match starts at the
3438 * current position */
3446 /* ":match" highlighting overrules 'hlsearch' */
3447 for (i
= 0; i
<= 3; ++i
)
3449 search_attr
= search_hl
.attr_cur
;
3450 else if (match_hl
[i
].attr_cur
!= 0)
3452 search_attr
= match_hl
[i
].attr_cur
;
3459 if (diff_hlf
!= (hlf_T
)0)
3461 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
)
3462 diff_hlf
= HLF_TXD
; /* changed text */
3463 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
)
3464 diff_hlf
= HLF_CHD
; /* changed line */
3465 line_attr
= hl_attr(diff_hlf
);
3469 /* Decide which of the highlight attributes to use. */
3472 char_attr
= area_attr
;
3473 else if (search_attr
!= 0)
3474 char_attr
= search_attr
;
3476 /* Use line_attr when not in the Visual or 'incsearch' area
3477 * (area_attr may be 0 when "noinvcur" is set). */
3478 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3479 || (vcol
< fromcol
|| vcol
>= tocol
)))
3480 char_attr
= line_attr
;
3487 char_attr
= syntax_attr
;
3495 * Get the next character to put on the screen.
3498 * The 'extra' array contains the extra stuff that is inserted to
3499 * represent special characters (non-printable stuff). When all
3500 * characters are the same, c_extra is used.
3501 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3509 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3510 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3529 /* If the UTF-8 character is more than one byte:
3530 * Decode it into "mb_c". */
3531 mb_l
= (*mb_ptr2len
)(p_extra
);
3537 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3544 /* if this is a DBCS character, put it in "mb_c" */
3545 mb_l
= MB_BYTE2LEN(c
);
3546 if (mb_l
>= n_extra
)
3549 mb_c
= (c
<< 8) + p_extra
[1];
3551 if (mb_l
== 0) /* at the NUL at end-of-line */
3554 /* If a double-width char doesn't fit display a '>' in the
3557 # ifdef FEAT_RIGHTLEFT
3558 wp
->w_p_rl
? (col
<= 0) :
3560 (col
>= W_WIDTH(wp
) - 1))
3561 && (*mb_char2cells
)(mb_c
) == 2)
3567 multi_attr
= hl_attr(HLF_AT
);
3568 /* put the pointer back to output the double-width
3569 * character at the start of the next line. */
3575 n_extra
-= mb_l
- 1;
3576 p_extra
+= mb_l
- 1;
3587 * Get a character from the line itself.
3596 /* If the UTF-8 character is more than one byte: Decode it
3598 mb_l
= (*mb_ptr2len
)(ptr
);
3602 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3603 /* Overlong encoded ASCII or ASCII with composing char
3604 * is displayed normally, except a NUL. */
3609 /* At start of the line we can have a composing char.
3610 * Draw it as a space with a composing char. */
3611 if (utf_iscomposing(mb_c
))
3613 for (i
= Screen_mco
- 1; i
> 0; --i
)
3614 u8cc
[i
] = u8cc
[i
- 1];
3620 if ((mb_l
== 1 && c
>= 0x80)
3621 || (mb_l
>= 1 && mb_c
== 0)
3622 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3623 || mb_c
>= 0x10000)))
3626 * Illegal UTF-8 byte: display as <xx>.
3627 * Non-BMP character : display as ? or fullwidth ?.
3631 transchar_hex(extra
, mb_c
);
3632 # ifdef FEAT_RIGHTLEFT
3633 if (wp
->w_p_rl
) /* reverse */
3637 else if (utf_char2cells(mb_c
) != 2)
3640 /* 0xff1f in UTF-8: full-width '?' */
3641 STRCPY(extra
, "\357\274\237");
3645 mb_c
= mb_ptr2char_adv(&p_extra
);
3646 mb_utf8
= (c
>= 0x80);
3647 n_extra
= (int)STRLEN(p_extra
);
3649 if (area_attr
== 0 && search_attr
== 0)
3651 n_attr
= n_extra
+ 1;
3652 extra_attr
= hl_attr(HLF_8
);
3653 saved_attr2
= char_attr
; /* save current attr */
3656 else if (mb_l
== 0) /* at the NUL at end-of-line */
3659 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3661 /* Do Arabic shaping. */
3665 /* The idea of what is the previous and next
3666 * character depends on 'rightleft'. */
3671 nc
= utf_ptr2char(ptr
+ mb_l
);
3676 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3682 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3690 mb_l
= MB_BYTE2LEN(c
);
3691 if (mb_l
== 0) /* at the NUL at end-of-line */
3695 /* We assume a second byte below 32 is illegal.
3696 * Hopefully this is OK for all double-byte encodings!
3699 mb_c
= (c
<< 8) + ptr
[1];
3704 /* head byte at end of line */
3706 transchar_nonprint(extra
, c
);
3710 /* illegal tail byte */
3712 STRCPY(extra
, "XX");
3715 n_extra
= (int)STRLEN(extra
) - 1;
3718 if (area_attr
== 0 && search_attr
== 0)
3720 n_attr
= n_extra
+ 1;
3721 extra_attr
= hl_attr(HLF_8
);
3722 saved_attr2
= char_attr
; /* save current attr */
3728 /* If a double-width char doesn't fit display a '>' in the
3729 * last column; the character is displayed at the start of the
3732 # ifdef FEAT_RIGHTLEFT
3733 wp
->w_p_rl
? (col
<= 0) :
3735 (col
>= W_WIDTH(wp
) - 1))
3736 && (*mb_char2cells
)(mb_c
) == 2)
3742 multi_attr
= hl_attr(HLF_AT
);
3743 /* Put pointer back so that the character will be
3744 * displayed at the start of the next line. */
3747 else if (*ptr
!= NUL
)
3750 /* If a double-width char doesn't fit at the left side display
3751 * a '<' in the first column. */
3752 if (n_skip
> 0 && mb_l
> 1)
3759 if (area_attr
== 0 && search_attr
== 0)
3761 n_attr
= n_extra
+ 1;
3762 extra_attr
= hl_attr(HLF_AT
);
3763 saved_attr2
= char_attr
; /* save current attr */
3774 /* 'list' : change char 160 to lcs_nbsp. */
3775 if (wp
->w_p_list
&& (c
== 160
3777 || (mb_utf8
&& mb_c
== 160)
3782 if (area_attr
== 0 && search_attr
== 0)
3785 extra_attr
= hl_attr(HLF_8
);
3786 saved_attr2
= char_attr
; /* save current attr */
3790 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3804 int can_spell
= TRUE
;
3808 /* Get syntax attribute, unless still at the start of the line
3809 * (double-wide char that doesn't fit). */
3810 v
= (long)(ptr
- line
);
3811 if (has_syntax
&& v
> 0)
3813 /* Get the syntax attribute for the character. If there
3814 * is an error, disable syntax highlighting. */
3815 save_did_emsg
= did_emsg
;
3818 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3820 has_spell
? &can_spell
:
3826 wp
->w_buffer
->b_syn_error
= TRUE
;
3830 did_emsg
= save_did_emsg
;
3832 /* Need to get the line again, a multi-line regexp may
3833 * have made it invalid. */
3834 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3838 char_attr
= syntax_attr
;
3840 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3845 /* Check spelling (unless at the end of the line).
3846 * Only do this when there is no syntax highlighting, the
3847 * @Spell cluster is not used or the current syntax item
3848 * contains the @Spell cluster. */
3849 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3854 char_attr
= syntax_attr
;
3862 char_u
*prev_ptr
, *p
;
3864 hlf_T spell_hlf
= HLF_COUNT
;
3868 prev_ptr
= ptr
- mb_l
;
3875 /* Use nextline[] if possible, it has the start of the
3876 * next line concatenated. */
3877 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3878 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
3881 cap_col
-= (int)(prev_ptr
- line
);
3882 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
3886 /* In Insert mode only highlight a word that
3887 * doesn't touch the cursor. */
3888 if (spell_hlf
!= HLF_COUNT
3889 && (State
& INSERT
) != 0
3890 && wp
->w_cursor
.lnum
== lnum
3891 && wp
->w_cursor
.col
>=
3892 (colnr_T
)(prev_ptr
- line
)
3893 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
3895 spell_hlf
= HLF_COUNT
;
3896 spell_redraw_lnum
= lnum
;
3899 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
3900 && (p
- nextline
) + len
> nextline_idx
)
3902 /* Remember that the good word continues at the
3903 * start of the next line. */
3904 checked_lnum
= lnum
+ 1;
3905 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
3908 /* Turn index into actual attributes. */
3909 if (spell_hlf
!= HLF_COUNT
)
3910 spell_attr
= highlight_attr
[spell_hlf
];
3915 && (p
- nextline
) + cap_col
>= nextline_idx
)
3917 /* Remember that the word in the next line
3918 * must start with a capital. */
3919 capcol_lnum
= lnum
+ 1;
3920 cap_col
= (int)((p
- nextline
) + cap_col
3924 /* Compute the actual column. */
3925 cap_col
+= (int)(prev_ptr
- line
);
3929 if (spell_attr
!= 0)
3932 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
3934 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
3937 #ifdef FEAT_LINEBREAK
3939 * Found last space before word: check for line break.
3941 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
3944 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
3948 1), (colnr_T
)vcol
, NULL
) - 1;
3955 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
3961 extra_attr
= hl_attr(HLF_8
);
3962 saved_attr2
= char_attr
; /* save current attr */
3966 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3979 * Handling of non-printable characters.
3981 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
3984 * when getting a character from the file, we may have to
3985 * turn it into something else on the way to putting it
3986 * into "ScreenLines".
3988 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
3990 /* tab amount depends on current column */
3991 n_extra
= (int)wp
->w_buffer
->b_p_ts
3992 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
3994 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4000 n_attr
= n_extra
+ 1;
4001 extra_attr
= hl_attr(HLF_8
);
4002 saved_attr2
= char_attr
; /* save current attr */
4005 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4020 && ((wp
->w_p_list
&& lcs_eol
> 0)
4021 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4024 && VIsual_mode
!= Ctrl_V
4027 # ifdef FEAT_RIGHTLEFT
4028 wp
->w_p_rl
? (col
>= 0) :
4030 (col
< W_WIDTH(wp
)))
4032 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4033 && lcs_eol_one
>= 0)
4035 /* Display a '$' after the line or highlight an extra
4036 * character if the line break is included. */
4037 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4038 /* For a diff line the highlighting continues after the
4042 diff_hlf
== (hlf_T
)0
4053 #ifdef FEAT_VIRTUALEDIT
4054 /* In virtualedit, visual selections may extend
4055 * beyond end of line. */
4056 if (area_highlighting
&& virtual_active()
4057 && tocol
!= MAXCOL
&& vcol
< tocol
)
4062 p_extra
= at_end_str
;
4072 --ptr
; /* put it back at the NUL */
4075 extra_attr
= hl_attr(HLF_AT
);
4080 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4087 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4092 p_extra
= transchar(c
);
4093 #ifdef FEAT_RIGHTLEFT
4094 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4095 rl_mirror(p_extra
); /* reverse "<12>" */
4097 n_extra
= byte2cells(c
) - 1;
4102 n_attr
= n_extra
+ 1;
4103 extra_attr
= hl_attr(HLF_8
);
4104 saved_attr2
= char_attr
; /* save current attr */
4107 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4110 #ifdef FEAT_VIRTUALEDIT
4111 else if (VIsual_active
4112 && (VIsual_mode
== Ctrl_V
4113 || VIsual_mode
== 'v')
4118 # ifdef FEAT_RIGHTLEFT
4119 wp
->w_p_rl
? (col
>= 0) :
4121 (col
< W_WIDTH(wp
))))
4124 --ptr
; /* put it back at the NUL */
4127 #if defined(LINE_ATTR)
4130 diff_hlf
!= (hlf_T
)0 ||
4134 # ifdef FEAT_RIGHTLEFT
4135 wp
->w_p_rl
? (col
>= 0) :
4137 (col
< W_WIDTH(wp
))))
4139 /* Highlight until the right side of the window */
4141 --ptr
; /* put it back at the NUL */
4143 /* Remember we do the char for line highlighting. */
4146 /* don't do search HL for the rest of the line */
4147 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4148 char_attr
= line_attr
;
4150 if (diff_hlf
== HLF_TXD
)
4153 if (attr
== 0 || char_attr
!= attr
)
4154 char_attr
= hl_attr(diff_hlf
);
4162 /* Don't override visual selection highlighting. */
4164 && draw_state
== WL_LINE
4166 char_attr
= extra_attr
;
4168 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4169 /* XIM don't send preedit_start and preedit_end, but they send
4170 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4171 * im_is_preediting() here. */
4173 && lnum
== curwin
->w_cursor
.lnum
4176 && im_is_preediting()
4177 && draw_state
== WL_LINE
)
4181 if (preedit_end_col
== MAXCOL
)
4182 getvcol(curwin
, &(curwin
->w_cursor
), &tcol
, NULL
, NULL
);
4184 tcol
= preedit_end_col
;
4185 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4187 if (feedback_old_attr
< 0)
4190 feedback_old_attr
= char_attr
;
4192 char_attr
= im_get_feedback_attr(feedback_col
);
4194 char_attr
= feedback_old_attr
;
4197 else if (feedback_old_attr
>= 0)
4199 char_attr
= feedback_old_attr
;
4200 feedback_old_attr
= -1;
4206 * Handle the case where we are in column 0 but not on the first
4207 * character of the line and the user wants us to show us a
4208 * special character (via 'listchars' option "precedes:<char>".
4210 if (lcs_prec_todo
!= NUL
4211 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4215 && draw_state
> WL_NR
4219 lcs_prec_todo
= NUL
;
4222 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4229 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4233 saved_attr3
= char_attr
; /* save current attr */
4234 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4240 * At end of the text line or just after the last character.
4243 #if defined(LINE_ATTR)
4244 || did_line_attr
== 1
4248 #ifdef FEAT_SEARCH_EXTRA
4249 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4252 /* invert at least one char, used for Visual and empty line or
4253 * highlight match at end of line. If it's beyond the last
4254 * char on the screen, just overwrite that one (tricky!) Not
4255 * needed when a '$' was displayed for 'list'. */
4256 if (lcs_eol
== lcs_eol_one
4257 && ((area_attr
!= 0 && vcol
== fromcol
&& c
== NUL
)
4258 #ifdef FEAT_SEARCH_EXTRA
4259 /* highlight 'hlsearch' match at end of line */
4260 || ((prevcol
== (long)search_hl
.startcol
4261 || prevcol
== (long)match_hl
[0].startcol
4262 || prevcol
== (long)match_hl
[1].startcol
4263 || prevcol
== (long)match_hl
[2].startcol
)
4264 # if defined(LINE_ATTR)
4265 && did_line_attr
<= 1
4273 #ifdef FEAT_RIGHTLEFT
4282 if (col
>= W_WIDTH(wp
))
4287 /* At the window boundary, highlight the last character
4288 * instead (better than nothing). */
4294 /* Add a blank character to highlight. */
4295 ScreenLines
[off
] = ' ';
4298 ScreenLinesUC
[off
] = 0;
4301 #ifdef FEAT_SEARCH_EXTRA
4304 for (i
= 0; i
<= 3; ++i
)
4307 char_attr
= search_hl
.attr
;
4308 else if ((ptr
- line
) - 1 == (long)match_hl
[i
].startcol
)
4310 char_attr
= match_hl
[i
].attr
;
4316 ScreenAttrs
[off
] = char_attr
;
4317 #ifdef FEAT_RIGHTLEFT
4328 * At end of the text line.
4333 /* Highlight 'cursorcolumn' past end of the line. */
4338 /* check if line ends before left margin */
4339 if (vcol
< v
+ col
- win_col_off(wp
))
4341 vcol
= v
+ col
- win_col_off(wp
);
4343 && (int)wp
->w_virtcol
>= vcol
4344 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4346 && lnum
!= wp
->w_cursor
.lnum
4347 # ifdef FEAT_RIGHTLEFT
4352 while (col
< W_WIDTH(wp
))
4354 ScreenLines
[off
] = ' ';
4357 ScreenLinesUC
[off
] = 0;
4360 if (vcol
== (long)wp
->w_virtcol
)
4362 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4365 ScreenAttrs
[off
++] = 0;
4371 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4376 * Update w_cline_height and w_cline_folded if the cursor line was
4377 * updated (saves a call to plines() later).
4379 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4381 curwin
->w_cline_row
= startrow
;
4382 curwin
->w_cline_height
= row
- startrow
;
4384 curwin
->w_cline_folded
= FALSE
;
4386 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4392 /* line continues beyond line end */
4399 #ifdef FEAT_RIGHTLEFT
4400 wp
->w_p_rl
? col
== 0 :
4402 col
== W_WIDTH(wp
) - 1)
4404 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4405 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4408 char_attr
= hl_attr(HLF_AT
);
4411 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4423 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4424 * highlight the cursor position itself. */
4425 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4426 && lnum
!= wp
->w_cursor
.lnum
4427 && draw_state
== WL_LINE
)
4429 vcol_save_attr
= char_attr
;
4430 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4433 vcol_save_attr
= -1;
4437 * Store character to be displayed.
4438 * Skip characters that are left of the screen for 'nowrap'.
4441 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4444 * Store the character.
4446 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4447 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4449 /* A double-wide character is: put first halve in left cell. */
4454 ScreenLines
[off
] = c
;
4456 if (enc_dbcs
== DBCS_JPNU
)
4457 ScreenLines2
[off
] = mb_c
& 0xff;
4462 ScreenLinesUC
[off
] = mb_c
;
4463 if ((c
& 0xff) == 0)
4464 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4465 for (i
= 0; i
< Screen_mco
; ++i
)
4467 ScreenLinesC
[i
][off
] = u8cc
[i
];
4473 ScreenLinesUC
[off
] = 0;
4477 ScreenAttrs
[off
] = multi_attr
;
4482 ScreenAttrs
[off
] = char_attr
;
4485 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4487 /* Need to fill two screen columns. */
4491 /* UTF-8: Put a 0 in the second screen char. */
4492 ScreenLines
[off
] = 0;
4494 /* DBCS: Put second byte in the second screen char. */
4495 ScreenLines
[off
] = mb_c
& 0xff;
4497 /* When "tocol" is halfway a character, set it to the end of
4498 * the character, otherwise highlighting won't stop. */
4501 #ifdef FEAT_RIGHTLEFT
4504 /* now it's time to backup one cell */
4511 #ifdef FEAT_RIGHTLEFT
4527 /* Only advance the "vcol" when after the 'number' column. */
4528 if (draw_state
>= WL_SBR
4536 if (vcol_save_attr
>= 0)
4537 char_attr
= vcol_save_attr
;
4540 /* restore attributes after "predeces" in 'listchars' */
4541 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4542 char_attr
= saved_attr3
;
4544 /* restore attributes after last 'listchars' or 'number' char */
4545 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4546 char_attr
= saved_attr2
;
4549 * At end of screen line and there is more to come: Display the line
4550 * so far. If there is no more to display it is catched above.
4553 #ifdef FEAT_RIGHTLEFT
4554 wp
->w_p_rl
? (col
< 0) :
4556 (col
>= W_WIDTH(wp
)))
4561 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4562 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4565 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4570 /* When not wrapping and finished diff lines, or when displayed
4571 * '$' and highlighting until last column, break here. */
4576 ) || lcs_eol_one
== -1)
4579 /* When the window is too narrow draw all "@" lines. */
4580 if (draw_state
!= WL_LINE
4586 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4587 #ifdef FEAT_VERTSPLIT
4588 draw_vsep_win(wp
, row
);
4593 /* When line got too long for screen break here. */
4600 if (screen_cur_row
== screen_row
- 1
4604 && W_WIDTH(wp
) == Columns
)
4606 /* Remember that the line wraps, used for modeless copy. */
4607 LineWraps
[screen_row
- 1] = TRUE
;
4610 * Special trick to make copy/paste of wrapped lines work with
4611 * xterm/screen: write an extra character beyond the end of
4612 * the line. This will work with all terminal types
4613 * (regardless of the xn,am settings).
4614 * Only do this on a fast tty.
4615 * Only do this if the cursor is on the current line
4616 * (something has been written in it).
4617 * Don't do this for the GUI.
4618 * Don't do this for double-width characters.
4619 * Don't do this for a window not at the right screen border.
4627 && ((*mb_off2cells
)(LineOffset
[screen_row
]) == 2
4628 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4629 + (int)Columns
- 2) == 2))
4633 /* First make sure we are at the end of the screen line,
4634 * then output the same character again to let the
4635 * terminal know about the wrap. If the terminal doesn't
4636 * auto-wrap, we overwrite the character. */
4637 if (screen_cur_col
!= W_WIDTH(wp
))
4638 screen_char(LineOffset
[screen_row
- 1]
4639 + (unsigned)Columns
- 1,
4640 screen_row
- 1, (int)(Columns
- 1));
4643 /* When there is a multi-byte character, just output a
4644 * space to keep it simple. */
4645 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4646 screen_row
- 1] + (Columns
- 1)]) > 1)
4650 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4652 /* force a redraw of the first char on the next line */
4653 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4654 screen_start(); /* don't know where cursor is now */
4659 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4660 #ifdef FEAT_RIGHTLEFT
4663 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4668 /* reset the drawing state for the start of a wrapped line */
4669 draw_state
= WL_START
;
4670 saved_n_extra
= n_extra
;
4671 saved_p_extra
= p_extra
;
4672 saved_c_extra
= c_extra
;
4673 saved_char_attr
= char_attr
;
4675 lcs_prec_todo
= lcs_prec
;
4676 #ifdef FEAT_LINEBREAK
4678 if (filler_todo
<= 0)
4680 need_showbreak
= TRUE
;
4684 /* When the filler lines are actually below the last line of the
4685 * file, don't draw the line itself, break here. */
4686 if (filler_todo
== 0 && wp
->w_botfill
)
4691 } /* for every character in the line */
4694 /* After an empty line check first word for capital. */
4695 if (*skipwhite(line
) == NUL
)
4697 capcol_lnum
= lnum
+ 1;
4706 static int comp_char_differs
__ARGS((int, int));
4709 * Return if the composing characters at "off_from" and "off_to" differ.
4712 comp_char_differs(off_from
, off_to
)
4718 for (i
= 0; i
< Screen_mco
; ++i
)
4720 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4722 if (ScreenLinesC
[i
][off_from
] == 0)
4730 * Check whether the given character needs redrawing:
4731 * - the (first byte of the) character is different
4732 * - the attributes are different
4733 * - the character is multi-byte and the next byte is different
4736 char_needs_redraw(off_from
, off_to
, cols
)
4742 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4743 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4747 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4748 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4749 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4750 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4751 != ScreenLines
[off_to
+ 1])))
4753 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4754 || (ScreenLinesUC
[off_from
] != 0
4755 && comp_char_differs(off_from
, off_to
))))
4763 * Move one "cooked" screen line to the screen, but only the characters that
4764 * have actually changed. Handle insert/delete character.
4765 * "coloff" gives the first column on the screen for this line.
4766 * "endcol" gives the columns where valid characters are.
4767 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4768 * needs to be cleared, negative otherwise.
4769 * "rlflag" is TRUE in a rightleft window:
4770 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4771 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4774 screen_line(row
, coloff
, endcol
, clear_width
4775 #ifdef FEAT_RIGHTLEFT
4783 #ifdef FEAT_RIGHTLEFT
4790 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4793 int force
= FALSE
; /* force update rest of the line */
4794 int redraw_this
/* bool: does character need redraw? */
4796 = TRUE
/* For GUI when while-loop empty */
4799 int redraw_next
; /* redraw_this for next character */
4801 int clear_next
= FALSE
;
4802 int char_cells
; /* 1: normal char */
4803 /* 2: occupies two display cells */
4804 # define CHAR_CELLS char_cells
4806 # define CHAR_CELLS 1
4809 # ifdef FEAT_CLIPBOARD
4810 clip_may_clear_selection(row
, row
);
4813 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
4814 off_to
= LineOffset
[row
] + coloff
;
4816 #ifdef FEAT_RIGHTLEFT
4819 /* Clear rest first, because it's left of the text. */
4820 if (clear_width
> 0)
4822 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
4823 && ScreenAttrs
[off_to
] == 0
4825 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
4833 screen_fill(row
, row
+ 1, col
+ coloff
,
4834 endcol
+ coloff
+ 1, ' ', ' ', 0);
4837 off_to
= LineOffset
[row
] + col
+ coloff
;
4839 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
4841 #endif /* FEAT_RIGHTLEFT */
4843 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
4845 while (col
< endcol
)
4848 if (has_mbyte
&& (col
+ 1 < endcol
))
4849 char_cells
= (*mb_off2cells
)(off_from
);
4854 redraw_this
= redraw_next
;
4855 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
4856 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
4859 /* If the next character was bold, then redraw the current character to
4860 * remove any pixels that might have spilt over into us. This only
4861 * happens in the GUI.
4863 if (redraw_next
&& gui
.in_use
)
4865 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
4867 hl
= syn_attr2attr(hl
);
4876 * Special handling when 'xs' termcap flag set (hpterm):
4877 * Attributes for characters are stored at the position where the
4878 * cursor is when writing the highlighting code. The
4879 * start-highlighting code must be written with the cursor on the
4880 * first highlighted character. The stop-highlighting code must
4881 * be written with the cursor just after the last highlighted
4883 * Overwriting a character doesn't remove it's highlighting. Need
4884 * to clear the rest of the line, and force redrawing it
4892 && ScreenAttrs
[off_to
] != 0
4893 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4896 * Need to remove highlighting attributes here.
4898 windgoto(row
, col
+ coloff
);
4899 out_str(T_CE
); /* clear rest of this screen line */
4900 screen_start(); /* don't know where cursor is now */
4901 force
= TRUE
; /* force redraw of rest of the line */
4902 redraw_next
= TRUE
; /* or else next char would miss out */
4905 * If the previous character was highlighted, need to stop
4906 * highlighting at this character.
4908 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
4910 screen_attr
= ScreenAttrs
[off_to
- 1];
4911 term_windgoto(row
, col
+ coloff
);
4912 screen_stop_highlight();
4915 screen_attr
= 0; /* highlighting has stopped */
4920 /* Check if overwriting a double-byte with a single-byte or
4921 * the other way around requires another character to be
4922 * redrawn. For UTF-8 this isn't needed, because comparing
4923 * ScreenLinesUC[] is sufficient. */
4926 && (*mb_off2cells
)(off_to
) > 1)
4928 /* Writing a single-cell character over a double-cell
4929 * character: need to redraw the next cell. */
4930 ScreenLines
[off_to
+ 1] = 0;
4933 else if (char_cells
== 2
4935 && (*mb_off2cells
)(off_to
) == 1
4936 && (*mb_off2cells
)(off_to
+ 1) > 1)
4938 /* Writing the second half of a double-cell character over
4939 * a double-cell character: need to redraw the second
4941 ScreenLines
[off_to
+ 2] = 0;
4945 if (enc_dbcs
== DBCS_JPNU
)
4946 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
4948 /* When writing a single-width character over a double-width
4949 * character and at the end of the redrawn text, need to clear out
4950 * the right halve of the old character.
4951 * Also required when writing the right halve of a double-width
4952 * char over the left halve of an existing one. */
4953 if (has_mbyte
&& col
+ char_cells
== endcol
4954 && ((char_cells
== 1
4955 && (*mb_off2cells
)(off_to
) > 1)
4957 && (*mb_off2cells
)(off_to
) == 1
4958 && (*mb_off2cells
)(off_to
+ 1) > 1)))
4962 ScreenLines
[off_to
] = ScreenLines
[off_from
];
4966 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
4967 if (ScreenLinesUC
[off_from
] != 0)
4971 for (i
= 0; i
< Screen_mco
; ++i
)
4972 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
4975 if (char_cells
== 2)
4976 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
4979 #if defined(FEAT_GUI) || defined(UNIX)
4980 /* The bold trick makes a single row of pixels appear in the next
4981 * character. When a bold character is removed, the next
4982 * character should be redrawn too. This happens for our own GUI
4983 * and for some xterms. */
4988 # if defined(FEAT_GUI) && defined(UNIX)
4996 hl
= ScreenAttrs
[off_to
];
4998 hl
= syn_attr2attr(hl
);
5003 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5005 /* For simplicity set the attributes of second half of a
5006 * double-wide character equal to the first half. */
5007 if (char_cells
== 2)
5008 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5010 if (enc_dbcs
!= 0 && char_cells
== 2)
5011 screen_char_2(off_to
, row
, col
+ coloff
);
5014 screen_char(off_to
, row
, col
+ coloff
);
5020 && col
+ coloff
> 0)
5022 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5025 * Don't output stop-highlight when moving the cursor, it will
5026 * stop the highlighting when it should continue.
5030 else if (screen_attr
!= 0)
5031 screen_stop_highlight();
5034 off_to
+= CHAR_CELLS
;
5035 off_from
+= CHAR_CELLS
;
5042 /* Clear the second half of a double-wide character of which the left
5043 * half was overwritten with a single-wide character. */
5044 ScreenLines
[off_to
] = ' ';
5046 ScreenLinesUC
[off_to
] = 0;
5047 screen_char(off_to
, row
, col
+ coloff
);
5052 #ifdef FEAT_RIGHTLEFT
5061 /* blank out the rest of the line */
5062 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5063 && ScreenAttrs
[off_to
] == 0
5065 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5072 if (col
< clear_width
)
5076 * In the GUI, clearing the rest of the line may leave pixels
5077 * behind if the first character cleared was bold. Some bold
5078 * fonts spill over the left. In this case we redraw the previous
5079 * character too. If we didn't skip any blanks above, then we
5080 * only redraw if the character wasn't already redrawn anyway.
5082 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5084 hl
= ScreenAttrs
[off_to
];
5085 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5090 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5091 * that its width is 2. */
5092 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5093 else if (enc_dbcs
!= 0)
5095 /* find previous character by counting from first
5096 * column and get its width. */
5097 unsigned off
= LineOffset
[row
];
5099 while (off
< off_to
)
5101 prev_cells
= (*mb_off2cells
)(off
);
5106 if (enc_dbcs
!= 0 && prev_cells
> 1)
5107 screen_char_2(off_to
- prev_cells
, row
,
5108 col
+ coloff
- prev_cells
);
5111 screen_char(off_to
- prev_cells
, row
,
5112 col
+ coloff
- prev_cells
);
5116 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5118 #ifdef FEAT_VERTSPLIT
5119 off_to
+= clear_width
- col
;
5125 if (clear_width
> 0)
5127 #ifdef FEAT_VERTSPLIT
5128 /* For a window that's left of another, draw the separator char. */
5129 if (col
+ coloff
< Columns
)
5133 c
= fillchar_vsep(&hl
);
5134 if (ScreenLines
[off_to
] != c
5136 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5137 != (c
>= 0x80 ? c
: 0))
5139 || ScreenAttrs
[off_to
] != hl
)
5141 ScreenLines
[off_to
] = c
;
5142 ScreenAttrs
[off_to
] = hl
;
5148 ScreenLinesUC
[off_to
] = c
;
5149 ScreenLinesC
[0][off_to
] = 0;
5152 ScreenLinesUC
[off_to
] = 0;
5155 screen_char(off_to
, row
, col
+ coloff
);
5160 LineWraps
[row
] = FALSE
;
5164 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5166 * Mirror text "str" for right-left displaying.
5167 * Only works for single-byte characters (e.g., numbers).
5176 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5185 #if defined(FEAT_WINDOWS) || defined(PROTO)
5187 * mark all status lines for redraw; used after first :cd
5194 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5195 if (wp
->w_status_height
)
5197 wp
->w_redr_status
= TRUE
;
5198 redraw_later(VALID
);
5203 * mark all status lines of the current buffer for redraw
5206 status_redraw_curbuf()
5210 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5211 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5213 wp
->w_redr_status
= TRUE
;
5214 redraw_later(VALID
);
5219 * Redraw all status lines that need to be redrawn.
5222 redraw_statuslines()
5226 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5227 if (wp
->w_redr_status
)
5228 win_redr_status(wp
);
5234 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5236 * Redraw all status lines at the bottom of frame "frp".
5239 win_redraw_last_status(frp
)
5242 if (frp
->fr_layout
== FR_LEAF
)
5243 frp
->fr_win
->w_redr_status
= TRUE
;
5244 else if (frp
->fr_layout
== FR_ROW
)
5246 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5247 win_redraw_last_status(frp
);
5249 else /* frp->fr_layout == FR_COL */
5251 frp
= frp
->fr_child
;
5252 while (frp
->fr_next
!= NULL
)
5254 win_redraw_last_status(frp
);
5259 #ifdef FEAT_VERTSPLIT
5261 * Draw the verticap separator right of window "wp" starting with line "row".
5264 draw_vsep_win(wp
, row
)
5271 if (wp
->w_vsep_width
)
5273 /* draw the vertical separator right of this window */
5274 c
= fillchar_vsep(&hl
);
5275 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5276 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5282 #ifdef FEAT_WILDMENU
5283 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5284 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5287 * Get the lenght of an item as it will be shown in the status line.
5290 status_match_len(xp
, s
)
5297 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5298 || xp
->xp_context
== EXPAND_MENUNAMES
);
5300 /* Check for menu separators - replace with '|'. */
5301 if (emenu
&& menu_is_separator(s
))
5307 if (skip_status_match_char(xp
, s
))
5309 len
+= ptr2cells(s
);
5317 * Return TRUE for characters that are not displayed in a status match.
5318 * These are backslashes used for escaping. Do show backslashes in help tags.
5321 skip_status_match_char(xp
, s
)
5325 return ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5327 || ((xp
->xp_context
== EXPAND_MENUS
5328 || xp
->xp_context
== EXPAND_MENUNAMES
)
5329 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5335 * Show wildchar matches in the status line.
5336 * Show at least the "match" item.
5337 * We start at item 'first_match' in the list and show all matches that fit.
5339 * If inversion is possible we use it. Else '=' characters are used.
5342 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5345 char_u
**matches
; /* list of matches */
5349 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5353 int clen
; /* lenght in screen cells */
5357 int highlight
= TRUE
;
5358 char_u
*selstart
= NULL
;
5359 int selstart_col
= 0;
5360 char_u
*selend
= NULL
;
5361 static int first_match
= 0;
5362 int add_left
= FALSE
;
5367 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5371 if (matches
== NULL
) /* interrupted completion? */
5376 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5379 buf
= alloc((unsigned)Columns
+ 1);
5383 if (match
== -1) /* don't show match but original text */
5388 /* count 1 for the ending ">" */
5389 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5392 else if (match
< first_match
)
5394 /* jumping left, as far as we can go */
5395 first_match
= match
;
5400 /* check if match fits on the screen */
5401 for (i
= first_match
; i
< match
; ++i
)
5402 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5403 if (first_match
> 0)
5405 /* jumping right, put match at the left */
5406 if ((long)clen
> Columns
)
5408 first_match
= match
;
5409 /* if showing the last match, we can add some on the left */
5411 for (i
= match
; i
< num_matches
; ++i
)
5413 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5414 if ((long)clen
>= Columns
)
5417 if (i
== num_matches
)
5422 while (first_match
> 0)
5424 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5425 if ((long)clen
>= Columns
)
5430 fillchar
= fillchar_status(&attr
, TRUE
);
5432 if (first_match
== 0)
5445 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5449 selstart
= buf
+ len
;
5450 selstart_col
= clen
;
5454 /* Check for menu separators - replace with '|' */
5456 emenu
= (xp
->xp_context
== EXPAND_MENUS
5457 || xp
->xp_context
== EXPAND_MENUNAMES
);
5458 if (emenu
&& menu_is_separator(s
))
5460 STRCPY(buf
+ len
, transchar('|'));
5461 l
= (int)STRLEN(buf
+ len
);
5467 for ( ; *s
!= NUL
; ++s
)
5469 if (skip_status_match_char(xp
, s
))
5471 clen
+= ptr2cells(s
);
5473 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5475 STRNCPY(buf
+ len
, s
, l
);
5482 STRCPY(buf
+ len
, transchar_byte(*s
));
5483 len
+= (int)STRLEN(buf
+ len
);
5489 *(buf
+ len
++) = ' ';
5490 *(buf
+ len
++) = ' ';
5492 if (++i
== num_matches
)
5496 if (i
!= num_matches
)
5498 *(buf
+ len
++) = '>';
5504 row
= cmdline_row
- 1;
5507 if (wild_menu_showing
== 0)
5509 if (msg_scrolled
> 0)
5511 /* Put the wildmenu just above the command line. If there is
5512 * no room, scroll the screen one line up. */
5513 if (cmdline_row
== Rows
- 1)
5515 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5523 wild_menu_showing
= WM_SCROLLED
;
5527 /* Create status line if needed by setting 'laststatus' to 2.
5528 * Set 'winminheight' to zero to avoid that the window is
5530 if (lastwin
->w_status_height
== 0)
5538 wild_menu_showing
= WM_SHOWN
;
5542 screen_puts(buf
, row
, 0, attr
);
5543 if (selstart
!= NULL
&& highlight
)
5546 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5549 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5552 #ifdef FEAT_VERTSPLIT
5553 win_redraw_last_status(topframe
);
5555 lastwin
->w_redr_status
= TRUE
;
5561 #if defined(FEAT_WINDOWS) || defined(PROTO)
5563 * Redraw the status line of window wp.
5565 * If inversion is possible we use it. Else '=' characters are used.
5578 wp
->w_redr_status
= FALSE
;
5579 if (wp
->w_status_height
== 0)
5581 /* no status line, can only be last window */
5582 redraw_cmdline
= TRUE
;
5584 else if (!redrawing()
5585 #ifdef FEAT_INS_EXPAND
5586 /* don't update status line when popup menu is visible and may be
5592 /* Don't redraw right now, do it later. */
5593 wp
->w_redr_status
= TRUE
;
5596 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5598 /* redraw custom status line */
5599 redraw_custum_statusline(wp
);
5604 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5606 get_trans_bufname(wp
->w_buffer
);
5608 len
= (int)STRLEN(p
);
5610 if (wp
->w_buffer
->b_help
5611 #ifdef FEAT_QUICKFIX
5614 || bufIsChanged(wp
->w_buffer
)
5615 || wp
->w_buffer
->b_p_ro
)
5617 if (wp
->w_buffer
->b_help
)
5619 STRCPY(p
+ len
, _("[Help]"));
5620 len
+= (int)STRLEN(p
+ len
);
5622 #ifdef FEAT_QUICKFIX
5625 STRCPY(p
+ len
, _("[Preview]"));
5626 len
+= (int)STRLEN(p
+ len
);
5629 if (bufIsChanged(wp
->w_buffer
))
5631 STRCPY(p
+ len
, "[+]");
5634 if (wp
->w_buffer
->b_p_ro
)
5636 STRCPY(p
+ len
, "[RO]");
5640 #ifndef FEAT_VERTSPLIT
5641 this_ru_col
= ru_col
;
5642 if (this_ru_col
< (Columns
+ 1) / 2)
5643 this_ru_col
= (Columns
+ 1) / 2;
5645 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5646 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5647 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5648 if (this_ru_col
<= 1)
5650 p
= (char_u
*)"<"; /* No room for file name! */
5660 /* Count total number of display cells. */
5661 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5662 clen
+= (*mb_ptr2cells
)(p
+ i
);
5663 /* Find first character that will fit.
5664 * Going from start to end is much faster for DBCS. */
5665 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5666 i
+= (*mb_ptr2len
)(p
+ i
))
5667 clen
-= (*mb_ptr2cells
)(p
+ i
);
5679 if (len
> this_ru_col
- 1)
5681 p
+= len
- (this_ru_col
- 1);
5683 len
= this_ru_col
- 1;
5686 row
= W_WINROW(wp
) + wp
->w_height
;
5687 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5688 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5689 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5691 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5692 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5693 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5694 - 1 + W_WINCOL(wp
)), attr
);
5696 #ifdef FEAT_CMDL_INFO
5697 win_redr_ruler(wp
, TRUE
);
5701 #ifdef FEAT_VERTSPLIT
5703 * May need to draw the character below the vertical separator.
5705 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5707 if (stl_connected(wp
))
5708 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5710 fillchar
= fillchar_vsep(&attr
);
5711 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5719 * Redraw the status line according to 'statusline' and take care of any
5720 * errors encountered.
5723 redraw_custum_statusline(wp
)
5726 int save_called_emsg
= called_emsg
;
5728 called_emsg
= FALSE
;
5729 win_redr_custom(wp
, FALSE
);
5731 set_string_option_direct((char_u
*)"statusline", -1,
5732 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5733 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5734 called_emsg
|= save_called_emsg
;
5738 # ifdef FEAT_VERTSPLIT
5740 * Return TRUE if the status line of window "wp" is connected to the status
5741 * line of the window right of it. If not, then it's a vertical separator.
5742 * Only call if (wp->w_vsep_width != 0).
5751 while (fr
->fr_parent
!= NULL
)
5753 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5755 if (fr
->fr_next
!= NULL
)
5760 if (fr
->fr_next
!= NULL
)
5769 #endif /* FEAT_WINDOWS */
5771 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
5773 * Get the value to show for the language mappings, active 'keymap'.
5776 get_keymap_str(wp
, buf
, len
)
5778 char_u
*buf
; /* buffer for the result */
5779 int len
; /* length of buffer */
5783 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
5788 buf_T
*old_curbuf
= curbuf
;
5789 win_T
*old_curwin
= curwin
;
5792 curbuf
= wp
->w_buffer
;
5794 STRCPY(buf
, "b:keymap_name"); /* must be writable */
5796 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
5798 curbuf
= old_curbuf
;
5799 curwin
= old_curwin
;
5800 if (p
== NULL
|| *p
== NUL
)
5804 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
5805 p
= wp
->w_buffer
->b_p_keymap
;
5808 p
= (char_u
*)"lang";
5810 if ((int)(STRLEN(p
) + 3) < len
)
5811 sprintf((char *)buf
, "<%s>", p
);
5818 return buf
[0] != NUL
;
5822 #if defined(FEAT_STL_OPT) || defined(PROTO)
5824 * Redraw the status line or ruler of window "wp".
5825 * When "wp" is NULL redraw the tab pages line from 'tabline'.
5828 win_redr_custom(wp
, draw_ruler
)
5830 int draw_ruler
; /* TRUE or FALSE */
5841 char_u buf
[MAXPATHL
];
5843 struct stl_hlrec hltab
[STL_MAX_ITEM
];
5844 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
5845 int use_sandbox
= FALSE
;
5847 /* setup environment for the task at hand */
5850 /* Use 'tabline'. Always at the first line of the screen. */
5854 attr
= hl_attr(HLF_TPF
);
5857 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
5862 row
= W_WINROW(wp
) + wp
->w_height
;
5863 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5864 maxwidth
= W_WIDTH(wp
);
5869 /* advance past any leading group spec - implicit in ru_col */
5874 if (atoi((char *) p
))
5875 while (VIM_ISDIGIT(*p
))
5880 #ifdef FEAT_VERTSPLIT
5881 col
= ru_col
- (Columns
- W_WIDTH(wp
));
5882 if (col
< (W_WIDTH(wp
) + 1) / 2)
5883 col
= (W_WIDTH(wp
) + 1) / 2;
5886 if (col
> (Columns
+ 1) / 2)
5887 col
= (Columns
+ 1) / 2;
5889 maxwidth
= W_WIDTH(wp
) - col
;
5891 if (!wp
->w_status_height
)
5895 --maxwidth
; /* writing in last column may cause scrolling */
5901 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
5906 if (*wp
->w_p_stl
!= NUL
)
5911 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
5912 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
5916 #ifdef FEAT_VERTSPLIT
5917 col
+= W_WINCOL(wp
);
5924 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
5927 fillchar
, maxwidth
, hltab
, tabtab
);
5928 len
= (int)STRLEN(buf
);
5930 while (width
< maxwidth
&& len
< sizeof(buf
) - 1)
5933 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
5935 buf
[len
++] = fillchar
;
5942 * Draw each snippet with the specified highlighting.
5946 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
5948 len
= (int)(hltab
[n
].start
- p
);
5949 screen_puts_len(p
, len
, row
, col
, curattr
);
5950 col
+= vim_strnsize(p
, len
);
5953 if (hltab
[n
].userhl
== 0)
5955 else if (hltab
[n
].userhl
< 0)
5956 curattr
= syn_id2attr(-hltab
[n
].userhl
);
5958 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
5959 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
5962 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
5964 screen_puts(p
, row
, col
, curattr
);
5968 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
5973 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
5975 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
5977 TabPageIdxs
[col
++] = fillchar
;
5978 p
= tabtab
[n
].start
;
5979 fillchar
= tabtab
[n
].userhl
;
5981 while (col
< Columns
)
5982 TabPageIdxs
[col
++] = fillchar
;
5986 #endif /* FEAT_STL_OPT */
5989 * Output a single character directly to the screen and update ScreenLines.
5992 screen_putchar(c
, row
, col
, attr
)
5998 char_u buf
[MB_MAXBYTES
+ 1];
6000 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6007 screen_puts(buf
, row
, col
, attr
);
6011 * Get a single character directly from ScreenLines into "bytes[]".
6012 * Also return its attribute in *attrp;
6015 screen_getbytes(row
, col
, bytes
, attrp
)
6023 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6025 off
= LineOffset
[row
] + col
;
6026 *attrp
= ScreenAttrs
[off
];
6027 bytes
[0] = ScreenLines
[off
];
6031 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6032 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6033 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6035 bytes
[0] = ScreenLines
[off
];
6036 bytes
[1] = ScreenLines2
[off
];
6039 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6041 bytes
[1] = ScreenLines
[off
+ 1];
6049 static int screen_comp_differs
__ARGS((int, int*));
6052 * Return TRUE if composing characters for screen posn "off" differs from
6053 * composing characters in "u8cc".
6056 screen_comp_differs(off
, u8cc
)
6062 for (i
= 0; i
< Screen_mco
; ++i
)
6064 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6074 * Put string '*text' on the screen at position 'row' and 'col', with
6075 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6076 * Note: only outputs within one row, message is truncated at screen boundary!
6077 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6080 screen_puts(text
, row
, col
, attr
)
6086 screen_puts_len(text
, -1, row
, col
, attr
);
6090 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6094 screen_puts_len(text
, len
, row
, col
, attr
)
6106 int mbyte_cells
= 1;
6109 int clear_next_cell
= FALSE
;
6111 int prev_c
= 0; /* previous Arabic character */
6117 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6120 off
= LineOffset
[row
] + col
;
6121 while (*ptr
!= NUL
&& col
< screen_Columns
6122 && (len
< 0 || (int)(ptr
- text
) < len
))
6126 /* check if this is the first byte of a multibyte */
6129 if (enc_utf8
&& len
> 0)
6130 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6132 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6133 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6135 else if (enc_dbcs
!= 0)
6136 mbyte_cells
= mbyte_blen
;
6140 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6141 (int)((text
+ len
) - ptr
));
6143 u8c
= utfc_ptr2char(ptr
, u8cc
);
6144 mbyte_cells
= utf_char2cells(u8c
);
6145 /* Non-BMP character: display as ? or fullwidth ?. */
6148 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6150 attr
= hl_attr(HLF_8
);
6153 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6155 /* Do Arabic shaping. */
6156 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6158 /* Past end of string to be displayed. */
6164 nc
= utfc_ptr2char(ptr
+ mbyte_blen
, pcc
);
6169 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6178 if (ScreenLines
[off
] != c
6180 || (mbyte_cells
== 2
6181 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6182 || (enc_dbcs
== DBCS_JPNU
6184 && ScreenLines2
[off
] != ptr
[1])
6186 && (ScreenLinesUC
[off
] != (u8char_T
)u8c
6187 || screen_comp_differs(off
, u8cc
)))
6189 || ScreenAttrs
[off
] != attr
6193 #if defined(FEAT_GUI) || defined(UNIX)
6194 /* The bold trick makes a single row of pixels appear in the next
6195 * character. When a bold character is removed, the next
6196 * character should be redrawn too. This happens for our own GUI
6197 * and for some xterms.
6198 * Force the redraw by setting the attribute to a different value
6199 * than "attr", the contents of ScreenLines[] may be needed by
6200 * mb_off2cells() further on.
6201 * Don't do this for the last drawn character, because the next
6202 * character may not be redrawn. */
6207 # if defined(FEAT_GUI) && defined(UNIX)
6217 n
= ScreenAttrs
[off
];
6219 if (col
+ mbyte_cells
< screen_Columns
6220 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6221 && (len
< 0 ? ptr
[mbyte_blen
] != NUL
6222 : ptr
+ mbyte_blen
< text
+ len
))
6223 ScreenAttrs
[off
+ mbyte_cells
] = attr
+ 1;
6225 if (col
+ 1 < screen_Columns
6226 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6227 && (len
< 0 ? ptr
[1] != NUL
: ptr
+ 1 < text
+ len
))
6228 ScreenLines
[off
+ 1] = 0;
6233 /* When at the end of the text and overwriting a two-cell
6234 * character with a one-cell character, need to clear the next
6235 * cell. Also when overwriting the left halve of a two-cell char
6236 * with the right halve of a two-cell char. Do this only once
6237 * (mb_off2cells() may return 2 on the right halve). */
6238 if (clear_next_cell
)
6239 clear_next_cell
= FALSE
;
6241 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6242 : ptr
+ mbyte_blen
>= text
+ len
)
6243 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
) > 1)
6244 || (mbyte_cells
== 2
6245 && (*mb_off2cells
)(off
) == 1
6246 && (*mb_off2cells
)(off
+ 1) > 1)))
6247 clear_next_cell
= TRUE
;
6249 /* Make sure we never leave a second byte of a double-byte behind,
6250 * it confuses mb_off2cells(). */
6252 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
) > 1)
6253 || (mbyte_cells
== 2
6254 && (*mb_off2cells
)(off
) == 1
6255 && (*mb_off2cells
)(off
+ 1) > 1)))
6256 ScreenLines
[off
+ mbyte_blen
] = 0;
6258 ScreenLines
[off
] = c
;
6259 ScreenAttrs
[off
] = attr
;
6263 if (c
< 0x80 && u8cc
[0] == 0)
6264 ScreenLinesUC
[off
] = 0;
6269 ScreenLinesUC
[off
] = u8c
;
6270 for (i
= 0; i
< Screen_mco
; ++i
)
6272 ScreenLinesC
[i
][off
] = u8cc
[i
];
6277 if (mbyte_cells
== 2)
6279 ScreenLines
[off
+ 1] = 0;
6280 ScreenAttrs
[off
+ 1] = attr
;
6282 screen_char(off
, row
, col
);
6284 else if (mbyte_cells
== 2)
6286 ScreenLines
[off
+ 1] = ptr
[1];
6287 ScreenAttrs
[off
+ 1] = attr
;
6288 screen_char_2(off
, row
, col
);
6290 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6292 ScreenLines2
[off
] = ptr
[1];
6293 screen_char(off
, row
, col
);
6297 screen_char(off
, row
, col
);
6305 if (clear_next_cell
)
6306 ptr
= (char_u
*)" ";
6318 #ifdef FEAT_SEARCH_EXTRA
6320 * Prepare for 'searchhl' highlighting.
6325 if (p_hls
&& !no_hlsearch
)
6327 last_pat_prog(&search_hl
.rm
);
6328 search_hl
.attr
= hl_attr(HLF_L
);
6333 * Clean up for 'searchhl' highlighting.
6338 if (search_hl
.rm
.regprog
!= NULL
)
6340 vim_free(search_hl
.rm
.regprog
);
6341 search_hl
.rm
.regprog
= NULL
;
6346 * Advance to the match in window "wp" line "lnum" or past it.
6349 prepare_search_hl(wp
, lnum
)
6353 match_T
*shl
; /* points to search_hl or match_hl */
6358 * When using a multi-line pattern, start searching at the top
6359 * of the window or just after a closed fold.
6360 * Do this both for search_hl and match_hl[3].
6362 for (i
= 3; i
>= 0; --i
)
6364 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
6365 if (shl
->rm
.regprog
!= NULL
6367 && re_multiline(shl
->rm
.regprog
))
6369 if (shl
->first_lnum
== 0)
6371 # ifdef FEAT_FOLDING
6372 for (shl
->first_lnum
= lnum
;
6373 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6374 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6375 NULL
, NULL
, TRUE
, NULL
))
6378 shl
->first_lnum
= wp
->w_topline
;
6382 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6384 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6387 shl
->first_lnum
= shl
->lnum
6388 + shl
->rm
.endpos
[0].lnum
6389 - shl
->rm
.startpos
[0].lnum
;
6390 n
= shl
->rm
.endpos
[0].col
;
6403 * Search for a next 'searchl' or ":match" match.
6405 * Sets shl->lnum and shl->rm contents.
6406 * Note: Assumes a previous match is always before "lnum", unless
6407 * shl->lnum is zero.
6408 * Careful: Any pointers for buffer lines will become invalid.
6411 next_search_hl(win
, shl
, lnum
, mincol
)
6413 match_T
*shl
; /* points to search_hl or match_hl */
6415 colnr_T mincol
; /* minimal column for a match */
6423 /* Check for three situations:
6424 * 1. If the "lnum" is below a previous match, start a new search.
6425 * 2. If the previous match includes "mincol", use it.
6426 * 3. Continue after the previous match.
6428 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6431 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6436 * Repeat searching for a match until one is found that includes "mincol"
6437 * or none is found in this line.
6439 called_emsg
= FALSE
;
6442 /* Three situations:
6443 * 1. No useful previous match: search from start of line.
6444 * 2. Not Vi compatible or empty match: continue at next character.
6445 * Break the loop if this is beyond the end of the line.
6446 * 3. Vi compatible searching: continue at end of previous match.
6450 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6451 || (shl
->rm
.endpos
[0].lnum
== 0
6452 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6456 matchcol
= shl
->rm
.startpos
[0].col
;
6457 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6466 matchcol
+= mb_ptr2len(ml
);
6472 matchcol
= shl
->rm
.endpos
[0].col
;
6475 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
);
6478 /* Error while handling regexp: stop using this regexp. */
6479 vim_free(shl
->rm
.regprog
);
6480 shl
->rm
.regprog
= NULL
;
6486 shl
->lnum
= 0; /* no match found */
6489 if (shl
->rm
.startpos
[0].lnum
> 0
6490 || shl
->rm
.startpos
[0].col
>= mincol
6492 || shl
->rm
.endpos
[0].col
> mincol
)
6494 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6495 break; /* useful match found */
6502 screen_start_highlight(attr
)
6505 attrentry_T
*aep
= NULL
;
6519 /* The GUI handles this internally. */
6520 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6526 if (attr
> HL_ALL
) /* special HL attr. */
6529 aep
= syn_cterm_attr2entry(attr
);
6531 aep
= syn_term_attr2entry(attr
);
6532 if (aep
== NULL
) /* did ":syntax clear" */
6535 attr
= aep
->ae_attr
;
6537 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6539 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6540 && cterm_normal_fg_bold
)
6541 /* If the Normal FG color has BOLD attribute and the new HL
6542 * has a FG color defined, clear BOLD. */
6544 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6546 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6547 /* underline or undercurl */
6549 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6551 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6555 * Output the color or start string after bold etc., in case the
6556 * bold etc. override the color setting.
6562 if (aep
->ae_u
.cterm
.fg_color
)
6563 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6564 if (aep
->ae_u
.cterm
.bg_color
)
6565 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6569 if (aep
->ae_u
.term
.start
!= NULL
)
6570 out_str(aep
->ae_u
.term
.start
);
6578 screen_stop_highlight()
6580 int do_ME
= FALSE
; /* output T_ME code */
6582 if (screen_attr
!= 0
6593 /* use internal GUI code */
6594 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6600 if (screen_attr
> HL_ALL
) /* special HL attr. */
6607 * Assume that t_me restores the original colors!
6609 aep
= syn_cterm_attr2entry(screen_attr
);
6610 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6611 || aep
->ae_u
.cterm
.bg_color
))
6616 aep
= syn_term_attr2entry(screen_attr
);
6617 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6619 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6622 out_str(aep
->ae_u
.term
.stop
);
6625 if (aep
== NULL
) /* did ":syntax clear" */
6628 screen_attr
= aep
->ae_attr
;
6632 * Often all ending-codes are equal to T_ME. Avoid outputting the
6633 * same sequence several times.
6635 if (screen_attr
& HL_STANDOUT
)
6637 if (STRCMP(T_SE
, T_ME
) == 0)
6642 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6644 if (STRCMP(T_UE
, T_ME
) == 0)
6649 if (screen_attr
& HL_ITALIC
)
6651 if (STRCMP(T_CZR
, T_ME
) == 0)
6656 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6661 /* set Normal cterm colors */
6662 if (cterm_normal_fg_color
!= 0)
6663 term_fg_color(cterm_normal_fg_color
- 1);
6664 if (cterm_normal_bg_color
!= 0)
6665 term_bg_color(cterm_normal_bg_color
- 1);
6666 if (cterm_normal_fg_bold
)
6675 * Reset the colors for a cterm. Used when leaving Vim.
6676 * The machine specific code may override this again.
6679 reset_cterm_colors()
6683 /* set Normal cterm colors */
6684 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
6689 if (cterm_normal_fg_bold
)
6698 * Put character ScreenLines["off"] on the screen at position "row" and "col",
6699 * using the attributes from ScreenAttrs["off"].
6702 screen_char(off
, row
, col
)
6709 /* Check for illegal values, just in case (could happen just after
6711 if (row
>= screen_Rows
|| col
>= screen_Columns
)
6714 /* Outputting the last character on the screen may scrollup the screen.
6715 * Don't to it! Mark the character invalid (update it when scrolled up) */
6716 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
6717 #ifdef FEAT_RIGHTLEFT
6718 /* account for first command-line character in rightleft mode */
6723 ScreenAttrs
[off
] = (sattr_T
)-1;
6728 * Stop highlighting first, so it's easier to move the cursor.
6730 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
6731 if (screen_char_attr
!= 0)
6732 attr
= screen_char_attr
;
6735 attr
= ScreenAttrs
[off
];
6736 if (screen_attr
!= attr
)
6737 screen_stop_highlight();
6741 if (screen_attr
!= attr
)
6742 screen_start_highlight(attr
);
6745 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6747 char_u buf
[MB_MAXBYTES
+ 1];
6749 /* Convert UTF-8 character to bytes and write it. */
6751 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
6754 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
6763 out_char(ScreenLines
[off
]);
6765 /* double-byte character in single-width cell */
6766 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6767 out_char(ScreenLines2
[off
]);
6777 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
6778 * on the screen at position 'row' and 'col'.
6779 * The attributes of the first byte is used for all. This is required to
6780 * output the two bytes of a double-byte character with nothing in between.
6783 screen_char_2(off
, row
, col
)
6788 /* Check for illegal values (could be wrong when screen was resized). */
6789 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
6792 /* Outputting the last character on the screen may scrollup the screen.
6793 * Don't to it! Mark the character invalid (update it when scrolled up) */
6794 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
6796 ScreenAttrs
[off
] = (sattr_T
)-1;
6800 /* Output the first byte normally (positions the cursor), then write the
6801 * second byte directly. */
6802 screen_char(off
, row
, col
);
6803 out_char(ScreenLines
[off
+ 1]);
6808 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
6810 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
6811 * This uses the contents of ScreenLines[] and doesn't change it.
6814 screen_draw_rectangle(row
, col
, height
, width
, invert
)
6824 /* Can't use ScreenLines unless initialized */
6825 if (ScreenLines
== NULL
)
6829 screen_char_attr
= HL_INVERSE
;
6830 for (r
= row
; r
< row
+ height
; ++r
)
6832 off
= LineOffset
[r
];
6833 for (c
= col
; c
< col
+ width
; ++c
)
6836 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
) > 1)
6838 screen_char_2(off
+ c
, r
, c
);
6844 screen_char(off
+ c
, r
, c
);
6846 if (utf_off2cells(off
+ c
) > 1)
6852 screen_char_attr
= 0;
6856 #ifdef FEAT_VERTSPLIT
6858 * Redraw the characters for a vertically split window.
6861 redraw_block(row
, end
, wp
)
6869 # ifdef FEAT_CLIPBOARD
6870 clip_may_clear_selection(row
, end
- 1);
6881 width
= wp
->w_width
;
6883 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
6888 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
6889 * with character 'c1' in first column followed by 'c2' in the other columns.
6890 * Use attributes 'attr'.
6893 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
6894 int start_row
, end_row
;
6895 int start_col
, end_col
;
6906 #if defined(FEAT_GUI) || defined(UNIX)
6907 int force_next
= FALSE
;
6910 if (end_row
> screen_Rows
) /* safety check */
6911 end_row
= screen_Rows
;
6912 if (end_col
> screen_Columns
) /* safety check */
6913 end_col
= screen_Columns
;
6914 if (ScreenLines
== NULL
6915 || start_row
>= end_row
6916 || start_col
>= end_col
) /* nothing to do */
6919 /* it's a "normal" terminal when not in a GUI or cterm */
6925 for (row
= start_row
; row
< end_row
; ++row
)
6928 * Try to use delete-line termcap code, when no attributes or in a
6929 * "normal" terminal, where a bold/italic space is just a
6934 && end_col
== Columns
6939 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
6942 * check if we really need to clear something
6945 if (c1
!= ' ') /* don't clear first char */
6948 off
= LineOffset
[row
] + col
;
6949 end_off
= LineOffset
[row
] + end_col
;
6951 /* skip blanks (used often, keep it fast!) */
6954 while (off
< end_off
&& ScreenLines
[off
] == ' '
6955 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
6959 while (off
< end_off
&& ScreenLines
[off
] == ' '
6960 && ScreenAttrs
[off
] == 0)
6962 if (off
< end_off
) /* something to be cleared */
6964 col
= off
- LineOffset
[row
];
6965 screen_stop_highlight();
6966 term_windgoto(row
, col
);/* clear rest of this screen line */
6968 screen_start(); /* don't know where cursor is now */
6969 col
= end_col
- col
;
6970 while (col
--) /* clear chars in ScreenLines */
6972 ScreenLines
[off
] = ' ';
6975 ScreenLinesUC
[off
] = 0;
6977 ScreenAttrs
[off
] = 0;
6981 did_delete
= TRUE
; /* the chars are cleared now */
6984 off
= LineOffset
[row
] + start_col
;
6986 for (col
= start_col
; col
< end_col
; ++col
)
6988 if (ScreenLines
[off
] != c
6990 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
6991 != (c
>= 0x80 ? c
: 0))
6993 || ScreenAttrs
[off
] != attr
6994 #if defined(FEAT_GUI) || defined(UNIX)
6999 #if defined(FEAT_GUI) || defined(UNIX)
7000 /* The bold trick may make a single row of pixels appear in
7001 * the next character. When a bold character is removed, the
7002 * next character should be redrawn too. This happens for our
7003 * own GUI and for some xterms. */
7008 # if defined(FEAT_GUI) && defined(UNIX)
7016 if (ScreenLines
[off
] != ' '
7017 && (ScreenAttrs
[off
] > HL_ALL
7018 || ScreenAttrs
[off
] & HL_BOLD
))
7024 ScreenLines
[off
] = c
;
7030 ScreenLinesUC
[off
] = c
;
7031 ScreenLinesC
[0][off
] = 0;
7034 ScreenLinesUC
[off
] = 0;
7037 ScreenAttrs
[off
] = attr
;
7038 if (!did_delete
|| c
!= ' ')
7039 screen_char(off
, row
, col
);
7042 if (col
== start_col
)
7049 if (end_col
== Columns
)
7050 LineWraps
[row
] = FALSE
;
7051 if (row
== Rows
- 1) /* overwritten the command line */
7053 redraw_cmdline
= TRUE
;
7054 if (c1
== ' ' && c2
== ' ')
7055 clear_cmdline
= FALSE
; /* command line has been cleared */
7057 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7063 * Check if there should be a delay. Used before clearing or redrawing the
7064 * screen or the command line.
7067 check_for_delay(check_msg_scroll
)
7068 int check_msg_scroll
;
7070 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7072 && emsg_silent
== 0)
7075 ui_delay(1000L, TRUE
);
7076 emsg_on_display
= FALSE
;
7077 if (check_msg_scroll
)
7083 * screen_valid - allocate screen buffers if size changed
7084 * If "clear" is TRUE: clear screen if it has been resized.
7085 * Returns TRUE if there is a valid screen to write to.
7086 * Returns FALSE when starting up and screen not initialized yet.
7092 screenalloc(clear
); /* allocate screen buffers if size changed */
7093 return (ScreenLines
!= NULL
);
7097 * Resize the shell to Rows and Columns.
7098 * Allocate ScreenLines[] and associated items.
7100 * There may be some time between setting Rows and Columns and (re)allocating
7101 * ScreenLines[]. This happens when starting up and when (manually) changing
7102 * the shell size. Always use screen_Rows and screen_Columns to access items
7103 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7104 * final size of the shell is needed.
7110 int new_row
, old_row
;
7115 int outofmem
= FALSE
;
7117 schar_T
*new_ScreenLines
;
7119 u8char_T
*new_ScreenLinesUC
= NULL
;
7120 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7121 schar_T
*new_ScreenLines2
= NULL
;
7124 sattr_T
*new_ScreenAttrs
;
7125 unsigned *new_LineOffset
;
7126 char_u
*new_LineWraps
;
7128 short *new_TabPageIdxs
;
7131 static int entered
= FALSE
; /* avoid recursiveness */
7132 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7135 * Allocation of the screen buffers is done only when the size changes and
7136 * when Rows and Columns have been set and we have started doing full
7139 if ((ScreenLines
!= NULL
7140 && Rows
== screen_Rows
7141 && Columns
== screen_Columns
7143 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7144 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7145 && p_mco
== Screen_mco
7150 || (!full_screen
&& ScreenLines
== NULL
))
7154 * It's possible that we produce an out-of-memory message below, which
7155 * will cause this function to be called again. To break the loop, just
7163 * Note that the window sizes are updated before reallocating the arrays,
7164 * thus we must not redraw here!
7166 ++RedrawingDisabled
;
7168 win_new_shellsize(); /* fit the windows in the new sized shell */
7170 comp_col(); /* recompute columns for shown command and ruler */
7173 * We're changing the size of the screen.
7174 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7175 * - Move lines from the old arrays into the new arrays, clear extra
7176 * lines (unless the screen is going to be cleared).
7177 * - Free the old arrays.
7179 * If anything fails, make ScreenLines NULL, so we don't do anything!
7180 * Continuing with the old ScreenLines may result in a crash, because the
7183 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7186 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7187 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7189 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
) * MAX_MCO
);
7192 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7193 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7194 for (i
= 0; i
< p_mco
; ++i
)
7195 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc((long_u
)(
7196 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7198 if (enc_dbcs
== DBCS_JPNU
)
7199 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7200 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7202 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7203 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7204 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7205 Rows
* sizeof(unsigned)), FALSE
);
7206 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7208 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7211 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7213 if (win_alloc_lines(wp
) == FAIL
)
7223 for (i
= 0; i
< p_mco
; ++i
)
7224 if (new_ScreenLinesC
[i
] == NULL
)
7227 if (new_ScreenLines
== NULL
7229 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7230 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7232 || new_ScreenAttrs
== NULL
7233 || new_LineOffset
== NULL
7234 || new_LineWraps
== NULL
7236 || new_TabPageIdxs
== NULL
7240 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7242 /* guess the size */
7243 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7245 /* Remember we did this to avoid getting outofmem messages over
7246 * and over again. */
7247 done_outofmem_msg
= TRUE
;
7249 vim_free(new_ScreenLines
);
7250 new_ScreenLines
= NULL
;
7252 vim_free(new_ScreenLinesUC
);
7253 new_ScreenLinesUC
= NULL
;
7254 for (i
= 0; i
< p_mco
; ++i
)
7256 vim_free(new_ScreenLinesC
[i
]);
7257 new_ScreenLinesC
[i
] = NULL
;
7259 vim_free(new_ScreenLines2
);
7260 new_ScreenLines2
= NULL
;
7262 vim_free(new_ScreenAttrs
);
7263 new_ScreenAttrs
= NULL
;
7264 vim_free(new_LineOffset
);
7265 new_LineOffset
= NULL
;
7266 vim_free(new_LineWraps
);
7267 new_LineWraps
= NULL
;
7269 vim_free(new_TabPageIdxs
);
7270 new_TabPageIdxs
= NULL
;
7275 done_outofmem_msg
= FALSE
;
7277 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7279 new_LineOffset
[new_row
] = new_row
* Columns
;
7280 new_LineWraps
[new_row
] = FALSE
;
7283 * If the screen is not going to be cleared, copy as much as
7284 * possible from the old screen to the new one and clear the rest
7285 * (used when resizing the window at the "--more--" prompt or when
7286 * executing an external command, for the GUI).
7290 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7291 ' ', (size_t)Columns
* sizeof(schar_T
));
7295 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7296 0, (size_t)Columns
* sizeof(u8char_T
));
7297 for (i
= 0; i
< p_mco
; ++i
)
7298 (void)vim_memset(new_ScreenLinesC
[i
]
7299 + new_row
* Columns
,
7300 0, (size_t)Columns
* sizeof(u8char_T
));
7302 if (enc_dbcs
== DBCS_JPNU
)
7303 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7304 0, (size_t)Columns
* sizeof(schar_T
));
7306 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7307 0, (size_t)Columns
* sizeof(sattr_T
));
7308 old_row
= new_row
+ (screen_Rows
- Rows
);
7309 if (old_row
>= 0 && ScreenLines
!= NULL
)
7311 if (screen_Columns
< Columns
)
7312 len
= screen_Columns
;
7316 /* When switching to utf-8 don't copy characters, they
7317 * may be invalid now. Also when p_mco changes. */
7318 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7319 && p_mco
== Screen_mco
)
7321 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7322 ScreenLines
+ LineOffset
[old_row
],
7323 (size_t)len
* sizeof(schar_T
));
7325 if (enc_utf8
&& ScreenLinesUC
!= NULL
7326 && p_mco
== Screen_mco
)
7328 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7329 ScreenLinesUC
+ LineOffset
[old_row
],
7330 (size_t)len
* sizeof(u8char_T
));
7331 for (i
= 0; i
< p_mco
; ++i
)
7332 mch_memmove(new_ScreenLinesC
[i
]
7333 + new_LineOffset
[new_row
],
7334 ScreenLinesC
[i
] + LineOffset
[old_row
],
7335 (size_t)len
* sizeof(u8char_T
));
7337 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7338 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7339 ScreenLines2
+ LineOffset
[old_row
],
7340 (size_t)len
* sizeof(schar_T
));
7342 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7343 ScreenAttrs
+ LineOffset
[old_row
],
7344 (size_t)len
* sizeof(sattr_T
));
7348 /* Use the last line of the screen for the current line. */
7349 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7354 ScreenLines
= new_ScreenLines
;
7356 ScreenLinesUC
= new_ScreenLinesUC
;
7357 for (i
= 0; i
< p_mco
; ++i
)
7358 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7360 ScreenLines2
= new_ScreenLines2
;
7362 ScreenAttrs
= new_ScreenAttrs
;
7363 LineOffset
= new_LineOffset
;
7364 LineWraps
= new_LineWraps
;
7366 TabPageIdxs
= new_TabPageIdxs
;
7369 /* It's important that screen_Rows and screen_Columns reflect the actual
7370 * size of ScreenLines[]. Set them before calling anything. */
7372 old_Rows
= screen_Rows
;
7375 screen_Columns
= Columns
;
7377 must_redraw
= CLEAR
; /* need to clear the screen later */
7384 && ScreenLines
!= NULL
7385 && old_Rows
!= Rows
)
7387 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7389 * Adjust the position of the cursor, for when executing an external
7392 if (msg_row
>= Rows
) /* Rows got smaller */
7393 msg_row
= Rows
- 1; /* put cursor at last row */
7394 else if (Rows
> old_Rows
) /* Rows got bigger */
7395 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7396 if (msg_col
>= Columns
) /* Columns got smaller */
7397 msg_col
= Columns
- 1; /* put cursor at last column */
7402 --RedrawingDisabled
;
7406 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7416 vim_free(ScreenLinesUC
);
7417 for (i
= 0; i
< Screen_mco
; ++i
)
7418 vim_free(ScreenLinesC
[i
]);
7419 vim_free(ScreenLines2
);
7421 vim_free(ScreenLines
);
7422 vim_free(ScreenAttrs
);
7423 vim_free(LineOffset
);
7424 vim_free(LineWraps
);
7426 vim_free(TabPageIdxs
);
7433 check_for_delay(FALSE
);
7434 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7435 screenclear2(); /* clear the screen */
7443 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7445 || (gui
.in_use
&& gui
.starting
)
7453 screen_attr
= -1; /* force setting the Normal colors */
7454 screen_stop_highlight(); /* don't want highlighting here */
7456 #ifdef FEAT_CLIPBOARD
7457 /* disable selection without redrawing it */
7458 clip_scroll_selection(9999);
7461 /* blank out ScreenLines */
7462 for (i
= 0; i
< Rows
; ++i
)
7464 lineclear(LineOffset
[i
], (int)Columns
);
7465 LineWraps
[i
] = FALSE
;
7468 if (can_clear(T_CL
))
7470 out_str(T_CL
); /* clear the display */
7471 clear_cmdline
= FALSE
;
7472 mode_displayed
= FALSE
;
7476 /* can't clear the screen, mark all chars with invalid attributes */
7477 for (i
= 0; i
< Rows
; ++i
)
7478 lineinvalid(LineOffset
[i
], (int)Columns
);
7479 clear_cmdline
= TRUE
;
7482 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7484 win_rest_invalid(firstwin
);
7485 redraw_cmdline
= TRUE
;
7487 redraw_tabline
= TRUE
;
7489 if (must_redraw
== CLEAR
) /* no need to clear again */
7490 must_redraw
= NOT_VALID
;
7492 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7494 screen_start(); /* don't know where cursor is now */
7495 msg_scrolled
= 0; /* can't scroll back */
7501 * Clear one line in ScreenLines.
7504 lineclear(off
, width
)
7508 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7511 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7512 (size_t)width
* sizeof(u8char_T
));
7514 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7518 * Mark one line in ScreenLines invalid by setting the attributes to an
7522 lineinvalid(off
, width
)
7526 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7529 #ifdef FEAT_VERTSPLIT
7531 * Copy part of a Screenline for vertically split window "wp".
7534 linecopy(to
, from
, wp
)
7539 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7540 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7542 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7543 wp
->w_width
* sizeof(schar_T
));
7549 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7550 wp
->w_width
* sizeof(u8char_T
));
7551 for (i
= 0; i
< p_mco
; ++i
)
7552 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7553 wp
->w_width
* sizeof(u8char_T
));
7555 if (enc_dbcs
== DBCS_JPNU
)
7556 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7557 wp
->w_width
* sizeof(schar_T
));
7559 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7560 wp
->w_width
* sizeof(sattr_T
));
7565 * Return TRUE if clearing with term string "p" would work.
7566 * It can't work when the string is empty or it won't set the right background.
7572 return (*p
!= NUL
&& (t_colors
<= 1
7576 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7580 * Reset cursor position. Use whenever cursor was moved because of outputting
7581 * something directly to the screen (shell commands) or a terminal control
7587 screen_cur_row
= screen_cur_col
= 9999;
7591 * Move the cursor to position "row","col" in the screen.
7592 * This tries to find the most efficient way to move, minimizing the number of
7593 * characters sent to the terminal.
7610 #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */
7611 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7616 #define PLAN_WRITE 4
7617 /* Can't use ScreenLines unless initialized */
7618 if (ScreenLines
== NULL
)
7621 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7623 /* Check for valid position. */
7624 if (row
< 0) /* window without text lines? */
7626 if (row
>= screen_Rows
)
7627 row
= screen_Rows
- 1;
7628 if (col
>= screen_Columns
)
7629 col
= screen_Columns
- 1;
7631 /* check if no cursor movement is allowed in highlight mode */
7632 if (screen_attr
&& *T_MS
== NUL
)
7633 noinvcurs
= HIGHL_COST
;
7636 goto_cost
= GOTO_COST
+ noinvcurs
;
7639 * Plan how to do the positioning:
7640 * 1. Use CR to move it to column 0, same row.
7641 * 2. Use T_LE to move it a few columns to the left.
7642 * 3. Use NL to move a few lines down, column 0.
7643 * 4. Move a few columns to the right with T_ND or by writing chars.
7645 * Don't do this if the cursor went beyond the last column, the cursor
7646 * position is unknown then (some terminals wrap, some don't )
7648 * First check if the highlighting attibutes allow us to write
7649 * characters to move the cursor to the right.
7651 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
7654 * If the cursor is in the same row, bigger col, we can use CR
7657 bs
= NULL
; /* init for GCC */
7659 if (row
== screen_cur_row
&& col
< screen_cur_col
)
7661 /* "le" is preferred over "bc", because "bc" is obsolete */
7663 bs
= T_LE
; /* "cursor left" */
7665 bs
= T_BC
; /* "backspace character (old) */
7667 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
7670 if (col
+ 1 < cost
) /* using CR is less characters */
7674 cost
= 1; /* CR is just one character */
7681 if (noinvcurs
) /* will stop highlighting */
7689 * If the cursor is above where we want to be, we can use CR LF.
7691 else if (row
> screen_cur_row
)
7695 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
7696 if (noinvcurs
) /* will stop highlighting */
7704 * If the cursor is in the same row, smaller col, just use write.
7709 wouldbe_col
= screen_cur_col
;
7714 * Check if any characters that need to be written have the
7715 * correct attributes. Also avoid UTF-8 characters.
7717 i
= col
- wouldbe_col
;
7720 if (cost
< goto_cost
&& i
> 0)
7723 * Check if the attributes are correct without additionally
7724 * stopping highlighting.
7726 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
7727 while (i
&& *p
++ == attr
)
7732 * Try if it works when highlighting is stopped here.
7737 while (i
&& *p
++ == 0)
7741 cost
= 999; /* different attributes, don't do it */
7746 /* Don't use an UTF-8 char for positioning, it's slow. */
7747 for (i
= wouldbe_col
; i
< col
; ++i
)
7748 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
7758 * We can do it without term_windgoto()!
7760 if (cost
< goto_cost
)
7762 if (plan
== PLAN_LE
)
7765 screen_stop_highlight();
7766 while (screen_cur_col
> col
)
7772 else if (plan
== PLAN_CR
)
7775 screen_stop_highlight();
7779 else if (plan
== PLAN_NL
)
7782 screen_stop_highlight();
7783 while (screen_cur_row
< row
)
7791 i
= col
- screen_cur_col
;
7795 * Use cursor-right if it's one character only. Avoids
7796 * removing a line of pixels from the last bold char, when
7797 * using the bold trick in the GUI.
7799 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
7808 off
= LineOffset
[row
] + screen_cur_col
;
7811 if (ScreenAttrs
[off
] != screen_attr
)
7812 screen_stop_highlight();
7816 out_char(ScreenLines
[off
]);
7818 if (enc_dbcs
== DBCS_JPNU
7819 && ScreenLines
[off
] == 0x8e)
7820 out_char(ScreenLines2
[off
]);
7831 if (cost
>= goto_cost
)
7834 screen_stop_highlight();
7835 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
7837 term_cursor_right(col
- screen_cur_col
);
7839 term_windgoto(row
, col
);
7841 screen_cur_row
= row
;
7842 screen_cur_col
= col
;
7847 * Set cursor to its position in the current window.
7855 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
7856 W_WINCOL(curwin
) + (
7857 #ifdef FEAT_RIGHTLEFT
7858 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
7860 has_mbyte
? (*mb_ptr2cells
)(ml_get_cursor()) :
7870 * insert 'line_count' lines at 'row' in window 'wp'
7871 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
7872 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
7874 * Returns FAIL if the lines are not inserted, OK for success.
7877 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
7890 wp
->w_lines_valid
= 0;
7892 if (wp
->w_height
< 5)
7895 if (line_count
> wp
->w_height
- row
)
7896 line_count
= wp
->w_height
- row
;
7898 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
7899 if (retval
!= MAYBE
)
7903 * If there is a next window or a status line, we first try to delete the
7904 * lines at the bottom to avoid messing what is after the window.
7905 * If this fails and there are following windows, don't do anything to avoid
7906 * messing up those windows, better just redraw.
7910 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
7912 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
7913 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
7915 else if (wp
->w_next
)
7920 * if no lines deleted, blank the lines that will end up below the window
7925 wp
->w_redr_status
= TRUE
;
7927 redraw_cmdline
= TRUE
;
7928 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
7929 lastrow
= nextrow
+ line_count
;
7932 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
7933 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
7937 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
7940 /* deletion will have messed up other windows */
7944 wp
->w_redr_status
= TRUE
;
7946 win_rest_invalid(W_NEXT(wp
));
7955 * delete "line_count" window lines at "row" in window "wp"
7956 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
7957 * If "mayclear" is TRUE the screen will be cleared if it is faster than
7959 * Return OK for success, FAIL if the lines are not deleted.
7962 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
7972 wp
->w_lines_valid
= 0;
7974 if (line_count
> wp
->w_height
- row
)
7975 line_count
= wp
->w_height
- row
;
7977 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
7978 if (retval
!= MAYBE
)
7981 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
7982 (int)Rows
, FALSE
, NULL
) == FAIL
)
7987 * If there are windows or status lines below, try to put them at the
7988 * correct place. If we can't do that, they have to be redrawn.
7990 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
7992 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
7993 line_count
, (int)Rows
, NULL
) == FAIL
)
7995 wp
->w_redr_status
= TRUE
;
7996 win_rest_invalid(wp
->w_next
);
8000 * If this is the last window and there is no status line, redraw the
8001 * command line later.
8005 redraw_cmdline
= TRUE
;
8010 * Common code for win_ins_lines() and win_del_lines().
8011 * Returns OK or FAIL when the work has been done.
8012 * Returns MAYBE when not finished yet.
8015 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8024 if (!redrawing() || line_count
<= 0)
8027 /* only a few lines left: redraw is faster */
8028 if (mayclear
&& Rows
- line_count
< 5
8029 #ifdef FEAT_VERTSPLIT
8030 && wp
->w_width
== Columns
8034 screenclear(); /* will set wp->w_lines_valid to 0 */
8039 * Delete all remaining lines
8041 if (row
+ line_count
>= wp
->w_height
)
8043 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8044 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8050 * when scrolling, the message on the command line should be cleared,
8051 * otherwise it will stay there forever.
8053 clear_cmdline
= TRUE
;
8056 * If the terminal can set a scroll region, use that.
8057 * Always do this in a vertically split window. This will redraw from
8058 * ScreenLines[] when t_CV isn't defined. That's faster than using
8060 * Don't use a scroll region when we are going to redraw the text, writing
8061 * a character in the lower right corner of the scroll region causes a
8062 * scroll-up in the DJGPP version.
8065 #ifdef FEAT_VERTSPLIT
8066 || W_WIDTH(wp
) != Columns
8070 #ifdef FEAT_VERTSPLIT
8071 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8073 scroll_region_set(wp
, row
);
8075 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8076 wp
->w_height
- row
, FALSE
, wp
);
8078 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8079 wp
->w_height
- row
, wp
);
8080 #ifdef FEAT_VERTSPLIT
8081 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8083 scroll_region_reset();
8088 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8096 * window 'wp' and everything after it is messed up, mark it for redraw
8099 win_rest_invalid(wp
)
8108 redraw_win_later(wp
, NOT_VALID
);
8110 wp
->w_redr_status
= TRUE
;
8114 redraw_cmdline
= TRUE
;
8118 * The rest of the routines in this file perform screen manipulations. The
8119 * given operation is performed physically on the screen. The corresponding
8120 * change is also made to the internal screen image. In this way, the editor
8121 * anticipates the effect of editing changes on the appearance of the screen.
8122 * That way, when we call screenupdate a complete redraw isn't usually
8123 * necessary. Another advantage is that we can keep adding code to anticipate
8124 * screen changes, and in the meantime, everything still works.
8128 * types for inserting or deleting lines
8138 #define USE_REDRAW 9
8141 * insert lines on the screen and update ScreenLines[]
8142 * 'end' is the line after the scrolled part. Normally it is Rows.
8143 * When scrolling region used 'off' is the offset from the top for the region.
8144 * 'row' and 'end' are relative to the start of the region.
8146 * return FAIL for failure, OK for success.
8149 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8154 win_T
*wp
; /* NULL or window to use width from */
8162 int can_ce
= can_clear(T_CE
);
8166 * - there is no valid screen
8167 * - the screen has to be redrawn completely
8168 * - the line count is less than one
8169 * - the line count is more than 'ttyscroll'
8171 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8175 * There are seven ways to insert lines:
8176 * 0. When in a vertically split window and t_CV isn't set, redraw the
8177 * characters from ScreenLines[].
8178 * 1. Use T_CD (clear to end of display) if it exists and the result of
8179 * the insert is just empty lines
8180 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8181 * present or line_count > 1. It looks better if we do all the inserts
8183 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8184 * insert is just empty lines and T_CE is not present or line_count >
8186 * 4. Use T_AL (insert line) if it exists.
8187 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8189 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8191 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8192 * the 'da' flag is not set or we have clear line capability.
8193 * 8. redraw the characters from ScreenLines[].
8195 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8196 * the scrollbar for the window. It does have insert line, use that if it
8199 result_empty
= (row
+ line_count
>= end
);
8200 #ifdef FEAT_VERTSPLIT
8201 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8205 if (can_clear(T_CD
) && result_empty
)
8207 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8209 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8211 else if (*T_AL
!= NUL
)
8213 else if (can_ce
&& result_empty
)
8215 else if (*T_DL
!= NUL
&& result_empty
)
8217 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8223 * For clearing the lines screen_del_lines() is used. This will also take
8224 * care of t_db if necessary.
8226 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8227 type
== USE_T_CE
|| type
== USE_T_DL
)
8228 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8231 * If text is retained below the screen, first clear or delete as many
8232 * lines at the bottom of the window as are about to be inserted so that
8233 * the deleted lines won't later surface during a screen_del_lines.
8236 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8238 #ifdef FEAT_CLIPBOARD
8239 /* Remove a modeless selection when inserting lines halfway the screen
8240 * or not the full width of the screen. */
8242 # ifdef FEAT_VERTSPLIT
8243 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8246 clip_clear_selection();
8248 clip_scroll_selection(-line_count
);
8252 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8253 * scrolling is actually carried out. */
8254 gui_dont_update_cursor();
8257 if (*T_CCS
!= NUL
) /* cursor relative to region */
8260 cursor_row
= row
+ off
;
8263 * Shift LineOffset[] line_count down to reflect the inserted lines.
8264 * Clear the inserted lines in ScreenLines[].
8268 for (i
= 0; i
< line_count
; ++i
)
8270 #ifdef FEAT_VERTSPLIT
8271 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8273 /* need to copy part of a line */
8275 while ((j
-= line_count
) >= row
)
8276 linecopy(j
+ line_count
, j
, wp
);
8278 if (can_clear((char_u
*)" "))
8279 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8281 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8282 LineWraps
[j
] = FALSE
;
8288 temp
= LineOffset
[j
];
8289 while ((j
-= line_count
) >= row
)
8291 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8292 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8294 LineOffset
[j
+ line_count
] = temp
;
8295 LineWraps
[j
+ line_count
] = FALSE
;
8296 if (can_clear((char_u
*)" "))
8297 lineclear(temp
, (int)Columns
);
8299 lineinvalid(temp
, (int)Columns
);
8303 screen_stop_highlight();
8304 windgoto(cursor_row
, 0);
8306 #ifdef FEAT_VERTSPLIT
8307 /* redraw the characters */
8308 if (type
== USE_REDRAW
)
8309 redraw_block(row
, end
, wp
);
8312 if (type
== USE_T_CAL
)
8314 term_append_lines(line_count
);
8315 screen_start(); /* don't know where cursor is now */
8319 for (i
= 0; i
< line_count
; i
++)
8321 if (type
== USE_T_AL
)
8323 if (i
&& cursor_row
!= 0)
8324 windgoto(cursor_row
, 0);
8327 else /* type == USE_T_SR */
8329 screen_start(); /* don't know where cursor is now */
8334 * With scroll-reverse and 'da' flag set we need to clear the lines that
8335 * have been scrolled down into the region.
8337 if (type
== USE_T_SR
&& *T_DA
)
8339 for (i
= 0; i
< line_count
; ++i
)
8341 windgoto(off
+ i
, 0);
8343 screen_start(); /* don't know where cursor is now */
8348 gui_can_update_cursor();
8350 out_flush(); /* always flush after a scroll */
8356 * delete lines on the screen and update ScreenLines[]
8357 * 'end' is the line after the scrolled part. Normally it is Rows.
8358 * When scrolling region used 'off' is the offset from the top for the region.
8359 * 'row' and 'end' are relative to the start of the region.
8361 * Return OK for success, FAIL if the lines are not deleted.
8365 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8370 int force
; /* even when line_count > p_ttyscroll */
8371 win_T
*wp
; /* NULL or window to use width from */
8378 int result_empty
; /* result is empty until end of region */
8379 int can_delete
; /* deleting line codes can be used */
8384 * - there is no valid screen
8385 * - the screen has to be redrawn completely
8386 * - the line count is less than one
8387 * - the line count is more than 'ttyscroll'
8389 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8390 (!force
&& line_count
> p_ttyscroll
))
8394 * Check if the rest of the current region will become empty.
8396 result_empty
= row
+ line_count
>= end
;
8399 * We can delete lines only when 'db' flag not set or when 'ce' option
8402 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8405 * There are six ways to delete lines:
8406 * 0. When in a vertically split window and t_CV isn't set, redraw the
8407 * characters from ScreenLines[].
8408 * 1. Use T_CD if it exists and the result is empty.
8409 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8410 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8411 * none of the other ways work.
8412 * 4. Use T_CE (erase line) if the result is empty.
8413 * 5. Use T_DL (delete line) if it exists.
8414 * 6. redraw the characters from ScreenLines[].
8416 #ifdef FEAT_VERTSPLIT
8417 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8421 if (can_clear(T_CD
) && result_empty
)
8423 #if defined(__BEOS__) && defined(BEOS_DR8)
8425 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8426 * its internal termcap... this works okay for tests which test *T_DB !=
8427 * NUL. It has the disadvantage that the user cannot use any :set t_*
8428 * command to get T_DB (back) to empty_option, only :set term=... will do
8430 * Anyway, this hack will hopefully go away with the next OS release.
8433 else if (row
== 0 && T_DB
== empty_option
8434 && (line_count
== 1 || *T_CDL
== NUL
))
8436 else if (row
== 0 && (
8438 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8439 * up, so use delete-line command */
8445 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8447 else if (can_clear(T_CE
) && result_empty
8448 #ifdef FEAT_VERTSPLIT
8449 && (wp
== NULL
|| wp
->w_width
== Columns
)
8453 else if (*T_DL
!= NUL
&& can_delete
)
8455 else if (*T_CDL
!= NUL
&& can_delete
)
8460 #ifdef FEAT_CLIPBOARD
8461 /* Remove a modeless selection when deleting lines halfway the screen or
8462 * not the full width of the screen. */
8464 # ifdef FEAT_VERTSPLIT
8465 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8468 clip_clear_selection();
8470 clip_scroll_selection(line_count
);
8474 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8475 * scrolling is actually carried out. */
8476 gui_dont_update_cursor();
8479 if (*T_CCS
!= NUL
) /* cursor relative to region */
8486 cursor_row
= row
+ off
;
8487 cursor_end
= end
+ off
;
8491 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8492 * Clear the inserted lines in ScreenLines[].
8496 for (i
= 0; i
< line_count
; ++i
)
8498 #ifdef FEAT_VERTSPLIT
8499 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8501 /* need to copy part of a line */
8503 while ((j
+= line_count
) <= end
- 1)
8504 linecopy(j
- line_count
, j
, wp
);
8506 if (can_clear((char_u
*)" "))
8507 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8509 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8510 LineWraps
[j
] = FALSE
;
8515 /* whole width, moving the line pointers is faster */
8517 temp
= LineOffset
[j
];
8518 while ((j
+= line_count
) <= end
- 1)
8520 LineOffset
[j
- line_count
] = LineOffset
[j
];
8521 LineWraps
[j
- line_count
] = LineWraps
[j
];
8523 LineOffset
[j
- line_count
] = temp
;
8524 LineWraps
[j
- line_count
] = FALSE
;
8525 if (can_clear((char_u
*)" "))
8526 lineclear(temp
, (int)Columns
);
8528 lineinvalid(temp
, (int)Columns
);
8532 screen_stop_highlight();
8534 #ifdef FEAT_VERTSPLIT
8535 /* redraw the characters */
8536 if (type
== USE_REDRAW
)
8537 redraw_block(row
, end
, wp
);
8540 if (type
== USE_T_CD
) /* delete the lines */
8542 windgoto(cursor_row
, 0);
8544 screen_start(); /* don't know where cursor is now */
8546 else if (type
== USE_T_CDL
)
8548 windgoto(cursor_row
, 0);
8549 term_delete_lines(line_count
);
8550 screen_start(); /* don't know where cursor is now */
8553 * Deleting lines at top of the screen or scroll region: Just scroll
8554 * the whole screen (scroll region) up by outputting newlines on the
8557 else if (type
== USE_NL
)
8559 windgoto(cursor_end
- 1, 0);
8560 for (i
= line_count
; --i
>= 0; )
8561 out_char('\n'); /* cursor will remain on same line */
8565 for (i
= line_count
; --i
>= 0; )
8567 if (type
== USE_T_DL
)
8569 windgoto(cursor_row
, 0);
8570 out_str(T_DL
); /* delete a line */
8572 else /* type == USE_T_CE */
8574 windgoto(cursor_row
+ i
, 0);
8575 out_str(T_CE
); /* erase a line */
8577 screen_start(); /* don't know where cursor is now */
8582 * If the 'db' flag is set, we need to clear the lines that have been
8583 * scrolled up at the bottom of the region.
8585 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8587 for (i
= line_count
; i
> 0; --i
)
8589 windgoto(cursor_end
- i
, 0);
8590 out_str(T_CE
); /* erase a line */
8591 screen_start(); /* don't know where cursor is now */
8596 gui_can_update_cursor();
8598 out_flush(); /* always flush after a scroll */
8605 * show the current mode and ruler
8607 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8608 * If clear_cmdline is FALSE there may be a message there that needs to be
8609 * cleared only if a mode is shown.
8610 * Return the length of the message (0 if no message).
8620 #ifdef FEAT_INS_EXPAND
8624 do_mode
= ((p_smd
&& msg_silent
== 0)
8625 && ((State
& INSERT
)
8631 if (do_mode
|| Recording
)
8634 * Don't show mode right now, when not redrawing or inside a mapping.
8635 * Call char_avail() only when we are going to show something, because
8636 * it takes a bit of time.
8638 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
8640 redraw_cmdline
= TRUE
; /* show mode later */
8644 nwr_save
= need_wait_return
;
8646 /* wait a bit before overwriting an important message */
8647 check_for_delay(FALSE
);
8649 /* if the cmdline is more than one line high, erase top lines */
8650 need_clear
= clear_cmdline
;
8651 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
8652 msg_clr_cmdline(); /* will reset clear_cmdline */
8654 /* Position on the last line in the window, column 0 */
8657 attr
= hl_attr(HLF_CM
); /* Highlight mode */
8660 MSG_PUTS_ATTR("--", attr
);
8661 #if defined(FEAT_XIM)
8662 if (xic
!= NULL
&& im_get_status() && !p_imdisable
8663 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
8664 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
8665 MSG_PUTS_ATTR(" IM", attr
);
8667 MSG_PUTS_ATTR(" XIM", attr
);
8670 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
8673 if (hangul_input_state_get())
8674 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
8677 #ifdef FEAT_INS_EXPAND
8678 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
8680 /* These messages can get long, avoid a wrap in a narrow
8681 * window. Prefer showing edit_submode_extra. */
8682 length
= (Rows
- msg_row
) * Columns
- 3;
8683 if (edit_submode_extra
!= NULL
)
8684 length
-= vim_strsize(edit_submode_extra
);
8687 if (edit_submode_pre
!= NULL
)
8688 length
-= vim_strsize(edit_submode_pre
);
8689 if (length
- vim_strsize(edit_submode
) > 0)
8691 if (edit_submode_pre
!= NULL
)
8692 msg_puts_attr(edit_submode_pre
, attr
);
8693 msg_puts_attr(edit_submode
, attr
);
8695 if (edit_submode_extra
!= NULL
)
8697 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
8698 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
8699 sub_attr
= hl_attr(edit_submode_highl
);
8702 msg_puts_attr(edit_submode_extra
, sub_attr
);
8710 #ifdef FEAT_VREPLACE
8711 if (State
& VREPLACE_FLAG
)
8712 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
8715 if (State
& REPLACE_FLAG
)
8716 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
8717 else if (State
& INSERT
)
8719 #ifdef FEAT_RIGHTLEFT
8721 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
8723 MSG_PUTS_ATTR(_(" INSERT"), attr
);
8725 else if (restart_edit
== 'I')
8726 MSG_PUTS_ATTR(_(" (insert)"), attr
);
8727 else if (restart_edit
== 'R')
8728 MSG_PUTS_ATTR(_(" (replace)"), attr
);
8729 else if (restart_edit
== 'V')
8730 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
8731 #ifdef FEAT_RIGHTLEFT
8733 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
8736 MSG_PUTS_ATTR(farsi_text_5
, attr
);
8740 if (State
& LANGMAP
)
8743 if (curwin
->w_p_arab
)
8744 MSG_PUTS_ATTR(_(" Arabic"), attr
);
8747 MSG_PUTS_ATTR(_(" (lang)"), attr
);
8750 if ((State
& INSERT
) && p_paste
)
8751 MSG_PUTS_ATTR(_(" (paste)"), attr
);
8758 /* Don't concatenate separate words to avoid translation
8760 switch ((VIsual_select
? 4 : 0)
8761 + (VIsual_mode
== Ctrl_V
) * 2
8762 + (VIsual_mode
== 'V'))
8764 case 0: p
= N_(" VISUAL"); break;
8765 case 1: p
= N_(" VISUAL LINE"); break;
8766 case 2: p
= N_(" VISUAL BLOCK"); break;
8767 case 4: p
= N_(" SELECT"); break;
8768 case 5: p
= N_(" SELECT LINE"); break;
8769 default: p
= N_(" SELECT BLOCK"); break;
8771 MSG_PUTS_ATTR(_(p
), attr
);
8774 MSG_PUTS_ATTR(" --", attr
);
8780 #ifdef FEAT_INS_EXPAND
8781 && edit_submode
== NULL
/* otherwise it gets too long */
8785 MSG_PUTS_ATTR(_("recording"), attr
);
8789 mode_displayed
= TRUE
;
8790 if (need_clear
|| clear_cmdline
)
8792 msg_didout
= FALSE
; /* overwrite this message */
8795 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
8797 else if (clear_cmdline
&& msg_silent
== 0)
8798 /* Clear the whole command line. Will reset "clear_cmdline". */
8801 #ifdef FEAT_CMDL_INFO
8803 /* In Visual mode the size of the selected area must be redrawn. */
8808 /* If the last window has no status line, the ruler is after the mode
8809 * message and must be redrawn */
8811 # ifdef FEAT_WINDOWS
8812 && lastwin
->w_status_height
== 0
8815 win_redr_ruler(lastwin
, TRUE
);
8817 redraw_cmdline
= FALSE
;
8818 clear_cmdline
= FALSE
;
8824 * Position for a mode message.
8834 * Delete mode message. Used when ESC is typed which is expected to end
8835 * Insert mode (but Insert mode didn't end yet!).
8836 * Caller should check "mode_displayed".
8843 * Don't delete it right now, when not redrawing or insided a mapping.
8845 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
8846 redraw_cmdline
= TRUE
; /* delete mode later */
8851 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
8856 #if defined(FEAT_WINDOWS)
8858 * Draw the tab pages line at the top of the Vim window.
8875 int attr_sel
= hl_attr(HLF_TPS
);
8876 int attr_nosel
= hl_attr(HLF_TP
);
8877 int attr_fill
= hl_attr(HLF_TPF
);
8880 int use_sep_chars
= (t_colors
< 8
8886 redraw_tabline
= FALSE
;
8888 #ifdef FEAT_GUI_TABLINE
8889 /* Take care of a GUI tabline. */
8890 if (gui_use_tabline())
8892 gui_update_tabline();
8897 if (tabline_height() < 1)
8900 #if defined(FEAT_STL_OPT)
8902 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
8903 for (scol
= 0; scol
< Columns
; ++scol
)
8904 TabPageIdxs
[scol
] = 0;
8906 /* Use the 'tabline' option if it's set. */
8909 int save_called_emsg
= called_emsg
;
8911 /* Check for an error. If there is one we would loop in redrawing the
8912 * screen. Avoid that by making 'tabline' empty. */
8913 called_emsg
= FALSE
;
8914 win_redr_custom(NULL
, FALSE
);
8916 set_string_option_direct((char_u
*)"tabline", -1,
8917 (char_u
*)"", OPT_FREE
, SID_ERROR
);
8918 called_emsg
|= save_called_emsg
;
8923 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
8926 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
8933 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
8938 if (tp
->tp_topframe
== topframe
)
8940 if (use_sep_chars
&& col
> 0)
8941 screen_putchar('|', 0, col
++, attr
);
8943 if (tp
->tp_topframe
!= topframe
)
8946 screen_putchar(' ', 0, col
++, attr
);
8955 cwp
= tp
->tp_curwin
;
8956 wp
= tp
->tp_firstwin
;
8960 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
8961 if (bufIsChanged(wp
->w_buffer
))
8963 if (modified
|| wincount
> 1)
8967 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
8968 len
= (int)STRLEN(NameBuff
);
8969 if (col
+ len
>= Columns
- 3)
8971 screen_puts_len(NameBuff
, len
, 0, col
,
8972 #if defined(FEAT_SYN_HL)
8973 hl_combine_attr(attr
, hl_attr(HLF_T
))
8981 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
8982 screen_putchar(' ', 0, col
++, attr
);
8985 room
= scol
- col
+ tabwidth
- 1;
8988 /* Get buffer name in NameBuff[] */
8989 get_trans_bufname(cwp
->w_buffer
);
8990 shorten_dir(NameBuff
);
8991 len
= vim_strsize(NameBuff
);
8997 len
-= ptr2cells(p
);
9007 if (len
> Columns
- col
- 1)
9008 len
= Columns
- col
- 1;
9010 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9013 screen_putchar(' ', 0, col
++, attr
);
9015 /* Store the tab page number in TabPageIdxs[], so that
9016 * jump_to_mouse() knows where each one is. */
9019 TabPageIdxs
[scol
++] = tabcount
;
9026 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9028 /* Put an "X" for closing the current tab if there are several. */
9029 if (first_tabpage
->tp_next
!= NULL
)
9031 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9032 TabPageIdxs
[Columns
- 1] = -999;
9036 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9038 redraw_tabline
= FALSE
;
9042 * Get buffer name for "buf" into NameBuff[].
9043 * Takes care of special buffer names and translates special characters.
9046 get_trans_bufname(buf
)
9049 if (buf_spname(buf
) != NULL
)
9050 STRCPY(NameBuff
, buf_spname(buf
));
9052 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9053 trans_characters(NameBuff
, MAXPATHL
);
9057 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9059 * Get the character to use in a status line. Get its attributes in "*attr".
9062 fillchar_status(attr
, is_curwin
)
9069 *attr
= hl_attr(HLF_S
);
9074 *attr
= hl_attr(HLF_SNC
);
9077 /* Use fill when there is highlighting, and highlighting of current
9078 * window differs, or the fillchars differ, or this is not the
9080 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9081 || !is_curwin
|| firstwin
== lastwin
)
9082 || (fill_stl
!= fill_stlnc
)))
9090 #ifdef FEAT_VERTSPLIT
9092 * Get the character to use in a separator between vertically split windows.
9093 * Get its attributes in "*attr".
9099 *attr
= hl_attr(HLF_C
);
9100 if (*attr
== 0 && fill_vert
== ' ')
9108 * Return TRUE if redrawing should currently be done.
9113 return (!RedrawingDisabled
9114 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9118 * Return TRUE if printing messages should currently be done.
9123 return (!(p_lz
&& char_avail() && !KeyTyped
));
9127 * Show current status info in ruler and various other places
9128 * If always is FALSE, only show ruler if position has changed.
9134 if (!always
&& !redrawing())
9136 #ifdef FEAT_INS_EXPAND
9139 # ifdef FEAT_WINDOWS
9140 /* Don't redraw right now, do it later. */
9141 curwin
->w_redr_status
= TRUE
;
9146 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9147 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9149 redraw_custum_statusline(curwin
);
9153 #ifdef FEAT_CMDL_INFO
9154 win_redr_ruler(curwin
, always
);
9159 # ifdef FEAT_STL_OPT
9160 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9161 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9168 #ifdef FEAT_CMDL_INFO
9170 win_redr_ruler(wp
, always
)
9178 int empty_line
= FALSE
;
9182 #ifdef FEAT_VERTSPLIT
9185 int width
= Columns
;
9186 # define WITH_OFF(x) x
9187 # define WITH_WIDTH(x) x
9189 # define WITH_OFF(x) 0
9190 # define WITH_WIDTH(x) Columns
9191 # define this_ru_col ru_col
9194 /* If 'ruler' off or redrawing disabled, don't do anything */
9199 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9200 * after deleting lines, before cursor.lnum is corrected.
9202 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9205 #ifdef FEAT_INS_EXPAND
9206 /* Don't draw the ruler while doing insert-completion, it might overwrite
9207 * the (long) mode message. */
9208 # ifdef FEAT_WINDOWS
9209 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9211 if (edit_submode
!= NULL
)
9213 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9221 int save_called_emsg
= called_emsg
;
9223 called_emsg
= FALSE
;
9224 win_redr_custom(wp
, TRUE
);
9226 set_string_option_direct((char_u
*)"rulerformat", -1,
9227 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9228 called_emsg
|= save_called_emsg
;
9234 * Check if not in Insert mode and the line is empty (will show "0-1").
9236 if (!(State
& INSERT
)
9237 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9241 * Only draw the ruler when something changed.
9243 validate_virtcol_win(wp
);
9246 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9247 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9248 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9249 #ifdef FEAT_VIRTUALEDIT
9250 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9252 || wp
->w_topline
!= wp
->w_ru_topline
9253 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9255 || wp
->w_topfill
!= wp
->w_ru_topfill
9257 || empty_line
!= wp
->w_ru_empty
)
9261 if (wp
->w_status_height
)
9263 row
= W_WINROW(wp
) + wp
->w_height
;
9264 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9265 # ifdef FEAT_VERTSPLIT
9267 width
= W_WIDTH(wp
);
9276 #ifdef FEAT_VERTSPLIT
9282 /* In list mode virtcol needs to be recomputed */
9283 virtcol
= wp
->w_virtcol
;
9284 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9286 wp
->w_p_list
= FALSE
;
9287 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9288 wp
->w_p_list
= TRUE
;
9292 * Some sprintfs return the length, some return a pointer.
9293 * To avoid portability problems we use strlen() here.
9295 sprintf((char *)buffer
, "%ld,",
9296 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9298 : (long)(wp
->w_cursor
.lnum
));
9299 col_print(buffer
+ STRLEN(buffer
),
9300 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9304 * Add a "50%" if there is room for it.
9305 * On the last line, don't print in the last column (scrolls the
9306 * screen up on some terminals).
9308 i
= (int)STRLEN(buffer
);
9309 get_rel_pos(wp
, buffer
+ i
+ 1);
9310 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9312 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9315 #ifdef FEAT_VERTSPLIT
9316 this_ru_col
= ru_col
- (Columns
- width
);
9317 if (this_ru_col
< 0)
9320 /* Never use more than half the window/screen width, leave the other
9321 * half for the filename. */
9322 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9323 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9324 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9326 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9330 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9333 buffer
[i
++] = fillchar
;
9336 get_rel_pos(wp
, buffer
+ i
);
9338 /* Truncate at window boundary. */
9343 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9345 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9346 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9355 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9356 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9358 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9360 screen_fill(row
, row
+ 1,
9361 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9362 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9363 fillchar
, fillchar
, attr
);
9364 /* don't redraw the cmdline because of showing the ruler */
9366 wp
->w_ru_cursor
= wp
->w_cursor
;
9367 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9368 wp
->w_ru_empty
= empty_line
;
9369 wp
->w_ru_topline
= wp
->w_topline
;
9370 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9372 wp
->w_ru_topfill
= wp
->w_topfill
;
9378 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9380 * Return the width of the 'number' column.
9381 * Caller may need to check if 'number' is set.
9382 * Otherwise it depends on 'numberwidth' and the line count.
9391 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9392 if (lnum
== wp
->w_nrwidth_line_count
)
9393 return wp
->w_nrwidth_width
;
9394 wp
->w_nrwidth_line_count
= lnum
;
9403 /* 'numberwidth' gives the minimal width plus one */
9404 if (n
< wp
->w_p_nuw
- 1)
9405 n
= wp
->w_p_nuw
- 1;
9407 wp
->w_nrwidth_width
= n
;