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
)
1236 /* Not VALID or INVERTED: redraw all lines. */
1238 mid_end
= wp
->w_height
;
1241 if (type
== SOME_VALID
)
1243 /* SOME_VALID: redraw all lines. */
1245 mid_end
= wp
->w_height
;
1250 /* check if we are updating or removing the inverted part */
1251 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1252 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1259 && (VIsual_mode
!= wp
->w_old_visual_mode
1260 || type
== INVERTED_ALL
))
1263 * If the type of Visual selection changed, redraw the whole
1264 * selection. Also when the ownership of the X selection is
1267 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1269 from
= curwin
->w_cursor
.lnum
;
1275 to
= curwin
->w_cursor
.lnum
;
1277 /* redraw more when the cursor moved as well */
1278 if (wp
->w_old_cursor_lnum
< from
)
1279 from
= wp
->w_old_cursor_lnum
;
1280 if (wp
->w_old_cursor_lnum
> to
)
1281 to
= wp
->w_old_cursor_lnum
;
1282 if (wp
->w_old_visual_lnum
< from
)
1283 from
= wp
->w_old_visual_lnum
;
1284 if (wp
->w_old_visual_lnum
> to
)
1285 to
= wp
->w_old_visual_lnum
;
1290 * Find the line numbers that need to be updated: The lines
1291 * between the old cursor position and the current cursor
1292 * position. Also check if the Visual position changed.
1294 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1296 from
= curwin
->w_cursor
.lnum
;
1297 to
= wp
->w_old_cursor_lnum
;
1301 from
= wp
->w_old_cursor_lnum
;
1302 to
= curwin
->w_cursor
.lnum
;
1303 if (from
== 0) /* Visual mode just started */
1307 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1308 || VIsual
.col
!= wp
->w_old_visual_col
)
1310 if (wp
->w_old_visual_lnum
< from
1311 && wp
->w_old_visual_lnum
!= 0)
1312 from
= wp
->w_old_visual_lnum
;
1313 if (wp
->w_old_visual_lnum
> to
)
1314 to
= wp
->w_old_visual_lnum
;
1315 if (VIsual
.lnum
< from
)
1317 if (VIsual
.lnum
> to
)
1323 * If in block mode and changed column or curwin->w_curswant:
1325 * First compute the actual start and end column.
1327 if (VIsual_mode
== Ctrl_V
)
1331 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1333 if (curwin
->w_curswant
== MAXCOL
)
1336 if (fromc
!= wp
->w_old_cursor_fcol
1337 || toc
!= wp
->w_old_cursor_lcol
)
1339 if (from
> VIsual
.lnum
)
1341 if (to
< VIsual
.lnum
)
1344 wp
->w_old_cursor_fcol
= fromc
;
1345 wp
->w_old_cursor_lcol
= toc
;
1350 /* Use the line numbers of the old Visual area. */
1351 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1353 from
= wp
->w_old_cursor_lnum
;
1354 to
= wp
->w_old_visual_lnum
;
1358 from
= wp
->w_old_visual_lnum
;
1359 to
= wp
->w_old_cursor_lnum
;
1364 * There is no need to update lines above the top of the window.
1366 if (from
< wp
->w_topline
)
1367 from
= wp
->w_topline
;
1370 * If we know the value of w_botline, use it to restrict the update to
1371 * the lines that are visible in the window.
1373 if (wp
->w_valid
& VALID_BOTLINE
)
1375 if (from
>= wp
->w_botline
)
1376 from
= wp
->w_botline
- 1;
1377 if (to
>= wp
->w_botline
)
1378 to
= wp
->w_botline
- 1;
1382 * Find the minimal part to be updated.
1383 * Watch out for scrolling that made entries in w_lines[] invalid.
1384 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1385 * top_end; need to redraw from top_end to the "to" line.
1386 * A middle mouse click with a Visual selection may change the text
1387 * above the Visual area and reset wl_valid, do count these for
1388 * mid_end (in srow).
1392 lnum
= wp
->w_topline
;
1396 mid_start
= top_end
;
1399 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1401 if (wp
->w_lines
[idx
].wl_valid
)
1402 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1403 else if (!scrolled_down
)
1404 srow
+= wp
->w_lines
[idx
].wl_size
;
1406 # ifdef FEAT_FOLDING
1407 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1408 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1414 mid_end
= wp
->w_height
;
1415 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1417 if (wp
->w_lines
[idx
].wl_valid
1418 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1420 /* Only update until first row of this line */
1424 srow
+= wp
->w_lines
[idx
].wl_size
;
1429 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1431 wp
->w_old_visual_mode
= VIsual_mode
;
1432 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1433 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1434 wp
->w_old_visual_col
= VIsual
.col
;
1435 wp
->w_old_curswant
= curwin
->w_curswant
;
1439 wp
->w_old_visual_mode
= 0;
1440 wp
->w_old_cursor_lnum
= 0;
1441 wp
->w_old_visual_lnum
= 0;
1442 wp
->w_old_visual_col
= 0;
1444 #endif /* FEAT_VISUAL */
1446 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1447 /* reset got_int, otherwise regexp won't work */
1448 save_got_int
= got_int
;
1452 win_foldinfo
.fi_level
= 0;
1456 * Update all the window rows.
1458 idx
= 0; /* first entry in w_lines[].wl_size */
1461 lnum
= wp
->w_topline
; /* first line shown in window */
1464 /* stop updating when reached the end of the window (check for _past_
1465 * the end of the window is at the end of the loop) */
1466 if (row
== wp
->w_height
)
1472 /* stop updating when hit the end of the file */
1473 if (lnum
> buf
->b_ml
.ml_line_count
)
1479 /* Remember the starting row of the line that is going to be dealt
1480 * with. It is used further down when the line doesn't fit. */
1484 * Update a line when it is in an area that needs updating, when it
1485 * has changes or w_lines[idx] is invalid.
1486 * bot_start may be halfway a wrapped line after using
1487 * win_del_lines(), check if the current line includes it.
1488 * When syntax folding is being used, the saved syntax states will
1489 * already have been updated, we can't see where the syntax state is
1490 * the same again, just update until the end of the window.
1493 || (row
>= mid_start
&& row
< mid_end
)
1494 #ifdef FEAT_SEARCH_EXTRA
1497 || idx
>= wp
->w_lines_valid
1498 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1504 || did_update
== DID_FOLD
1505 || (did_update
== DID_LINE
1506 && syntax_present(buf
)
1508 # ifdef FEAT_FOLDING
1509 (foldmethodIsSyntax(wp
)
1510 && hasAnyFolding(wp
)) ||
1512 syntax_check_changed(lnum
)))
1516 #ifdef FEAT_SEARCH_EXTRA
1517 if (lnum
== mod_top
)
1522 * When at start of changed lines: May scroll following lines
1523 * up or down to minimize redrawing.
1524 * Don't do this when the change continues until the end.
1525 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1528 && mod_bot
!= MAXLNUM
1529 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1536 /* Count the old number of window rows, using w_lines[], which
1537 * should still contain the sizes for the lines as they are
1538 * currently displayed. */
1539 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1541 /* Only valid lines have a meaningful wl_lnum. Invalid
1542 * lines are part of the changed area. */
1543 if (wp
->w_lines
[i
].wl_valid
1544 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1546 old_rows
+= wp
->w_lines
[i
].wl_size
;
1548 if (wp
->w_lines
[i
].wl_valid
1549 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1551 /* Must have found the last valid entry above mod_bot.
1552 * Add following invalid entries. */
1554 while (i
< wp
->w_lines_valid
1555 && !wp
->w_lines
[i
].wl_valid
)
1556 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1562 if (i
>= wp
->w_lines_valid
)
1564 /* We can't find a valid line below the changed lines,
1565 * need to redraw until the end of the window.
1566 * Inserting/deleting lines has no use. */
1571 /* Able to count old number of rows: Count new window
1572 * rows, and may insert/delete lines */
1574 for (l
= lnum
; l
< mod_bot
; ++l
)
1577 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1582 if (l
== wp
->w_topline
)
1583 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1587 new_rows
+= plines_win(wp
, l
, TRUE
);
1589 if (new_rows
> wp
->w_height
- row
- 2)
1591 /* it's getting too much, must redraw the rest */
1596 xtra_rows
= new_rows
- old_rows
;
1599 /* May scroll text up. If there is not enough
1600 * remaining text or scrolling fails, must redraw the
1601 * rest. If scrolling works, must redraw the text
1602 * below the scrolled text. */
1603 if (row
- xtra_rows
>= wp
->w_height
- 2)
1607 check_for_delay(FALSE
);
1608 if (win_del_lines(wp
, row
,
1609 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1612 bot_start
= wp
->w_height
+ xtra_rows
;
1615 else if (xtra_rows
> 0)
1617 /* May scroll text down. If there is not enough
1618 * remaining text of scrolling fails, must redraw the
1620 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1624 check_for_delay(FALSE
);
1625 if (win_ins_lines(wp
, row
+ old_rows
,
1626 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1628 else if (top_end
> row
+ old_rows
)
1629 /* Scrolled the part at the top that requires
1631 top_end
+= xtra_rows
;
1635 /* When not updating the rest, may need to move w_lines[]
1637 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1641 int x
= row
+ new_rows
;
1643 /* move entries in w_lines[] upwards */
1646 /* stop at last valid entry in w_lines[] */
1647 if (i
>= wp
->w_lines_valid
)
1649 wp
->w_lines_valid
= j
;
1652 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1653 /* stop at a line that won't fit */
1654 if (x
+ (int)wp
->w_lines
[j
].wl_size
1657 wp
->w_lines_valid
= j
+ 1;
1660 x
+= wp
->w_lines
[j
++].wl_size
;
1668 /* move entries in w_lines[] downwards */
1670 wp
->w_lines_valid
+= j
;
1671 if (wp
->w_lines_valid
> wp
->w_height
)
1672 wp
->w_lines_valid
= wp
->w_height
;
1673 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1674 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1676 /* The w_lines[] entries for inserted lines are
1677 * now invalid, but wl_size may be used above.
1681 wp
->w_lines
[i
].wl_size
= 0;
1682 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1691 * When lines are folded, display one line for all of them.
1692 * Otherwise, display normally (can be several display lines when
1695 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1696 if (fold_count
!= 0)
1698 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1701 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1702 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1704 did_update
= DID_FOLD
;
1709 if (idx
< wp
->w_lines_valid
1710 && wp
->w_lines
[idx
].wl_valid
1711 && wp
->w_lines
[idx
].wl_lnum
== lnum
1712 && lnum
> wp
->w_topline
1713 && !(dy_flags
& DY_LASTLINE
)
1714 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1716 && diff_check_fill(wp
, lnum
) == 0
1720 /* This line is not going to fit. Don't draw anything here,
1721 * will draw "@ " lines below. */
1722 row
= wp
->w_height
+ 1;
1726 #ifdef FEAT_SEARCH_EXTRA
1727 prepare_search_hl(wp
, lnum
);
1730 /* Let the syntax stuff know we skipped a few lines. */
1731 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1732 && syntax_present(buf
))
1733 syntax_end_parsing(syntax_last_parsed
+ 1);
1739 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1742 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1743 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1746 did_update
= DID_LINE
;
1747 syntax_last_parsed
= lnum
;
1751 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1752 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1753 if (row
> wp
->w_height
) /* past end of screen */
1755 /* we may need the size of that too long line later on */
1756 if (dollar_vcol
== 0)
1757 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1761 if (dollar_vcol
== 0)
1762 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1765 lnum
+= fold_count
+ 1;
1772 /* This line does not need updating, advance to the next one */
1773 row
+= wp
->w_lines
[idx
++].wl_size
;
1774 if (row
> wp
->w_height
) /* past end of screen */
1777 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1782 did_update
= DID_NONE
;
1786 if (lnum
> buf
->b_ml
.ml_line_count
)
1793 * End of loop over all window lines.
1797 if (idx
> wp
->w_lines_valid
)
1798 wp
->w_lines_valid
= idx
;
1802 * Let the syntax stuff know we stop parsing here.
1804 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1805 syntax_end_parsing(syntax_last_parsed
+ 1);
1809 * If we didn't hit the end of the file, and we didn't finish the last
1810 * line we were working on, then the line didn't fit.
1812 wp
->w_empty_rows
= 0;
1814 wp
->w_filler_rows
= 0;
1816 if (!eof
&& !didline
)
1818 if (lnum
== wp
->w_topline
)
1821 * Single line that does not fit!
1822 * Don't overwrite it, it can be edited.
1824 wp
->w_botline
= lnum
+ 1;
1827 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1829 /* Window ends in filler lines. */
1830 wp
->w_botline
= lnum
;
1831 wp
->w_filler_rows
= wp
->w_height
- srow
;
1834 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1837 * Last line isn't finished: Display "@@@" at the end.
1839 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1840 W_WINROW(wp
) + wp
->w_height
,
1841 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1842 '@', '@', hl_attr(HLF_AT
));
1843 set_empty_rows(wp
, srow
);
1844 wp
->w_botline
= lnum
;
1848 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1849 wp
->w_botline
= lnum
;
1854 #ifdef FEAT_VERTSPLIT
1855 draw_vsep_win(wp
, row
);
1857 if (eof
) /* we hit the end of the file */
1859 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1861 j
= diff_check_fill(wp
, wp
->w_botline
);
1862 if (j
> 0 && !wp
->w_botfill
)
1865 * Display filler lines at the end of the file
1867 if (char2cells(fill_diff
) > 1)
1871 if (row
+ j
> wp
->w_height
)
1872 j
= wp
->w_height
- row
;
1873 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1878 else if (dollar_vcol
== 0)
1879 wp
->w_botline
= lnum
;
1881 /* make sure the rest of the screen is blank */
1882 /* put '~'s on rows that aren't part of the file. */
1883 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1886 /* Reset the type of redrawing required, the window has been updated. */
1887 wp
->w_redr_type
= 0;
1889 wp
->w_old_topfill
= wp
->w_topfill
;
1890 wp
->w_old_botfill
= wp
->w_botfill
;
1893 if (dollar_vcol
== 0)
1896 * There is a trick with w_botline. If we invalidate it on each
1897 * change that might modify it, this will cause a lot of expensive
1898 * calls to plines() in update_topline() each time. Therefore the
1899 * value of w_botline is often approximated, and this value is used to
1900 * compute the value of w_topline. If the value of w_botline was
1901 * wrong, check that the value of w_topline is correct (cursor is on
1902 * the visible part of the text). If it's not, we need to redraw
1903 * again. Mostly this just means scrolling up a few lines, so it
1904 * doesn't look too bad. Only do this for the current window (where
1905 * changes are relevant).
1907 wp
->w_valid
|= VALID_BOTLINE
;
1908 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1911 curwin
->w_valid
&= ~VALID_TOPLINE
;
1912 update_topline(); /* may invalidate w_botline again */
1913 if (must_redraw
!= 0)
1915 /* Don't update for changes in buffer again. */
1916 i
= curbuf
->b_mod_set
;
1917 curbuf
->b_mod_set
= FALSE
;
1920 curbuf
->b_mod_set
= i
;
1926 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1927 /* restore got_int, unless CTRL-C was hit while redrawing */
1929 got_int
= save_got_int
;
1934 static int draw_signcolumn
__ARGS((win_T
*wp
));
1937 * Return TRUE when window "wp" has a column to draw signs in.
1943 return (wp
->w_buffer
->b_signlist
!= NULL
1944 # ifdef FEAT_NETBEANS_INTG
1952 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1953 * as the filler character.
1956 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
1964 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
1971 #ifdef FEAT_RIGHTLEFT
1974 /* No check for cmdline window: should never be right-left. */
1975 # ifdef FEAT_FOLDING
1980 /* draw the fold column at the right */
1981 if (n
> W_WIDTH(wp
))
1983 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
1984 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
1985 ' ', ' ', hl_attr(HLF_FC
));
1989 if (draw_signcolumn(wp
))
1993 /* draw the sign column left of the fold column */
1994 if (nn
> W_WIDTH(wp
))
1996 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
1997 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
1998 ' ', ' ', hl_attr(HLF_SC
));
2002 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2003 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2004 c2
, c2
, hl_attr(hl
));
2005 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2006 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2007 c1
, c2
, hl_attr(hl
));
2013 if (cmdwin_type
!= 0 && wp
== curwin
)
2015 /* draw the cmdline character in the leftmost column */
2017 if (n
> wp
->w_width
)
2019 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2020 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2021 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2025 if (wp
->w_p_fdc
> 0)
2027 int nn
= n
+ wp
->w_p_fdc
;
2029 /* draw the fold column at the left */
2030 if (nn
> W_WIDTH(wp
))
2032 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2033 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2034 ' ', ' ', hl_attr(HLF_FC
));
2039 if (draw_signcolumn(wp
))
2043 /* draw the sign column after the fold column */
2044 if (nn
> W_WIDTH(wp
))
2046 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2047 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2048 ' ', ' ', hl_attr(HLF_SC
));
2052 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2053 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2054 c1
, c2
, hl_attr(hl
));
2056 set_empty_rows(wp
, row
);
2061 * Display one folded line.
2064 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2067 foldinfo_T
*foldinfo
;
2073 linenr_T lnume
= lnum
+ fold_count
- 1;
2079 int off
= (int)(current_ScreenLine
- ScreenLines
);
2082 /* Build the fold line:
2083 * 1. Add the cmdwin_type for the command-line window
2084 * 2. Add the 'foldcolumn'
2085 * 3. Add the 'number' column
2086 * 4. Compose the text
2088 * 6. set highlighting for the Visual area an other text
2093 * 1. Add the cmdwin_type for the command-line window
2094 * Ignores 'rightleft', this window is never right-left.
2097 if (cmdwin_type
!= 0 && wp
== curwin
)
2099 ScreenLines
[off
] = cmdwin_type
;
2100 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2103 ScreenLinesUC
[off
] = 0;
2110 * 2. Add the 'foldcolumn'
2113 if (fdc
> W_WIDTH(wp
) - col
)
2114 fdc
= W_WIDTH(wp
) - col
;
2117 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2118 #ifdef FEAT_RIGHTLEFT
2123 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2125 /* reverse the fold column */
2126 for (i
= 0; i
< fdc
; ++i
)
2127 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2131 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2135 #ifdef FEAT_RIGHTLEFT
2136 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2137 for (ri = 0; ri < l; ++ri) \
2138 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2140 for (ri = 0; ri < l; ++ri) \
2141 ScreenAttrs[off + (p) + ri] = v
2143 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2144 ScreenAttrs[off + (p) + ri] = v
2147 /* Set all attributes of the 'number' column and the text */
2148 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2151 /* If signs are being displayed, add two spaces. */
2152 if (draw_signcolumn(wp
))
2154 len
= W_WIDTH(wp
) - col
;
2159 # ifdef FEAT_RIGHTLEFT
2161 /* the line number isn't reversed */
2162 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2163 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2166 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2173 * 3. Add the 'number' column
2177 len
= W_WIDTH(wp
) - col
;
2180 int w
= number_width(wp
);
2184 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2185 #ifdef FEAT_RIGHTLEFT
2187 /* the line number isn't reversed */
2188 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2192 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2198 * 4. Compose the folded-line string with 'foldtext', if set.
2200 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2202 txtcol
= col
; /* remember where text starts */
2205 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2206 * Right-left text is put in columns 0 - number-col, normal text is put
2207 * in columns number-col - window-width.
2213 int u8c
, u8cc
[MAX_MCO
];
2219 int prev_c
= 0; /* previous Arabic character */
2220 int prev_c1
= 0; /* first composing char for prev_c */
2223 # ifdef FEAT_RIGHTLEFT
2230 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2231 for (p
= text
; *p
!= NUL
; )
2233 cells
= (*mb_ptr2cells
)(p
);
2234 c_len
= (*mb_ptr2len
)(p
);
2235 if (col
+ cells
> W_WIDTH(wp
)
2236 # ifdef FEAT_RIGHTLEFT
2237 - (wp
->w_p_rl
? col
: 0)
2241 ScreenLines
[idx
] = *p
;
2244 u8c
= utfc_ptr2char(p
, u8cc
);
2245 if (*p
< 0x80 && u8cc
[0] == 0)
2247 ScreenLinesUC
[idx
] = 0;
2255 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2257 /* Do Arabic shaping. */
2262 /* The idea of what is the previous and next
2263 * character depends on 'rightleft'. */
2268 nc
= utf_ptr2char(p
+ c_len
);
2273 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2279 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2281 ScreenLines
[idx
] = firstbyte
;
2286 /* Non-BMP character: display as ? or fullwidth ?. */
2288 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2290 ScreenLinesUC
[idx
] = u8c
;
2291 for (i
= 0; i
< Screen_mco
; ++i
)
2293 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2299 ScreenLines
[idx
+ 1] = 0;
2301 else if (cells
> 1) /* double-byte character */
2303 if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2304 ScreenLines2
[idx
] = p
[1];
2306 ScreenLines
[idx
+ 1] = p
[1];
2316 len
= (int)STRLEN(text
);
2317 if (len
> W_WIDTH(wp
) - col
)
2318 len
= W_WIDTH(wp
) - col
;
2321 #ifdef FEAT_RIGHTLEFT
2323 STRNCPY(current_ScreenLine
, text
, len
);
2326 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2331 /* Fill the rest of the line with the fold filler */
2332 #ifdef FEAT_RIGHTLEFT
2336 while (col
< W_WIDTH(wp
)
2337 #ifdef FEAT_RIGHTLEFT
2338 - (wp
->w_p_rl
? txtcol
: 0)
2345 if (fill_fold
>= 0x80)
2347 ScreenLinesUC
[off
+ col
] = fill_fold
;
2348 ScreenLinesC
[0][off
+ col
] = 0;
2351 ScreenLinesUC
[off
+ col
] = 0;
2354 ScreenLines
[off
+ col
++] = fill_fold
;
2361 * 6. set highlighting for the Visual area an other text.
2362 * If all folded lines are in the Visual area, highlight the line.
2365 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2367 if (ltoreq(curwin
->w_cursor
, VIsual
))
2369 /* Visual is after curwin->w_cursor */
2370 top
= &curwin
->w_cursor
;
2375 /* Visual is before curwin->w_cursor */
2377 bot
= &curwin
->w_cursor
;
2379 if (lnum
>= top
->lnum
2380 && lnume
<= bot
->lnum
2381 && (VIsual_mode
!= 'v'
2382 || ((lnum
> top
->lnum
2383 || (lnum
== top
->lnum
2385 && (lnume
< bot
->lnum
2386 || (lnume
== bot
->lnum
2387 && (bot
->col
- (*p_sel
== 'e'))
2388 >= STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2390 if (VIsual_mode
== Ctrl_V
)
2392 /* Visual block mode: highlight the chars part of the block */
2393 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2395 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2396 len
= wp
->w_old_cursor_lcol
;
2398 len
= W_WIDTH(wp
) - txtcol
;
2399 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2400 len
- (int)wp
->w_old_cursor_fcol
);
2405 /* Set all attributes of the text */
2406 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2413 /* Show 'cursorcolumn' in the fold line. */
2414 if (wp
->w_p_cuc
&& (int)wp
->w_virtcol
+ txtcol
< W_WIDTH(wp
))
2415 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
] = hl_combine_attr(
2416 ScreenAttrs
[off
+ wp
->w_virtcol
+ txtcol
], hl_attr(HLF_CUC
));
2419 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2420 (int)W_WIDTH(wp
), FALSE
);
2423 * Update w_cline_height and w_cline_folded if the cursor line was
2424 * updated (saves a call to plines() later).
2427 && lnum
<= curwin
->w_cursor
.lnum
2428 && lnume
>= curwin
->w_cursor
.lnum
)
2430 curwin
->w_cline_row
= row
;
2431 curwin
->w_cline_height
= 1;
2432 curwin
->w_cline_folded
= TRUE
;
2433 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2438 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2441 copy_text_attr(off
, buf
, len
, attr
)
2449 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2452 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2454 for (i
= 0; i
< len
; ++i
)
2455 ScreenAttrs
[off
+ i
] = attr
;
2459 * Fill the foldcolumn at "p" for window "wp".
2460 * Only to be called when 'foldcolumn' > 0.
2463 fill_foldcolumn(p
, wp
, closed
, lnum
)
2466 int closed
; /* TRUE of FALSE */
2467 linenr_T lnum
; /* current line number */
2474 /* Init to all spaces. */
2475 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2477 level
= win_foldinfo
.fi_level
;
2480 /* If there is only one column put more info in it. */
2481 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2483 /* If the column is too narrow, we start at the lowest level that
2484 * fits and use numbers to indicated the depth. */
2485 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2486 if (first_level
< 1)
2489 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2491 if (win_foldinfo
.fi_lnum
== lnum
2492 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2494 else if (first_level
== 1)
2496 else if (first_level
+ i
<= 9)
2497 p
[i
] = '0' + first_level
+ i
;
2500 if (first_level
+ i
== level
)
2505 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2507 #endif /* FEAT_FOLDING */
2510 * Display line "lnum" of window 'wp' on the screen.
2511 * Start at row "startrow", stop when "endrow" is reached.
2512 * wp->w_virtcol needs to be valid.
2514 * Return the number of last row the line occupies.
2518 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2523 int nochange
; /* not updating for changed text */
2525 int col
; /* visual column on screen */
2526 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2527 int c
= 0; /* init for GCC */
2528 long vcol
= 0; /* virtual column (for tabs) */
2529 long vcol_prev
= -1; /* "vcol" of previous character */
2530 char_u
*line
; /* current line */
2531 char_u
*ptr
; /* current position in "line" */
2532 int row
; /* row in the window, excl w_winrow */
2533 int screen_row
; /* row on the screen, incl w_winrow */
2535 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2536 int n_extra
= 0; /* number of extra chars */
2537 char_u
*p_extra
= NULL
; /* string of extra chars */
2538 int c_extra
= NUL
; /* extra chars, all the same */
2539 int extra_attr
= 0; /* attributes when n_extra != 0 */
2540 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2541 displaying lcs_eol at end-of-line */
2542 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2543 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2545 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2546 int saved_n_extra
= 0;
2547 char_u
*saved_p_extra
= NULL
;
2548 int saved_c_extra
= 0;
2549 int saved_char_attr
= 0;
2551 int n_attr
= 0; /* chars with special attr */
2552 int saved_attr2
= 0; /* char_attr saved for n_attr */
2553 int n_attr3
= 0; /* chars with overruling special attr */
2554 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2556 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2558 int fromcol
, tocol
; /* start/end of inverting */
2559 int fromcol_prev
= -2; /* start of inverting after cursor */
2560 int noinvcur
= FALSE
; /* don't invert the cursor */
2567 int char_attr
= 0; /* attributes for next character */
2568 int attr_pri
= FALSE
; /* char_attr has priority */
2569 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2571 int attr
= 0; /* attributes for area highlighting */
2572 int area_attr
= 0; /* attributes desired by highlighting */
2573 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2575 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2576 int syntax_attr
= 0; /* attributes desired by syntax */
2577 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2581 int has_spell
= FALSE
; /* this buffer has spell checking */
2582 # define SPWORDLEN 150
2583 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2584 int nextlinecol
= 0; /* column where nextline[] starts */
2585 int nextline_idx
= 0; /* index in nextline[] where next line
2587 int spell_attr
= 0; /* attributes desired by spelling */
2588 int word_end
= 0; /* last byte with same spell_attr */
2589 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2590 static int checked_col
= 0; /* column in "checked_lnum" up to which
2591 * there are no spell errors */
2592 static int cap_col
= -1; /* column to check for Cap word */
2593 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2594 int cur_checked_col
= 0; /* checked column for current line */
2596 int extra_check
; /* has syntax or linebreak */
2598 int multi_attr
= 0; /* attributes desired by multibyte */
2599 int mb_l
= 1; /* multi-byte byte length */
2600 int mb_c
= 0; /* decoded multi-byte character */
2601 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2602 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2605 int filler_lines
; /* nr of filler lines to be drawn */
2606 int filler_todo
; /* nr of filler lines still to do + 1 */
2607 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2608 int change_start
= MAXCOL
; /* first col of changed area */
2609 int change_end
= -1; /* last col of changed area */
2611 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2612 #ifdef FEAT_LINEBREAK
2613 int need_showbreak
= FALSE
;
2615 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2616 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2618 int line_attr
= 0; /* atrribute for the whole line */
2620 #ifdef FEAT_SEARCH_EXTRA
2621 match_T
*shl
; /* points to search_hl or match_hl */
2623 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_MBYTE)
2627 int prev_c
= 0; /* previous Arabic character */
2628 int prev_c1
= 0; /* first composing char for prev_c */
2630 #if defined(LINE_ATTR)
2631 int did_line_attr
= 0;
2634 /* draw_state: items that are drawn in sequence: */
2635 #define WL_START 0 /* nothing done yet */
2637 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2639 # define WL_CMDLINE WL_START
2642 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2644 # define WL_FOLD WL_CMDLINE
2647 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2649 # define WL_SIGN WL_FOLD /* column for signs */
2651 #define WL_NR WL_SIGN + 1 /* line number */
2652 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2653 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2655 # define WL_SBR WL_NR
2657 #define WL_LINE WL_SBR + 1 /* text in the line */
2658 int draw_state
= WL_START
; /* what to draw next */
2659 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2660 int feedback_col
= 0;
2661 int feedback_old_attr
= -1;
2665 if (startrow
> endrow
) /* past the end already! */
2669 screen_row
= row
+ W_WINROW(wp
);
2672 * To speed up the loop below, set extra_check when there is linebreak,
2673 * trailing white space and/or syntax processing to be done.
2675 #ifdef FEAT_LINEBREAK
2676 extra_check
= wp
->w_p_lbr
;
2681 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2683 /* Prepare for syntax highlighting in this line. When there is an
2684 * error, stop syntax highlighting. */
2685 save_did_emsg
= did_emsg
;
2687 syntax_start(wp
, lnum
);
2689 wp
->w_buffer
->b_syn_error
= TRUE
;
2692 did_emsg
= save_did_emsg
;
2701 && *wp
->w_buffer
->b_p_spl
!= NUL
2702 && wp
->w_buffer
->b_langp
.ga_len
> 0
2703 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2705 /* Prepare for spell checking. */
2709 /* Get the start of the next line, so that words that wrap to the next
2710 * line are found too: "et<line-break>al.".
2711 * Trick: skip a few chars for C/shell/Vim comments */
2712 nextline
[SPWORDLEN
] = NUL
;
2713 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2715 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2716 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2719 /* When a word wrapped from the previous line the start of the current
2721 if (lnum
== checked_lnum
)
2722 cur_checked_col
= checked_col
;
2725 /* When there was a sentence end in the previous line may require a
2726 * word starting with capital in this line. In line 1 always check
2727 * the first word. */
2728 if (lnum
!= capcol_lnum
)
2737 * handle visual active in this window
2742 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2744 /* Visual is after curwin->w_cursor */
2745 if (ltoreq(curwin
->w_cursor
, VIsual
))
2747 top
= &curwin
->w_cursor
;
2750 else /* Visual is before curwin->w_cursor */
2753 bot
= &curwin
->w_cursor
;
2755 if (VIsual_mode
== Ctrl_V
) /* block mode */
2757 if (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
)
2759 fromcol
= wp
->w_old_cursor_fcol
;
2760 tocol
= wp
->w_old_cursor_lcol
;
2763 else /* non-block mode */
2765 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2767 else if (lnum
== top
->lnum
)
2769 if (VIsual_mode
== 'V') /* linewise */
2773 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2774 if (gchar_pos(top
) == NUL
)
2775 tocol
= fromcol
+ 1;
2778 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2780 if (*p_sel
== 'e' && bot
->col
== 0
2781 #ifdef FEAT_VIRTUALEDIT
2789 else if (bot
->col
== MAXCOL
)
2795 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2798 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2806 /* Check if the character under the cursor should not be inverted */
2807 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2815 /* if inverting in this line set area_highlighting */
2818 area_highlighting
= TRUE
;
2819 attr
= hl_attr(HLF_V
);
2820 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2821 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2822 attr
= hl_attr(HLF_VNC
);
2828 * handle 'incsearch' and ":s///c" highlighting
2831 #endif /* FEAT_VISUAL */
2834 && lnum
>= curwin
->w_cursor
.lnum
2835 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2837 if (lnum
== curwin
->w_cursor
.lnum
)
2838 getvcol(curwin
, &(curwin
->w_cursor
),
2839 (colnr_T
*)&fromcol
, NULL
, NULL
);
2842 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2845 pos
.col
= search_match_endcol
;
2846 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2850 if (fromcol
== tocol
) /* do at least one character */
2851 tocol
= fromcol
+ 1; /* happens when past end of line */
2852 area_highlighting
= TRUE
;
2853 attr
= hl_attr(HLF_I
);
2857 filler_lines
= diff_check(wp
, lnum
);
2858 if (filler_lines
< 0)
2860 if (filler_lines
== -1)
2862 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2863 diff_hlf
= HLF_ADD
; /* added line */
2864 else if (change_start
== 0)
2865 diff_hlf
= HLF_TXD
; /* changed text */
2867 diff_hlf
= HLF_CHD
; /* changed line */
2870 diff_hlf
= HLF_ADD
; /* added line */
2872 area_highlighting
= TRUE
;
2874 if (lnum
== wp
->w_topline
)
2875 filler_lines
= wp
->w_topfill
;
2876 filler_todo
= filler_lines
;
2881 /* If this line has a sign with line highlighting set line_attr. */
2882 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2884 line_attr
= sign_get_attr((int)v
, TRUE
);
2886 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2887 /* Highlight the current line in the quickfix window. */
2888 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2889 line_attr
= hl_attr(HLF_L
);
2892 area_highlighting
= TRUE
;
2895 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2901 /* For checking first word with a capital skip white space. */
2903 cap_col
= (int)(skipwhite(line
) - line
);
2905 /* To be able to spell-check over line boundaries copy the end of the
2906 * current line into nextline[]. Above the start of the next line was
2907 * copied to nextline[SPWORDLEN]. */
2908 if (nextline
[SPWORDLEN
] == NUL
)
2910 /* No next line or it is empty. */
2911 nextlinecol
= MAXCOL
;
2916 v
= (long)STRLEN(line
);
2919 /* Short line, use it completely and append the start of the
2922 mch_memmove(nextline
, line
, (size_t)v
);
2923 mch_memmove(nextline
+ v
, nextline
+ SPWORDLEN
,
2924 STRLEN(nextline
+ SPWORDLEN
) + 1);
2925 nextline_idx
= v
+ 1;
2929 /* Long line, use only the last SPWORDLEN bytes. */
2930 nextlinecol
= v
- SPWORDLEN
;
2931 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2932 nextline_idx
= SPWORDLEN
+ 1;
2938 /* find start of trailing whitespace */
2939 if (wp
->w_p_list
&& lcs_trail
)
2941 trailcol
= (colnr_T
)STRLEN(ptr
);
2942 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
2944 trailcol
+= (colnr_T
) (ptr
- line
);
2949 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
2950 * first character to be displayed.
2959 char_u
*prev_ptr
= ptr
;
2961 while (vcol
< v
&& *ptr
!= NUL
)
2963 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
2971 #ifdef FEAT_VIRTUALEDIT
2972 /* When 'virtualedit' is set the end of the line may be before the
2973 * start of the displayed part. */
2974 if (vcol
< v
&& *ptr
== NUL
&& virtual_active())
2978 /* Handle a character that's not completely on the screen: Put ptr at
2979 * that character but skip the first few screen characters. */
2992 * Adjust for when the inverted text is before the screen,
2993 * and when the start of the inverted text is before the screen.
2997 else if (fromcol
>= 0 && fromcol
< vcol
)
3000 #ifdef FEAT_LINEBREAK
3001 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3003 need_showbreak
= TRUE
;
3006 /* When spell checking a word we need to figure out the start of the
3007 * word and if it's badly spelled or not. */
3011 hlf_T spell_hlf
= HLF_COUNT
;
3014 wp
->w_cursor
.lnum
= lnum
;
3015 wp
->w_cursor
.col
= (colnr_T
)(ptr
- line
);
3016 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3017 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3019 /* no bad word found at line start, don't check until end of a
3021 spell_hlf
= HLF_COUNT
;
3022 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
) - line
+ 1);
3026 /* bad word found, use attributes until end of word */
3027 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3029 /* Turn index into actual attributes. */
3030 if (spell_hlf
!= HLF_COUNT
)
3031 spell_attr
= highlight_attr
[spell_hlf
];
3036 /* Need to restart syntax highlighting for this line. */
3038 syntax_start(wp
, lnum
);
3045 * Correct highlighting for cursor that can't be disabled.
3046 * Avoids having to check this for each character.
3052 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3054 /* highlighting starts at cursor, let it start just after the
3056 fromcol_prev
= fromcol
;
3059 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3060 /* restart highlighting after the cursor */
3061 fromcol_prev
= wp
->w_virtcol
;
3063 if (fromcol
>= tocol
)
3067 #ifdef FEAT_SEARCH_EXTRA
3069 * Handle highlighting the last used search pattern and ":match".
3070 * Do this for both search_hl and match_hl[3].
3072 for (i
= 3; i
>= 0; --i
)
3074 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
3075 shl
->startcol
= MAXCOL
;
3076 shl
->endcol
= MAXCOL
;
3078 if (shl
->rm
.regprog
!= NULL
)
3080 v
= (long)(ptr
- line
);
3081 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3083 /* Need to get the line again, a multi-line regexp may have made it
3085 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3088 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3090 if (shl
->lnum
== lnum
)
3091 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3094 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3095 - shl
->rm
.startpos
[0].lnum
)
3096 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3098 shl
->endcol
= MAXCOL
;
3099 /* Highlight one character for an empty match. */
3100 if (shl
->startcol
== shl
->endcol
)
3103 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3104 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3109 if ((long)shl
->startcol
< v
) /* match at leftcol */
3111 shl
->attr_cur
= shl
->attr
;
3112 search_attr
= shl
->attr
;
3114 area_highlighting
= TRUE
;
3121 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3122 * active, because it's not clear what is selected then. */
3123 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3125 line_attr
= hl_attr(HLF_CUL
);
3126 area_highlighting
= TRUE
;
3130 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3132 #ifdef FEAT_RIGHTLEFT
3135 /* Rightleft window: process the text in the normal direction, but put
3136 * it in current_ScreenLine[] from right to left. Start at the
3137 * rightmost column of the window. */
3138 col
= W_WIDTH(wp
) - 1;
3144 * Repeat for the whole displayed line.
3148 /* Skip this quickly when working on the text. */
3149 if (draw_state
!= WL_LINE
)
3152 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3154 draw_state
= WL_CMDLINE
;
3155 if (cmdwin_type
!= 0 && wp
== curwin
)
3157 /* Draw the cmdline character. */
3158 *extra
= cmdwin_type
;
3162 char_attr
= hl_attr(HLF_AT
);
3168 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3170 draw_state
= WL_FOLD
;
3171 if (wp
->w_p_fdc
> 0)
3173 /* Draw the 'foldcolumn'. */
3174 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3175 n_extra
= wp
->w_p_fdc
;
3178 char_attr
= hl_attr(HLF_FC
);
3184 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3186 draw_state
= WL_SIGN
;
3187 /* Show the sign column when there are any signs in this
3188 * buffer or when using Netbeans. */
3189 if (draw_signcolumn(wp
)
3196 # ifdef FEAT_SIGN_ICONS
3200 /* Draw two cells with the sign value or blank. */
3202 char_attr
= hl_attr(HLF_SC
);
3205 if (row
== startrow
)
3207 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3209 # ifdef FEAT_SIGN_ICONS
3210 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3212 if (gui
.in_use
&& icon_sign
!= 0)
3214 /* Use the image in this position. */
3215 c_extra
= SIGN_BYTE
;
3216 # ifdef FEAT_NETBEANS_INTG
3217 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3218 c_extra
= MULTISIGN_BYTE
;
3220 char_attr
= icon_sign
;
3226 p_extra
= sign_get_text(text_sign
);
3227 if (p_extra
!= NULL
)
3230 n_extra
= (int)STRLEN(p_extra
);
3232 char_attr
= sign_get_attr(text_sign
, FALSE
);
3239 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3242 /* Display the line number. After the first fill with blanks
3243 * when the 'n' flag isn't in 'cpo' */
3249 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3251 /* Draw the line number (empty space after wrapping). */
3258 sprintf((char *)extra
, "%*ld ",
3259 number_width(wp
), (long)lnum
);
3260 if (wp
->w_skipcol
> 0)
3261 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3263 #ifdef FEAT_RIGHTLEFT
3264 if (wp
->w_p_rl
) /* reverse line numbers */
3272 n_extra
= number_width(wp
) + 1;
3273 char_attr
= hl_attr(HLF_N
);
3275 /* When 'cursorline' is set highlight the line number of
3276 * the current line differently. */
3277 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3278 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3283 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3284 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3286 draw_state
= WL_SBR
;
3288 if (filler_todo
> 0)
3290 /* Draw "deleted" diff line(s). */
3291 if (char2cells(fill_diff
) > 1)
3294 c_extra
= fill_diff
;
3295 # ifdef FEAT_RIGHTLEFT
3300 n_extra
= W_WIDTH(wp
) - col
;
3301 char_attr
= hl_attr(HLF_DED
);
3304 # ifdef FEAT_LINEBREAK
3305 if (*p_sbr
!= NUL
&& need_showbreak
)
3307 /* Draw 'showbreak' at the start of each broken line. */
3310 n_extra
= (int)STRLEN(p_sbr
);
3311 char_attr
= hl_attr(HLF_AT
);
3312 need_showbreak
= FALSE
;
3313 /* Correct end of highlighted area for 'showbreak',
3314 * required when 'linebreak' is also set. */
3322 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3324 draw_state
= WL_LINE
;
3327 /* Continue item from end of wrapped line. */
3328 n_extra
= saved_n_extra
;
3329 c_extra
= saved_c_extra
;
3330 p_extra
= saved_p_extra
;
3331 char_attr
= saved_char_attr
;
3338 /* When still displaying '$' of change command, stop at cursor */
3339 if (dollar_vcol
!= 0 && wp
== curwin
3340 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3346 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3348 /* Pretend we have finished updating the window. Except when
3349 * 'cursorcolumn' is set. */
3352 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3359 if (draw_state
== WL_LINE
&& area_highlighting
)
3361 /* handle Visual or match highlighting in this line */
3364 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3365 && (*mb_ptr2cells
)(ptr
) > 1)
3367 || ((int)vcol_prev
== fromcol_prev
3369 area_attr
= attr
; /* start highlighting */
3370 else if (area_attr
!= 0
3372 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3373 area_attr
= 0; /* stop highlighting */
3375 #ifdef FEAT_SEARCH_EXTRA
3379 * Check for start/end of search pattern match.
3380 * After end, check for start/end of next match.
3381 * When another match, have to check for start again.
3382 * Watch out for matching an empty string!
3383 * Do this first for search_hl, then for match_hl, so that
3384 * ":match" overrules 'hlsearch'.
3386 v
= (long)(ptr
- line
);
3387 for (i
= 3; i
>= 0; --i
)
3389 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
3390 while (shl
->rm
.regprog
!= NULL
)
3392 if (shl
->startcol
!= MAXCOL
3393 && v
>= (long)shl
->startcol
3394 && v
< (long)shl
->endcol
)
3396 shl
->attr_cur
= shl
->attr
;
3398 else if (v
== (long)shl
->endcol
)
3402 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3404 /* Need to get the line again, a multi-line regexp
3405 * may have made it invalid. */
3406 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3409 if (shl
->lnum
== lnum
)
3411 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3412 if (shl
->rm
.endpos
[0].lnum
== 0)
3413 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3415 shl
->endcol
= MAXCOL
;
3417 if (shl
->startcol
== shl
->endcol
)
3419 /* highlight empty match, try again after
3423 shl
->endcol
+= (*mb_ptr2len
)(line
3430 /* Loop to check if the match starts at the
3431 * current position */
3439 /* ":match" highlighting overrules 'hlsearch' */
3440 for (i
= 0; i
<= 3; ++i
)
3442 search_attr
= search_hl
.attr_cur
;
3443 else if (match_hl
[i
].attr_cur
!= 0)
3445 search_attr
= match_hl
[i
].attr_cur
;
3452 if (diff_hlf
!= (hlf_T
)0)
3454 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
)
3455 diff_hlf
= HLF_TXD
; /* changed text */
3456 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
)
3457 diff_hlf
= HLF_CHD
; /* changed line */
3458 line_attr
= hl_attr(diff_hlf
);
3462 /* Decide which of the highlight attributes to use. */
3465 char_attr
= area_attr
;
3466 else if (search_attr
!= 0)
3467 char_attr
= search_attr
;
3469 /* Use line_attr when not in the Visual or 'incsearch' area
3470 * (area_attr may be 0 when "noinvcur" is set). */
3471 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3472 || (vcol
< fromcol
|| vcol
>= tocol
)))
3473 char_attr
= line_attr
;
3480 char_attr
= syntax_attr
;
3488 * Get the next character to put on the screen.
3491 * The 'extra' array contains the extra stuff that is inserted to
3492 * represent special characters (non-printable stuff). When all
3493 * characters are the same, c_extra is used.
3494 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3502 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3503 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3522 /* If the UTF-8 character is more than one byte:
3523 * Decode it into "mb_c". */
3524 mb_l
= (*mb_ptr2len
)(p_extra
);
3530 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3537 /* if this is a DBCS character, put it in "mb_c" */
3538 mb_l
= MB_BYTE2LEN(c
);
3539 if (mb_l
>= n_extra
)
3542 mb_c
= (c
<< 8) + p_extra
[1];
3544 if (mb_l
== 0) /* at the NUL at end-of-line */
3547 /* If a double-width char doesn't fit display a '>' in the
3550 # ifdef FEAT_RIGHTLEFT
3551 wp
->w_p_rl
? (col
<= 0) :
3553 (col
>= W_WIDTH(wp
) - 1))
3554 && (*mb_char2cells
)(mb_c
) == 2)
3560 multi_attr
= hl_attr(HLF_AT
);
3561 /* put the pointer back to output the double-width
3562 * character at the start of the next line. */
3568 n_extra
-= mb_l
- 1;
3569 p_extra
+= mb_l
- 1;
3580 * Get a character from the line itself.
3589 /* If the UTF-8 character is more than one byte: Decode it
3591 mb_l
= (*mb_ptr2len
)(ptr
);
3595 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3596 /* Overlong encoded ASCII or ASCII with composing char
3597 * is displayed normally, except a NUL. */
3602 /* At start of the line we can have a composing char.
3603 * Draw it as a space with a composing char. */
3604 if (utf_iscomposing(mb_c
))
3606 for (i
= Screen_mco
- 1; i
> 0; --i
)
3607 u8cc
[i
] = u8cc
[i
- 1];
3613 if ((mb_l
== 1 && c
>= 0x80)
3614 || (mb_l
>= 1 && mb_c
== 0)
3615 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3616 || mb_c
>= 0x10000)))
3619 * Illegal UTF-8 byte: display as <xx>.
3620 * Non-BMP character : display as ? or fullwidth ?.
3624 transchar_hex(extra
, mb_c
);
3625 # ifdef FEAT_RIGHTLEFT
3626 if (wp
->w_p_rl
) /* reverse */
3630 else if (utf_char2cells(mb_c
) != 2)
3633 /* 0xff1f in UTF-8: full-width '?' */
3634 STRCPY(extra
, "\357\274\237");
3638 mb_c
= mb_ptr2char_adv(&p_extra
);
3639 mb_utf8
= (c
>= 0x80);
3640 n_extra
= (int)STRLEN(p_extra
);
3642 if (area_attr
== 0 && search_attr
== 0)
3644 n_attr
= n_extra
+ 1;
3645 extra_attr
= hl_attr(HLF_8
);
3646 saved_attr2
= char_attr
; /* save current attr */
3649 else if (mb_l
== 0) /* at the NUL at end-of-line */
3652 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3654 /* Do Arabic shaping. */
3658 /* The idea of what is the previous and next
3659 * character depends on 'rightleft'. */
3664 nc
= utf_ptr2char(ptr
+ mb_l
);
3669 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3675 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3683 mb_l
= MB_BYTE2LEN(c
);
3684 if (mb_l
== 0) /* at the NUL at end-of-line */
3688 /* We assume a second byte below 32 is illegal.
3689 * Hopefully this is OK for all double-byte encodings!
3692 mb_c
= (c
<< 8) + ptr
[1];
3697 /* head byte at end of line */
3699 transchar_nonprint(extra
, c
);
3703 /* illegal tail byte */
3705 STRCPY(extra
, "XX");
3708 n_extra
= (int)STRLEN(extra
) - 1;
3711 if (area_attr
== 0 && search_attr
== 0)
3713 n_attr
= n_extra
+ 1;
3714 extra_attr
= hl_attr(HLF_8
);
3715 saved_attr2
= char_attr
; /* save current attr */
3721 /* If a double-width char doesn't fit display a '>' in the
3722 * last column; the character is displayed at the start of the
3725 # ifdef FEAT_RIGHTLEFT
3726 wp
->w_p_rl
? (col
<= 0) :
3728 (col
>= W_WIDTH(wp
) - 1))
3729 && (*mb_char2cells
)(mb_c
) == 2)
3735 multi_attr
= hl_attr(HLF_AT
);
3736 /* Put pointer back so that the character will be
3737 * displayed at the start of the next line. */
3740 else if (*ptr
!= NUL
)
3743 /* If a double-width char doesn't fit at the left side display
3744 * a '<' in the first column. */
3745 if (n_skip
> 0 && mb_l
> 1)
3752 if (area_attr
== 0 && search_attr
== 0)
3754 n_attr
= n_extra
+ 1;
3755 extra_attr
= hl_attr(HLF_AT
);
3756 saved_attr2
= char_attr
; /* save current attr */
3767 /* 'list' : change char 160 to lcs_nbsp. */
3768 if (wp
->w_p_list
&& (c
== 160
3770 || (mb_utf8
&& mb_c
== 160)
3775 if (area_attr
== 0 && search_attr
== 0)
3778 extra_attr
= hl_attr(HLF_8
);
3779 saved_attr2
= char_attr
; /* save current attr */
3783 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3797 int can_spell
= TRUE
;
3801 /* Get syntax attribute, unless still at the start of the line
3802 * (double-wide char that doesn't fit). */
3803 v
= (long)(ptr
- line
);
3804 if (has_syntax
&& v
> 0)
3806 /* Get the syntax attribute for the character. If there
3807 * is an error, disable syntax highlighting. */
3808 save_did_emsg
= did_emsg
;
3811 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3813 has_spell
? &can_spell
:
3819 wp
->w_buffer
->b_syn_error
= TRUE
;
3823 did_emsg
= save_did_emsg
;
3825 /* Need to get the line again, a multi-line regexp may
3826 * have made it invalid. */
3827 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3831 char_attr
= syntax_attr
;
3833 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3838 /* Check spelling (unless at the end of the line).
3839 * Only do this when there is no syntax highlighting, the
3840 * @Spell cluster is not used or the current syntax item
3841 * contains the @Spell cluster. */
3842 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3847 char_attr
= syntax_attr
;
3855 char_u
*prev_ptr
, *p
;
3857 hlf_T spell_hlf
= HLF_COUNT
;
3861 prev_ptr
= ptr
- mb_l
;
3868 /* Use nextline[] if possible, it has the start of the
3869 * next line concatenated. */
3870 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3871 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
3874 cap_col
-= (int)(prev_ptr
- line
);
3875 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
3879 /* In Insert mode only highlight a word that
3880 * doesn't touch the cursor. */
3881 if (spell_hlf
!= HLF_COUNT
3882 && (State
& INSERT
) != 0
3883 && wp
->w_cursor
.lnum
== lnum
3884 && wp
->w_cursor
.col
>=
3885 (colnr_T
)(prev_ptr
- line
)
3886 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
3888 spell_hlf
= HLF_COUNT
;
3889 spell_redraw_lnum
= lnum
;
3892 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
3893 && (p
- nextline
) + len
> nextline_idx
)
3895 /* Remember that the good word continues at the
3896 * start of the next line. */
3897 checked_lnum
= lnum
+ 1;
3898 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
3901 /* Turn index into actual attributes. */
3902 if (spell_hlf
!= HLF_COUNT
)
3903 spell_attr
= highlight_attr
[spell_hlf
];
3908 && (p
- nextline
) + cap_col
>= nextline_idx
)
3910 /* Remember that the word in the next line
3911 * must start with a capital. */
3912 capcol_lnum
= lnum
+ 1;
3913 cap_col
= (int)((p
- nextline
) + cap_col
3917 /* Compute the actual column. */
3918 cap_col
+= (int)(prev_ptr
- line
);
3922 if (spell_attr
!= 0)
3925 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
3927 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
3930 #ifdef FEAT_LINEBREAK
3932 * Found last space before word: check for line break.
3934 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
3937 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
3941 1), (colnr_T
)vcol
, NULL
) - 1;
3948 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
3954 extra_attr
= hl_attr(HLF_8
);
3955 saved_attr2
= char_attr
; /* save current attr */
3959 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3972 * Handling of non-printable characters.
3974 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
3977 * when getting a character from the file, we may have to
3978 * turn it into something else on the way to putting it
3979 * into "ScreenLines".
3981 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
3983 /* tab amount depends on current column */
3984 n_extra
= (int)wp
->w_buffer
->b_p_ts
3985 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
3987 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
3993 n_attr
= n_extra
+ 1;
3994 extra_attr
= hl_attr(HLF_8
);
3995 saved_attr2
= char_attr
; /* save current attr */
3998 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4013 && ((wp
->w_p_list
&& lcs_eol
> 0)
4014 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4017 && VIsual_mode
!= Ctrl_V
4020 # ifdef FEAT_RIGHTLEFT
4021 wp
->w_p_rl
? (col
>= 0) :
4023 (col
< W_WIDTH(wp
)))
4025 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4026 && lcs_eol_one
>= 0)
4028 /* Display a '$' after the line or highlight an extra
4029 * character if the line break is included. */
4030 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4031 /* For a diff line the highlighting continues after the
4035 diff_hlf
== (hlf_T
)0
4046 #ifdef FEAT_VIRTUALEDIT
4047 /* In virtualedit, visual selections may extend
4048 * beyond end of line. */
4049 if (area_highlighting
&& virtual_active()
4050 && tocol
!= MAXCOL
&& vcol
< tocol
)
4055 p_extra
= at_end_str
;
4065 --ptr
; /* put it back at the NUL */
4068 extra_attr
= hl_attr(HLF_AT
);
4073 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4080 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4085 p_extra
= transchar(c
);
4086 #ifdef FEAT_RIGHTLEFT
4087 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4088 rl_mirror(p_extra
); /* reverse "<12>" */
4090 n_extra
= byte2cells(c
) - 1;
4095 n_attr
= n_extra
+ 1;
4096 extra_attr
= hl_attr(HLF_8
);
4097 saved_attr2
= char_attr
; /* save current attr */
4100 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4103 #ifdef FEAT_VIRTUALEDIT
4104 else if (VIsual_active
4105 && (VIsual_mode
== Ctrl_V
4106 || VIsual_mode
== 'v')
4111 # ifdef FEAT_RIGHTLEFT
4112 wp
->w_p_rl
? (col
>= 0) :
4114 (col
< W_WIDTH(wp
))))
4117 --ptr
; /* put it back at the NUL */
4120 #if defined(LINE_ATTR)
4123 diff_hlf
!= (hlf_T
)0 ||
4127 # ifdef FEAT_RIGHTLEFT
4128 wp
->w_p_rl
? (col
>= 0) :
4130 (col
< W_WIDTH(wp
))))
4132 /* Highlight until the right side of the window */
4134 --ptr
; /* put it back at the NUL */
4136 /* Remember we do the char for line highlighting. */
4139 /* don't do search HL for the rest of the line */
4140 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4141 char_attr
= line_attr
;
4143 if (diff_hlf
== HLF_TXD
)
4146 if (attr
== 0 || char_attr
!= attr
)
4147 char_attr
= hl_attr(diff_hlf
);
4155 /* Don't override visual selection highlighting. */
4157 && draw_state
== WL_LINE
4159 char_attr
= extra_attr
;
4161 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4162 /* XIM don't send preedit_start and preedit_end, but they send
4163 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4164 * im_is_preediting() here. */
4166 && lnum
== curwin
->w_cursor
.lnum
4169 && im_is_preediting()
4170 && draw_state
== WL_LINE
)
4174 if (preedit_end_col
== MAXCOL
)
4175 getvcol(curwin
, &(curwin
->w_cursor
), &tcol
, NULL
, NULL
);
4177 tcol
= preedit_end_col
;
4178 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4180 if (feedback_old_attr
< 0)
4183 feedback_old_attr
= char_attr
;
4185 char_attr
= im_get_feedback_attr(feedback_col
);
4187 char_attr
= feedback_old_attr
;
4190 else if (feedback_old_attr
>= 0)
4192 char_attr
= feedback_old_attr
;
4193 feedback_old_attr
= -1;
4199 * Handle the case where we are in column 0 but not on the first
4200 * character of the line and the user wants us to show us a
4201 * special character (via 'listchars' option "precedes:<char>".
4203 if (lcs_prec_todo
!= NUL
4204 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4208 && draw_state
> WL_NR
4212 lcs_prec_todo
= NUL
;
4215 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4222 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4226 saved_attr3
= char_attr
; /* save current attr */
4227 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4233 * At end of the text line or just after the last character.
4236 #if defined(LINE_ATTR)
4237 || did_line_attr
== 1
4241 #ifdef FEAT_SEARCH_EXTRA
4242 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4245 /* invert at least one char, used for Visual and empty line or
4246 * highlight match at end of line. If it's beyond the last
4247 * char on the screen, just overwrite that one (tricky!) Not
4248 * needed when a '$' was displayed for 'list'. */
4249 if (lcs_eol
== lcs_eol_one
4250 && ((area_attr
!= 0 && vcol
== fromcol
&& c
== NUL
)
4251 #ifdef FEAT_SEARCH_EXTRA
4252 /* highlight 'hlsearch' match at end of line */
4253 || ((prevcol
== (long)search_hl
.startcol
4254 || prevcol
== (long)match_hl
[0].startcol
4255 || prevcol
== (long)match_hl
[1].startcol
4256 || prevcol
== (long)match_hl
[2].startcol
)
4257 # if defined(LINE_ATTR)
4258 && did_line_attr
<= 1
4266 #ifdef FEAT_RIGHTLEFT
4275 if (col
>= W_WIDTH(wp
))
4280 /* At the window boundary, highlight the last character
4281 * instead (better than nothing). */
4287 /* Add a blank character to highlight. */
4288 ScreenLines
[off
] = ' ';
4291 ScreenLinesUC
[off
] = 0;
4294 #ifdef FEAT_SEARCH_EXTRA
4297 for (i
= 0; i
<= 3; ++i
)
4300 char_attr
= search_hl
.attr
;
4301 else if ((ptr
- line
) - 1 == (long)match_hl
[i
].startcol
)
4303 char_attr
= match_hl
[i
].attr
;
4309 ScreenAttrs
[off
] = char_attr
;
4310 #ifdef FEAT_RIGHTLEFT
4321 * At end of the text line.
4326 /* Highlight 'cursorcolumn' past end of the line. */
4331 /* check if line ends before left margin */
4332 if (vcol
< v
+ col
- win_col_off(wp
))
4334 vcol
= v
+ col
- win_col_off(wp
);
4336 && (int)wp
->w_virtcol
>= vcol
4337 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4339 && lnum
!= wp
->w_cursor
.lnum
4340 # ifdef FEAT_RIGHTLEFT
4345 while (col
< W_WIDTH(wp
))
4347 ScreenLines
[off
] = ' ';
4350 ScreenLinesUC
[off
] = 0;
4353 if (vcol
== (long)wp
->w_virtcol
)
4355 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4358 ScreenAttrs
[off
++] = 0;
4364 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4369 * Update w_cline_height and w_cline_folded if the cursor line was
4370 * updated (saves a call to plines() later).
4372 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4374 curwin
->w_cline_row
= startrow
;
4375 curwin
->w_cline_height
= row
- startrow
;
4377 curwin
->w_cline_folded
= FALSE
;
4379 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4385 /* line continues beyond line end */
4392 #ifdef FEAT_RIGHTLEFT
4393 wp
->w_p_rl
? col
== 0 :
4395 col
== W_WIDTH(wp
) - 1)
4397 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4398 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4401 char_attr
= hl_attr(HLF_AT
);
4404 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4416 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4417 * highlight the cursor position itself. */
4418 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4419 && lnum
!= wp
->w_cursor
.lnum
4420 && draw_state
== WL_LINE
)
4422 vcol_save_attr
= char_attr
;
4423 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4426 vcol_save_attr
= -1;
4430 * Store character to be displayed.
4431 * Skip characters that are left of the screen for 'nowrap'.
4434 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4437 * Store the character.
4439 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4440 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4442 /* A double-wide character is: put first halve in left cell. */
4447 ScreenLines
[off
] = c
;
4449 if (enc_dbcs
== DBCS_JPNU
)
4450 ScreenLines2
[off
] = mb_c
& 0xff;
4455 ScreenLinesUC
[off
] = mb_c
;
4456 if ((c
& 0xff) == 0)
4457 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4458 for (i
= 0; i
< Screen_mco
; ++i
)
4460 ScreenLinesC
[i
][off
] = u8cc
[i
];
4466 ScreenLinesUC
[off
] = 0;
4470 ScreenAttrs
[off
] = multi_attr
;
4475 ScreenAttrs
[off
] = char_attr
;
4478 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4480 /* Need to fill two screen columns. */
4484 /* UTF-8: Put a 0 in the second screen char. */
4485 ScreenLines
[off
] = 0;
4487 /* DBCS: Put second byte in the second screen char. */
4488 ScreenLines
[off
] = mb_c
& 0xff;
4490 /* When "tocol" is halfway a character, set it to the end of
4491 * the character, otherwise highlighting won't stop. */
4494 #ifdef FEAT_RIGHTLEFT
4497 /* now it's time to backup one cell */
4504 #ifdef FEAT_RIGHTLEFT
4520 /* Only advance the "vcol" when after the 'number' column. */
4521 if (draw_state
>= WL_SBR
4529 if (vcol_save_attr
>= 0)
4530 char_attr
= vcol_save_attr
;
4533 /* restore attributes after "predeces" in 'listchars' */
4534 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4535 char_attr
= saved_attr3
;
4537 /* restore attributes after last 'listchars' or 'number' char */
4538 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4539 char_attr
= saved_attr2
;
4542 * At end of screen line and there is more to come: Display the line
4543 * so far. If there is no more to display it is catched above.
4546 #ifdef FEAT_RIGHTLEFT
4547 wp
->w_p_rl
? (col
< 0) :
4549 (col
>= W_WIDTH(wp
)))
4554 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4555 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4558 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4563 /* When not wrapping and finished diff lines, or when displayed
4564 * '$' and highlighting until last column, break here. */
4569 ) || lcs_eol_one
== -1)
4572 /* When the window is too narrow draw all "@" lines. */
4573 if (draw_state
!= WL_LINE
4579 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4580 #ifdef FEAT_VERTSPLIT
4581 draw_vsep_win(wp
, row
);
4586 /* When line got too long for screen break here. */
4593 if (screen_cur_row
== screen_row
- 1
4597 && W_WIDTH(wp
) == Columns
)
4599 /* Remember that the line wraps, used for modeless copy. */
4600 LineWraps
[screen_row
- 1] = TRUE
;
4603 * Special trick to make copy/paste of wrapped lines work with
4604 * xterm/screen: write an extra character beyond the end of
4605 * the line. This will work with all terminal types
4606 * (regardless of the xn,am settings).
4607 * Only do this on a fast tty.
4608 * Only do this if the cursor is on the current line
4609 * (something has been written in it).
4610 * Don't do this for the GUI.
4611 * Don't do this for double-width characters.
4612 * Don't do this for a window not at the right screen border.
4620 && ((*mb_off2cells
)(LineOffset
[screen_row
]) == 2
4621 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4622 + (int)Columns
- 2) == 2))
4626 /* First make sure we are at the end of the screen line,
4627 * then output the same character again to let the
4628 * terminal know about the wrap. If the terminal doesn't
4629 * auto-wrap, we overwrite the character. */
4630 if (screen_cur_col
!= W_WIDTH(wp
))
4631 screen_char(LineOffset
[screen_row
- 1]
4632 + (unsigned)Columns
- 1,
4633 screen_row
- 1, (int)(Columns
- 1));
4636 /* When there is a multi-byte character, just output a
4637 * space to keep it simple. */
4638 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4639 screen_row
- 1] + (Columns
- 1)]) > 1)
4643 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4645 /* force a redraw of the first char on the next line */
4646 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4647 screen_start(); /* don't know where cursor is now */
4652 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4653 #ifdef FEAT_RIGHTLEFT
4656 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4661 /* reset the drawing state for the start of a wrapped line */
4662 draw_state
= WL_START
;
4663 saved_n_extra
= n_extra
;
4664 saved_p_extra
= p_extra
;
4665 saved_c_extra
= c_extra
;
4666 saved_char_attr
= char_attr
;
4668 lcs_prec_todo
= lcs_prec
;
4669 #ifdef FEAT_LINEBREAK
4671 if (filler_todo
<= 0)
4673 need_showbreak
= TRUE
;
4677 /* When the filler lines are actually below the last line of the
4678 * file, don't draw the line itself, break here. */
4679 if (filler_todo
== 0 && wp
->w_botfill
)
4684 } /* for every character in the line */
4687 /* After an empty line check first word for capital. */
4688 if (*skipwhite(line
) == NUL
)
4690 capcol_lnum
= lnum
+ 1;
4699 static int comp_char_differs
__ARGS((int, int));
4702 * Return if the composing characters at "off_from" and "off_to" differ.
4705 comp_char_differs(off_from
, off_to
)
4711 for (i
= 0; i
< Screen_mco
; ++i
)
4713 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4715 if (ScreenLinesC
[i
][off_from
] == 0)
4723 * Check whether the given character needs redrawing:
4724 * - the (first byte of the) character is different
4725 * - the attributes are different
4726 * - the character is multi-byte and the next byte is different
4729 char_needs_redraw(off_from
, off_to
, cols
)
4735 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4736 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4740 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4741 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4742 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4743 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4744 != ScreenLines
[off_to
+ 1])))
4746 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4747 || (ScreenLinesUC
[off_from
] != 0
4748 && comp_char_differs(off_from
, off_to
))))
4756 * Move one "cooked" screen line to the screen, but only the characters that
4757 * have actually changed. Handle insert/delete character.
4758 * "coloff" gives the first column on the screen for this line.
4759 * "endcol" gives the columns where valid characters are.
4760 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4761 * needs to be cleared, negative otherwise.
4762 * "rlflag" is TRUE in a rightleft window:
4763 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4764 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4767 screen_line(row
, coloff
, endcol
, clear_width
4768 #ifdef FEAT_RIGHTLEFT
4776 #ifdef FEAT_RIGHTLEFT
4783 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4786 int force
= FALSE
; /* force update rest of the line */
4787 int redraw_this
/* bool: does character need redraw? */
4789 = TRUE
/* For GUI when while-loop empty */
4792 int redraw_next
; /* redraw_this for next character */
4794 int clear_next
= FALSE
;
4795 int char_cells
; /* 1: normal char */
4796 /* 2: occupies two display cells */
4797 # define CHAR_CELLS char_cells
4799 # define CHAR_CELLS 1
4802 # ifdef FEAT_CLIPBOARD
4803 clip_may_clear_selection(row
, row
);
4806 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
4807 off_to
= LineOffset
[row
] + coloff
;
4809 #ifdef FEAT_RIGHTLEFT
4812 /* Clear rest first, because it's left of the text. */
4813 if (clear_width
> 0)
4815 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
4816 && ScreenAttrs
[off_to
] == 0
4818 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
4826 screen_fill(row
, row
+ 1, col
+ coloff
,
4827 endcol
+ coloff
+ 1, ' ', ' ', 0);
4830 off_to
= LineOffset
[row
] + col
+ coloff
;
4832 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
4834 #endif /* FEAT_RIGHTLEFT */
4836 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
4838 while (col
< endcol
)
4841 if (has_mbyte
&& (col
+ 1 < endcol
))
4842 char_cells
= (*mb_off2cells
)(off_from
);
4847 redraw_this
= redraw_next
;
4848 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
4849 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
4852 /* If the next character was bold, then redraw the current character to
4853 * remove any pixels that might have spilt over into us. This only
4854 * happens in the GUI.
4856 if (redraw_next
&& gui
.in_use
)
4858 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
4860 hl
= syn_attr2attr(hl
);
4869 * Special handling when 'xs' termcap flag set (hpterm):
4870 * Attributes for characters are stored at the position where the
4871 * cursor is when writing the highlighting code. The
4872 * start-highlighting code must be written with the cursor on the
4873 * first highlighted character. The stop-highlighting code must
4874 * be written with the cursor just after the last highlighted
4876 * Overwriting a character doesn't remove it's highlighting. Need
4877 * to clear the rest of the line, and force redrawing it
4885 && ScreenAttrs
[off_to
] != 0
4886 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4889 * Need to remove highlighting attributes here.
4891 windgoto(row
, col
+ coloff
);
4892 out_str(T_CE
); /* clear rest of this screen line */
4893 screen_start(); /* don't know where cursor is now */
4894 force
= TRUE
; /* force redraw of rest of the line */
4895 redraw_next
= TRUE
; /* or else next char would miss out */
4898 * If the previous character was highlighted, need to stop
4899 * highlighting at this character.
4901 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
4903 screen_attr
= ScreenAttrs
[off_to
- 1];
4904 term_windgoto(row
, col
+ coloff
);
4905 screen_stop_highlight();
4908 screen_attr
= 0; /* highlighting has stopped */
4913 /* Check if overwriting a double-byte with a single-byte or
4914 * the other way around requires another character to be
4915 * redrawn. For UTF-8 this isn't needed, because comparing
4916 * ScreenLinesUC[] is sufficient. */
4919 && (*mb_off2cells
)(off_to
) > 1)
4921 /* Writing a single-cell character over a double-cell
4922 * character: need to redraw the next cell. */
4923 ScreenLines
[off_to
+ 1] = 0;
4926 else if (char_cells
== 2
4928 && (*mb_off2cells
)(off_to
) == 1
4929 && (*mb_off2cells
)(off_to
+ 1) > 1)
4931 /* Writing the second half of a double-cell character over
4932 * a double-cell character: need to redraw the second
4934 ScreenLines
[off_to
+ 2] = 0;
4938 if (enc_dbcs
== DBCS_JPNU
)
4939 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
4941 /* When writing a single-width character over a double-width
4942 * character and at the end of the redrawn text, need to clear out
4943 * the right halve of the old character.
4944 * Also required when writing the right halve of a double-width
4945 * char over the left halve of an existing one. */
4946 if (has_mbyte
&& col
+ char_cells
== endcol
4947 && ((char_cells
== 1
4948 && (*mb_off2cells
)(off_to
) > 1)
4950 && (*mb_off2cells
)(off_to
) == 1
4951 && (*mb_off2cells
)(off_to
+ 1) > 1)))
4955 ScreenLines
[off_to
] = ScreenLines
[off_from
];
4959 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
4960 if (ScreenLinesUC
[off_from
] != 0)
4964 for (i
= 0; i
< Screen_mco
; ++i
)
4965 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
4968 if (char_cells
== 2)
4969 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
4972 #if defined(FEAT_GUI) || defined(UNIX)
4973 /* The bold trick makes a single row of pixels appear in the next
4974 * character. When a bold character is removed, the next
4975 * character should be redrawn too. This happens for our own GUI
4976 * and for some xterms. */
4981 # if defined(FEAT_GUI) && defined(UNIX)
4989 hl
= ScreenAttrs
[off_to
];
4991 hl
= syn_attr2attr(hl
);
4996 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
4998 /* For simplicity set the attributes of second half of a
4999 * double-wide character equal to the first half. */
5000 if (char_cells
== 2)
5001 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5003 if (enc_dbcs
!= 0 && char_cells
== 2)
5004 screen_char_2(off_to
, row
, col
+ coloff
);
5007 screen_char(off_to
, row
, col
+ coloff
);
5013 && col
+ coloff
> 0)
5015 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5018 * Don't output stop-highlight when moving the cursor, it will
5019 * stop the highlighting when it should continue.
5023 else if (screen_attr
!= 0)
5024 screen_stop_highlight();
5027 off_to
+= CHAR_CELLS
;
5028 off_from
+= CHAR_CELLS
;
5035 /* Clear the second half of a double-wide character of which the left
5036 * half was overwritten with a single-wide character. */
5037 ScreenLines
[off_to
] = ' ';
5039 ScreenLinesUC
[off_to
] = 0;
5040 screen_char(off_to
, row
, col
+ coloff
);
5045 #ifdef FEAT_RIGHTLEFT
5054 /* blank out the rest of the line */
5055 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5056 && ScreenAttrs
[off_to
] == 0
5058 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5065 if (col
< clear_width
)
5069 * In the GUI, clearing the rest of the line may leave pixels
5070 * behind if the first character cleared was bold. Some bold
5071 * fonts spill over the left. In this case we redraw the previous
5072 * character too. If we didn't skip any blanks above, then we
5073 * only redraw if the character wasn't already redrawn anyway.
5075 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
)
5081 hl
= ScreenAttrs
[off_to
];
5082 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5083 screen_char(off_to
- 1, row
, col
+ coloff
- 1);
5086 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5088 #ifdef FEAT_VERTSPLIT
5089 off_to
+= clear_width
- col
;
5095 if (clear_width
> 0)
5097 #ifdef FEAT_VERTSPLIT
5098 /* For a window that's left of another, draw the separator char. */
5099 if (col
+ coloff
< Columns
)
5103 c
= fillchar_vsep(&hl
);
5104 if (ScreenLines
[off_to
] != c
5106 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5107 != (c
>= 0x80 ? c
: 0))
5109 || ScreenAttrs
[off_to
] != hl
)
5111 ScreenLines
[off_to
] = c
;
5112 ScreenAttrs
[off_to
] = hl
;
5118 ScreenLinesUC
[off_to
] = c
;
5119 ScreenLinesC
[0][off_to
] = 0;
5122 ScreenLinesUC
[off_to
] = 0;
5125 screen_char(off_to
, row
, col
+ coloff
);
5130 LineWraps
[row
] = FALSE
;
5134 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5136 * Mirror text "str" for right-left displaying.
5137 * Only works for single-byte characters (e.g., numbers).
5146 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5155 #if defined(FEAT_WINDOWS) || defined(PROTO)
5157 * mark all status lines for redraw; used after first :cd
5164 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5165 if (wp
->w_status_height
)
5167 wp
->w_redr_status
= TRUE
;
5168 redraw_later(VALID
);
5173 * mark all status lines of the current buffer for redraw
5176 status_redraw_curbuf()
5180 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5181 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5183 wp
->w_redr_status
= TRUE
;
5184 redraw_later(VALID
);
5189 * Redraw all status lines that need to be redrawn.
5192 redraw_statuslines()
5196 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5197 if (wp
->w_redr_status
)
5198 win_redr_status(wp
);
5204 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5206 * Redraw all status lines at the bottom of frame "frp".
5209 win_redraw_last_status(frp
)
5212 if (frp
->fr_layout
== FR_LEAF
)
5213 frp
->fr_win
->w_redr_status
= TRUE
;
5214 else if (frp
->fr_layout
== FR_ROW
)
5216 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5217 win_redraw_last_status(frp
);
5219 else /* frp->fr_layout == FR_COL */
5221 frp
= frp
->fr_child
;
5222 while (frp
->fr_next
!= NULL
)
5224 win_redraw_last_status(frp
);
5229 #ifdef FEAT_VERTSPLIT
5231 * Draw the verticap separator right of window "wp" starting with line "row".
5234 draw_vsep_win(wp
, row
)
5241 if (wp
->w_vsep_width
)
5243 /* draw the vertical separator right of this window */
5244 c
= fillchar_vsep(&hl
);
5245 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5246 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5252 #ifdef FEAT_WILDMENU
5253 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5254 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5257 * Get the lenght of an item as it will be shown in the status line.
5260 status_match_len(xp
, s
)
5267 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5268 || xp
->xp_context
== EXPAND_MENUNAMES
);
5270 /* Check for menu separators - replace with '|'. */
5271 if (emenu
&& menu_is_separator(s
))
5277 if (skip_status_match_char(xp
, s
))
5279 len
+= ptr2cells(s
);
5287 * Return TRUE for characters that are not displayed in a status match.
5288 * These are backslashes used for escaping. Do show backslashes in help tags.
5291 skip_status_match_char(xp
, s
)
5295 return ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5297 || ((xp
->xp_context
== EXPAND_MENUS
5298 || xp
->xp_context
== EXPAND_MENUNAMES
)
5299 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5305 * Show wildchar matches in the status line.
5306 * Show at least the "match" item.
5307 * We start at item 'first_match' in the list and show all matches that fit.
5309 * If inversion is possible we use it. Else '=' characters are used.
5312 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5315 char_u
**matches
; /* list of matches */
5319 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5323 int clen
; /* lenght in screen cells */
5327 int highlight
= TRUE
;
5328 char_u
*selstart
= NULL
;
5329 int selstart_col
= 0;
5330 char_u
*selend
= NULL
;
5331 static int first_match
= 0;
5332 int add_left
= FALSE
;
5337 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5341 if (matches
== NULL
) /* interrupted completion? */
5346 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5349 buf
= alloc((unsigned)Columns
+ 1);
5353 if (match
== -1) /* don't show match but original text */
5358 /* count 1 for the ending ">" */
5359 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5362 else if (match
< first_match
)
5364 /* jumping left, as far as we can go */
5365 first_match
= match
;
5370 /* check if match fits on the screen */
5371 for (i
= first_match
; i
< match
; ++i
)
5372 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5373 if (first_match
> 0)
5375 /* jumping right, put match at the left */
5376 if ((long)clen
> Columns
)
5378 first_match
= match
;
5379 /* if showing the last match, we can add some on the left */
5381 for (i
= match
; i
< num_matches
; ++i
)
5383 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5384 if ((long)clen
>= Columns
)
5387 if (i
== num_matches
)
5392 while (first_match
> 0)
5394 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5395 if ((long)clen
>= Columns
)
5400 fillchar
= fillchar_status(&attr
, TRUE
);
5402 if (first_match
== 0)
5415 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5419 selstart
= buf
+ len
;
5420 selstart_col
= clen
;
5424 /* Check for menu separators - replace with '|' */
5426 emenu
= (xp
->xp_context
== EXPAND_MENUS
5427 || xp
->xp_context
== EXPAND_MENUNAMES
);
5428 if (emenu
&& menu_is_separator(s
))
5430 STRCPY(buf
+ len
, transchar('|'));
5431 l
= (int)STRLEN(buf
+ len
);
5437 for ( ; *s
!= NUL
; ++s
)
5439 if (skip_status_match_char(xp
, s
))
5441 clen
+= ptr2cells(s
);
5443 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5445 STRNCPY(buf
+ len
, s
, l
);
5452 STRCPY(buf
+ len
, transchar_byte(*s
));
5453 len
+= (int)STRLEN(buf
+ len
);
5459 *(buf
+ len
++) = ' ';
5460 *(buf
+ len
++) = ' ';
5462 if (++i
== num_matches
)
5466 if (i
!= num_matches
)
5468 *(buf
+ len
++) = '>';
5474 row
= cmdline_row
- 1;
5477 if (wild_menu_showing
== 0)
5479 if (msg_scrolled
> 0)
5481 /* Put the wildmenu just above the command line. If there is
5482 * no room, scroll the screen one line up. */
5483 if (cmdline_row
== Rows
- 1)
5485 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5493 wild_menu_showing
= WM_SCROLLED
;
5497 /* Create status line if needed by setting 'laststatus' to 2.
5498 * Set 'winminheight' to zero to avoid that the window is
5500 if (lastwin
->w_status_height
== 0)
5508 wild_menu_showing
= WM_SHOWN
;
5512 screen_puts(buf
, row
, 0, attr
);
5513 if (selstart
!= NULL
&& highlight
)
5516 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5519 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5522 #ifdef FEAT_VERTSPLIT
5523 win_redraw_last_status(topframe
);
5525 lastwin
->w_redr_status
= TRUE
;
5531 #if defined(FEAT_WINDOWS) || defined(PROTO)
5533 * Redraw the status line of window wp.
5535 * If inversion is possible we use it. Else '=' characters are used.
5548 wp
->w_redr_status
= FALSE
;
5549 if (wp
->w_status_height
== 0)
5551 /* no status line, can only be last window */
5552 redraw_cmdline
= TRUE
;
5554 else if (!redrawing()
5555 #ifdef FEAT_INS_EXPAND
5556 /* don't update status line when popup menu is visible and may be
5562 /* Don't redraw right now, do it later. */
5563 wp
->w_redr_status
= TRUE
;
5566 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5568 /* redraw custom status line */
5569 redraw_custum_statusline(wp
);
5574 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5576 get_trans_bufname(wp
->w_buffer
);
5578 len
= (int)STRLEN(p
);
5580 if (wp
->w_buffer
->b_help
5581 #ifdef FEAT_QUICKFIX
5584 || bufIsChanged(wp
->w_buffer
)
5585 || wp
->w_buffer
->b_p_ro
)
5587 if (wp
->w_buffer
->b_help
)
5589 STRCPY(p
+ len
, _("[Help]"));
5590 len
+= (int)STRLEN(p
+ len
);
5592 #ifdef FEAT_QUICKFIX
5595 STRCPY(p
+ len
, _("[Preview]"));
5596 len
+= (int)STRLEN(p
+ len
);
5599 if (bufIsChanged(wp
->w_buffer
))
5601 STRCPY(p
+ len
, "[+]");
5604 if (wp
->w_buffer
->b_p_ro
)
5606 STRCPY(p
+ len
, "[RO]");
5610 #ifndef FEAT_VERTSPLIT
5611 this_ru_col
= ru_col
;
5612 if (this_ru_col
< (Columns
+ 1) / 2)
5613 this_ru_col
= (Columns
+ 1) / 2;
5615 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5616 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5617 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5618 if (this_ru_col
<= 1)
5620 p
= (char_u
*)"<"; /* No room for file name! */
5630 /* Count total number of display cells. */
5631 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5632 clen
+= (*mb_ptr2cells
)(p
+ i
);
5633 /* Find first character that will fit.
5634 * Going from start to end is much faster for DBCS. */
5635 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5636 i
+= (*mb_ptr2len
)(p
+ i
))
5637 clen
-= (*mb_ptr2cells
)(p
+ i
);
5649 if (len
> this_ru_col
- 1)
5651 p
+= len
- (this_ru_col
- 1);
5653 len
= this_ru_col
- 1;
5656 row
= W_WINROW(wp
) + wp
->w_height
;
5657 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5658 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5659 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5661 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5662 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5663 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5664 - 1 + W_WINCOL(wp
)), attr
);
5666 #ifdef FEAT_CMDL_INFO
5667 win_redr_ruler(wp
, TRUE
);
5671 #ifdef FEAT_VERTSPLIT
5673 * May need to draw the character below the vertical separator.
5675 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5677 if (stl_connected(wp
))
5678 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5680 fillchar
= fillchar_vsep(&attr
);
5681 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5689 * Redraw the status line according to 'statusline' and take care of any
5690 * errors encountered.
5693 redraw_custum_statusline(wp
)
5696 int save_called_emsg
= called_emsg
;
5698 called_emsg
= FALSE
;
5699 win_redr_custom(wp
, FALSE
);
5701 set_string_option_direct((char_u
*)"statusline", -1,
5702 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5703 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5704 called_emsg
|= save_called_emsg
;
5708 # ifdef FEAT_VERTSPLIT
5710 * Return TRUE if the status line of window "wp" is connected to the status
5711 * line of the window right of it. If not, then it's a vertical separator.
5712 * Only call if (wp->w_vsep_width != 0).
5721 while (fr
->fr_parent
!= NULL
)
5723 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5725 if (fr
->fr_next
!= NULL
)
5730 if (fr
->fr_next
!= NULL
)
5739 #endif /* FEAT_WINDOWS */
5741 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
5743 * Get the value to show for the language mappings, active 'keymap'.
5746 get_keymap_str(wp
, buf
, len
)
5748 char_u
*buf
; /* buffer for the result */
5749 int len
; /* length of buffer */
5753 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
5758 buf_T
*old_curbuf
= curbuf
;
5759 win_T
*old_curwin
= curwin
;
5762 curbuf
= wp
->w_buffer
;
5764 STRCPY(buf
, "b:keymap_name"); /* must be writable */
5766 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
5768 curbuf
= old_curbuf
;
5769 curwin
= old_curwin
;
5770 if (p
== NULL
|| *p
== NUL
)
5774 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
5775 p
= wp
->w_buffer
->b_p_keymap
;
5778 p
= (char_u
*)"lang";
5780 if ((int)(STRLEN(p
) + 3) < len
)
5781 sprintf((char *)buf
, "<%s>", p
);
5788 return buf
[0] != NUL
;
5792 #if defined(FEAT_STL_OPT) || defined(PROTO)
5794 * Redraw the status line or ruler of window "wp".
5795 * When "wp" is NULL redraw the tab pages line from 'tabline'.
5798 win_redr_custom(wp
, draw_ruler
)
5800 int draw_ruler
; /* TRUE or FALSE */
5811 char_u buf
[MAXPATHL
];
5813 struct stl_hlrec hltab
[STL_MAX_ITEM
];
5814 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
5815 int use_sandbox
= FALSE
;
5817 /* setup environment for the task at hand */
5820 /* Use 'tabline'. Always at the first line of the screen. */
5824 attr
= hl_attr(HLF_TPF
);
5827 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
5832 row
= W_WINROW(wp
) + wp
->w_height
;
5833 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5834 maxwidth
= W_WIDTH(wp
);
5839 /* advance past any leading group spec - implicit in ru_col */
5844 if (atoi((char *) p
))
5845 while (VIM_ISDIGIT(*p
))
5850 #ifdef FEAT_VERTSPLIT
5851 col
= ru_col
- (Columns
- W_WIDTH(wp
));
5852 if (col
< (W_WIDTH(wp
) + 1) / 2)
5853 col
= (W_WIDTH(wp
) + 1) / 2;
5856 if (col
> (Columns
+ 1) / 2)
5857 col
= (Columns
+ 1) / 2;
5859 maxwidth
= W_WIDTH(wp
) - col
;
5861 if (!wp
->w_status_height
)
5865 --maxwidth
; /* writing in last column may cause scrolling */
5871 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
5876 if (*wp
->w_p_stl
!= NUL
)
5881 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
5882 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
5886 #ifdef FEAT_VERTSPLIT
5887 col
+= W_WINCOL(wp
);
5894 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
5897 fillchar
, maxwidth
, hltab
, tabtab
);
5898 len
= (int)STRLEN(buf
);
5900 while (width
< maxwidth
&& len
< sizeof(buf
) - 1)
5903 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
5905 buf
[len
++] = fillchar
;
5912 * Draw each snippet with the specified highlighting.
5916 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
5918 len
= (int)(hltab
[n
].start
- p
);
5919 screen_puts_len(p
, len
, row
, col
, curattr
);
5920 col
+= vim_strnsize(p
, len
);
5923 if (hltab
[n
].userhl
== 0)
5925 else if (hltab
[n
].userhl
< 0)
5926 curattr
= syn_id2attr(-hltab
[n
].userhl
);
5928 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
5929 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
5932 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
5934 screen_puts(p
, row
, col
, curattr
);
5938 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
5943 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
5945 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
5947 TabPageIdxs
[col
++] = fillchar
;
5948 p
= tabtab
[n
].start
;
5949 fillchar
= tabtab
[n
].userhl
;
5951 while (col
< Columns
)
5952 TabPageIdxs
[col
++] = fillchar
;
5956 #endif /* FEAT_STL_OPT */
5959 * Output a single character directly to the screen and update ScreenLines.
5962 screen_putchar(c
, row
, col
, attr
)
5968 char_u buf
[MB_MAXBYTES
+ 1];
5970 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
5977 screen_puts(buf
, row
, col
, attr
);
5981 * Get a single character directly from ScreenLines into "bytes[]".
5982 * Also return its attribute in *attrp;
5985 screen_getbytes(row
, col
, bytes
, attrp
)
5993 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
5995 off
= LineOffset
[row
] + col
;
5996 *attrp
= ScreenAttrs
[off
];
5997 bytes
[0] = ScreenLines
[off
];
6001 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6002 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6003 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6005 bytes
[0] = ScreenLines
[off
];
6006 bytes
[1] = ScreenLines2
[off
];
6009 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6011 bytes
[1] = ScreenLines
[off
+ 1];
6019 static int screen_comp_differs
__ARGS((int, int*));
6022 * Return TRUE if composing characters for screen posn "off" differs from
6023 * composing characters in "u8cc".
6026 screen_comp_differs(off
, u8cc
)
6032 for (i
= 0; i
< Screen_mco
; ++i
)
6034 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6044 * Put string '*text' on the screen at position 'row' and 'col', with
6045 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6046 * Note: only outputs within one row, message is truncated at screen boundary!
6047 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6050 screen_puts(text
, row
, col
, attr
)
6056 screen_puts_len(text
, -1, row
, col
, attr
);
6060 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6064 screen_puts_len(text
, len
, row
, col
, attr
)
6076 int mbyte_cells
= 1;
6079 int clear_next_cell
= FALSE
;
6081 int prev_c
= 0; /* previous Arabic character */
6087 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6090 off
= LineOffset
[row
] + col
;
6091 while (*ptr
!= NUL
&& col
< screen_Columns
6092 && (len
< 0 || (int)(ptr
- text
) < len
))
6096 /* check if this is the first byte of a multibyte */
6099 if (enc_utf8
&& len
> 0)
6100 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6102 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6103 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6105 else if (enc_dbcs
!= 0)
6106 mbyte_cells
= mbyte_blen
;
6110 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6111 (int)((text
+ len
) - ptr
));
6113 u8c
= utfc_ptr2char(ptr
, u8cc
);
6114 mbyte_cells
= utf_char2cells(u8c
);
6115 /* Non-BMP character: display as ? or fullwidth ?. */
6118 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6120 attr
= hl_attr(HLF_8
);
6123 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6125 /* Do Arabic shaping. */
6126 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6128 /* Past end of string to be displayed. */
6134 nc
= utfc_ptr2char(ptr
+ mbyte_blen
, pcc
);
6139 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6148 if (ScreenLines
[off
] != c
6150 || (mbyte_cells
== 2
6151 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6152 || (enc_dbcs
== DBCS_JPNU
6154 && ScreenLines2
[off
] != ptr
[1])
6156 && (ScreenLinesUC
[off
] != (u8char_T
)u8c
6157 || screen_comp_differs(off
, u8cc
)))
6159 || ScreenAttrs
[off
] != attr
6163 #if defined(FEAT_GUI) || defined(UNIX)
6164 /* The bold trick makes a single row of pixels appear in the next
6165 * character. When a bold character is removed, the next
6166 * character should be redrawn too. This happens for our own GUI
6167 * and for some xterms.
6168 * Force the redraw by setting the attribute to a different value
6169 * than "attr", the contents of ScreenLines[] may be needed by
6170 * mb_off2cells() further on.
6171 * Don't do this for the last drawn character, because the next
6172 * character may not be redrawn. */
6177 # if defined(FEAT_GUI) && defined(UNIX)
6187 n
= ScreenAttrs
[off
];
6189 if (col
+ mbyte_cells
< screen_Columns
6190 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6191 && (len
< 0 ? ptr
[mbyte_blen
] != NUL
6192 : ptr
+ mbyte_blen
< text
+ len
))
6193 ScreenAttrs
[off
+ mbyte_cells
] = attr
+ 1;
6195 if (col
+ 1 < screen_Columns
6196 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6197 && (len
< 0 ? ptr
[1] != NUL
: ptr
+ 1 < text
+ len
))
6198 ScreenLines
[off
+ 1] = 0;
6203 /* When at the end of the text and overwriting a two-cell
6204 * character with a one-cell character, need to clear the next
6205 * cell. Also when overwriting the left halve of a two-cell char
6206 * with the right halve of a two-cell char. Do this only once
6207 * (mb_off2cells() may return 2 on the right halve). */
6208 if (clear_next_cell
)
6209 clear_next_cell
= FALSE
;
6211 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6212 : ptr
+ mbyte_blen
>= text
+ len
)
6213 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
) > 1)
6214 || (mbyte_cells
== 2
6215 && (*mb_off2cells
)(off
) == 1
6216 && (*mb_off2cells
)(off
+ 1) > 1)))
6217 clear_next_cell
= TRUE
;
6219 /* Make sure we never leave a second byte of a double-byte behind,
6220 * it confuses mb_off2cells(). */
6222 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
) > 1)
6223 || (mbyte_cells
== 2
6224 && (*mb_off2cells
)(off
) == 1
6225 && (*mb_off2cells
)(off
+ 1) > 1)))
6226 ScreenLines
[off
+ mbyte_blen
] = 0;
6228 ScreenLines
[off
] = c
;
6229 ScreenAttrs
[off
] = attr
;
6233 if (c
< 0x80 && u8cc
[0] == 0)
6234 ScreenLinesUC
[off
] = 0;
6239 ScreenLinesUC
[off
] = u8c
;
6240 for (i
= 0; i
< Screen_mco
; ++i
)
6242 ScreenLinesC
[i
][off
] = u8cc
[i
];
6247 if (mbyte_cells
== 2)
6249 ScreenLines
[off
+ 1] = 0;
6250 ScreenAttrs
[off
+ 1] = attr
;
6252 screen_char(off
, row
, col
);
6254 else if (mbyte_cells
== 2)
6256 ScreenLines
[off
+ 1] = ptr
[1];
6257 ScreenAttrs
[off
+ 1] = attr
;
6258 screen_char_2(off
, row
, col
);
6260 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6262 ScreenLines2
[off
] = ptr
[1];
6263 screen_char(off
, row
, col
);
6267 screen_char(off
, row
, col
);
6275 if (clear_next_cell
)
6276 ptr
= (char_u
*)" ";
6288 #ifdef FEAT_SEARCH_EXTRA
6290 * Prepare for 'searchhl' highlighting.
6295 if (p_hls
&& !no_hlsearch
)
6297 last_pat_prog(&search_hl
.rm
);
6298 search_hl
.attr
= hl_attr(HLF_L
);
6303 * Clean up for 'searchhl' highlighting.
6308 if (search_hl
.rm
.regprog
!= NULL
)
6310 vim_free(search_hl
.rm
.regprog
);
6311 search_hl
.rm
.regprog
= NULL
;
6316 * Advance to the match in window "wp" line "lnum" or past it.
6319 prepare_search_hl(wp
, lnum
)
6323 match_T
*shl
; /* points to search_hl or match_hl */
6328 * When using a multi-line pattern, start searching at the top
6329 * of the window or just after a closed fold.
6330 * Do this both for search_hl and match_hl[3].
6332 for (i
= 3; i
>= 0; --i
)
6334 shl
= (i
== 3) ? &search_hl
: &match_hl
[i
];
6335 if (shl
->rm
.regprog
!= NULL
6337 && re_multiline(shl
->rm
.regprog
))
6339 if (shl
->first_lnum
== 0)
6341 # ifdef FEAT_FOLDING
6342 for (shl
->first_lnum
= lnum
;
6343 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6344 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6345 NULL
, NULL
, TRUE
, NULL
))
6348 shl
->first_lnum
= wp
->w_topline
;
6352 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6354 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6357 shl
->first_lnum
= shl
->lnum
6358 + shl
->rm
.endpos
[0].lnum
6359 - shl
->rm
.startpos
[0].lnum
;
6360 n
= shl
->rm
.endpos
[0].col
;
6373 * Search for a next 'searchl' or ":match" match.
6375 * Sets shl->lnum and shl->rm contents.
6376 * Note: Assumes a previous match is always before "lnum", unless
6377 * shl->lnum is zero.
6378 * Careful: Any pointers for buffer lines will become invalid.
6381 next_search_hl(win
, shl
, lnum
, mincol
)
6383 match_T
*shl
; /* points to search_hl or match_hl */
6385 colnr_T mincol
; /* minimal column for a match */
6393 /* Check for three situations:
6394 * 1. If the "lnum" is below a previous match, start a new search.
6395 * 2. If the previous match includes "mincol", use it.
6396 * 3. Continue after the previous match.
6398 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6401 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6406 * Repeat searching for a match until one is found that includes "mincol"
6407 * or none is found in this line.
6409 called_emsg
= FALSE
;
6412 /* Three situations:
6413 * 1. No useful previous match: search from start of line.
6414 * 2. Not Vi compatible or empty match: continue at next character.
6415 * Break the loop if this is beyond the end of the line.
6416 * 3. Vi compatible searching: continue at end of previous match.
6420 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6421 || (shl
->rm
.endpos
[0].lnum
== 0
6422 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6426 matchcol
= shl
->rm
.startpos
[0].col
;
6427 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6436 matchcol
+= mb_ptr2len(ml
);
6442 matchcol
= shl
->rm
.endpos
[0].col
;
6445 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
);
6448 /* Error while handling regexp: stop using this regexp. */
6449 vim_free(shl
->rm
.regprog
);
6450 shl
->rm
.regprog
= NULL
;
6456 shl
->lnum
= 0; /* no match found */
6459 if (shl
->rm
.startpos
[0].lnum
> 0
6460 || shl
->rm
.startpos
[0].col
>= mincol
6462 || shl
->rm
.endpos
[0].col
> mincol
)
6464 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6465 break; /* useful match found */
6472 screen_start_highlight(attr
)
6475 attrentry_T
*aep
= NULL
;
6489 /* The GUI handles this internally. */
6490 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6496 if (attr
> HL_ALL
) /* special HL attr. */
6499 aep
= syn_cterm_attr2entry(attr
);
6501 aep
= syn_term_attr2entry(attr
);
6502 if (aep
== NULL
) /* did ":syntax clear" */
6505 attr
= aep
->ae_attr
;
6507 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6509 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6510 && cterm_normal_fg_bold
)
6511 /* If the Normal FG color has BOLD attribute and the new HL
6512 * has a FG color defined, clear BOLD. */
6514 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6516 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6517 /* underline or undercurl */
6519 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6521 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6525 * Output the color or start string after bold etc., in case the
6526 * bold etc. override the color setting.
6532 if (aep
->ae_u
.cterm
.fg_color
)
6533 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6534 if (aep
->ae_u
.cterm
.bg_color
)
6535 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6539 if (aep
->ae_u
.term
.start
!= NULL
)
6540 out_str(aep
->ae_u
.term
.start
);
6548 screen_stop_highlight()
6550 int do_ME
= FALSE
; /* output T_ME code */
6552 if (screen_attr
!= 0
6563 /* use internal GUI code */
6564 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6570 if (screen_attr
> HL_ALL
) /* special HL attr. */
6577 * Assume that t_me restores the original colors!
6579 aep
= syn_cterm_attr2entry(screen_attr
);
6580 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6581 || aep
->ae_u
.cterm
.bg_color
))
6586 aep
= syn_term_attr2entry(screen_attr
);
6587 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6589 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6592 out_str(aep
->ae_u
.term
.stop
);
6595 if (aep
== NULL
) /* did ":syntax clear" */
6598 screen_attr
= aep
->ae_attr
;
6602 * Often all ending-codes are equal to T_ME. Avoid outputting the
6603 * same sequence several times.
6605 if (screen_attr
& HL_STANDOUT
)
6607 if (STRCMP(T_SE
, T_ME
) == 0)
6612 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6614 if (STRCMP(T_UE
, T_ME
) == 0)
6619 if (screen_attr
& HL_ITALIC
)
6621 if (STRCMP(T_CZR
, T_ME
) == 0)
6626 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6631 /* set Normal cterm colors */
6632 if (cterm_normal_fg_color
!= 0)
6633 term_fg_color(cterm_normal_fg_color
- 1);
6634 if (cterm_normal_bg_color
!= 0)
6635 term_bg_color(cterm_normal_bg_color
- 1);
6636 if (cterm_normal_fg_bold
)
6645 * Reset the colors for a cterm. Used when leaving Vim.
6646 * The machine specific code may override this again.
6649 reset_cterm_colors()
6653 /* set Normal cterm colors */
6654 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
6659 if (cterm_normal_fg_bold
)
6668 * Put character ScreenLines["off"] on the screen at position "row" and "col",
6669 * using the attributes from ScreenAttrs["off"].
6672 screen_char(off
, row
, col
)
6679 /* Check for illegal values, just in case (could happen just after
6681 if (row
>= screen_Rows
|| col
>= screen_Columns
)
6684 /* Outputting the last character on the screen may scrollup the screen.
6685 * Don't to it! Mark the character invalid (update it when scrolled up) */
6686 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
6687 #ifdef FEAT_RIGHTLEFT
6688 /* account for first command-line character in rightleft mode */
6693 ScreenAttrs
[off
] = (sattr_T
)-1;
6698 * Stop highlighting first, so it's easier to move the cursor.
6700 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
6701 if (screen_char_attr
!= 0)
6702 attr
= screen_char_attr
;
6705 attr
= ScreenAttrs
[off
];
6706 if (screen_attr
!= attr
)
6707 screen_stop_highlight();
6711 if (screen_attr
!= attr
)
6712 screen_start_highlight(attr
);
6715 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6717 char_u buf
[MB_MAXBYTES
+ 1];
6719 /* Convert UTF-8 character to bytes and write it. */
6721 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
6724 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
6733 out_char(ScreenLines
[off
]);
6735 /* double-byte character in single-width cell */
6736 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6737 out_char(ScreenLines2
[off
]);
6747 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
6748 * on the screen at position 'row' and 'col'.
6749 * The attributes of the first byte is used for all. This is required to
6750 * output the two bytes of a double-byte character with nothing in between.
6753 screen_char_2(off
, row
, col
)
6758 /* Check for illegal values (could be wrong when screen was resized). */
6759 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
6762 /* Outputting the last character on the screen may scrollup the screen.
6763 * Don't to it! Mark the character invalid (update it when scrolled up) */
6764 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
6766 ScreenAttrs
[off
] = (sattr_T
)-1;
6770 /* Output the first byte normally (positions the cursor), then write the
6771 * second byte directly. */
6772 screen_char(off
, row
, col
);
6773 out_char(ScreenLines
[off
+ 1]);
6778 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
6780 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
6781 * This uses the contents of ScreenLines[] and doesn't change it.
6784 screen_draw_rectangle(row
, col
, height
, width
, invert
)
6794 /* Can't use ScreenLines unless initialized */
6795 if (ScreenLines
== NULL
)
6799 screen_char_attr
= HL_INVERSE
;
6800 for (r
= row
; r
< row
+ height
; ++r
)
6802 off
= LineOffset
[r
];
6803 for (c
= col
; c
< col
+ width
; ++c
)
6806 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
) > 1)
6808 screen_char_2(off
+ c
, r
, c
);
6814 screen_char(off
+ c
, r
, c
);
6816 if (utf_off2cells(off
+ c
) > 1)
6822 screen_char_attr
= 0;
6826 #ifdef FEAT_VERTSPLIT
6828 * Redraw the characters for a vertically split window.
6831 redraw_block(row
, end
, wp
)
6839 # ifdef FEAT_CLIPBOARD
6840 clip_may_clear_selection(row
, end
- 1);
6851 width
= wp
->w_width
;
6853 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
6858 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
6859 * with character 'c1' in first column followed by 'c2' in the other columns.
6860 * Use attributes 'attr'.
6863 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
6864 int start_row
, end_row
;
6865 int start_col
, end_col
;
6876 #if defined(FEAT_GUI) || defined(UNIX)
6877 int force_next
= FALSE
;
6880 if (end_row
> screen_Rows
) /* safety check */
6881 end_row
= screen_Rows
;
6882 if (end_col
> screen_Columns
) /* safety check */
6883 end_col
= screen_Columns
;
6884 if (ScreenLines
== NULL
6885 || start_row
>= end_row
6886 || start_col
>= end_col
) /* nothing to do */
6889 /* it's a "normal" terminal when not in a GUI or cterm */
6895 for (row
= start_row
; row
< end_row
; ++row
)
6898 * Try to use delete-line termcap code, when no attributes or in a
6899 * "normal" terminal, where a bold/italic space is just a
6904 && end_col
== Columns
6909 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
6912 * check if we really need to clear something
6915 if (c1
!= ' ') /* don't clear first char */
6918 off
= LineOffset
[row
] + col
;
6919 end_off
= LineOffset
[row
] + end_col
;
6921 /* skip blanks (used often, keep it fast!) */
6924 while (off
< end_off
&& ScreenLines
[off
] == ' '
6925 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
6929 while (off
< end_off
&& ScreenLines
[off
] == ' '
6930 && ScreenAttrs
[off
] == 0)
6932 if (off
< end_off
) /* something to be cleared */
6934 col
= off
- LineOffset
[row
];
6935 screen_stop_highlight();
6936 term_windgoto(row
, col
);/* clear rest of this screen line */
6938 screen_start(); /* don't know where cursor is now */
6939 col
= end_col
- col
;
6940 while (col
--) /* clear chars in ScreenLines */
6942 ScreenLines
[off
] = ' ';
6945 ScreenLinesUC
[off
] = 0;
6947 ScreenAttrs
[off
] = 0;
6951 did_delete
= TRUE
; /* the chars are cleared now */
6954 off
= LineOffset
[row
] + start_col
;
6956 for (col
= start_col
; col
< end_col
; ++col
)
6958 if (ScreenLines
[off
] != c
6960 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
6961 != (c
>= 0x80 ? c
: 0))
6963 || ScreenAttrs
[off
] != attr
6964 #if defined(FEAT_GUI) || defined(UNIX)
6969 #if defined(FEAT_GUI) || defined(UNIX)
6970 /* The bold trick may make a single row of pixels appear in
6971 * the next character. When a bold character is removed, the
6972 * next character should be redrawn too. This happens for our
6973 * own GUI and for some xterms. */
6978 # if defined(FEAT_GUI) && defined(UNIX)
6986 if (ScreenLines
[off
] != ' '
6987 && (ScreenAttrs
[off
] > HL_ALL
6988 || ScreenAttrs
[off
] & HL_BOLD
))
6994 ScreenLines
[off
] = c
;
7000 ScreenLinesUC
[off
] = c
;
7001 ScreenLinesC
[0][off
] = 0;
7004 ScreenLinesUC
[off
] = 0;
7007 ScreenAttrs
[off
] = attr
;
7008 if (!did_delete
|| c
!= ' ')
7009 screen_char(off
, row
, col
);
7012 if (col
== start_col
)
7019 if (end_col
== Columns
)
7020 LineWraps
[row
] = FALSE
;
7021 if (row
== Rows
- 1) /* overwritten the command line */
7023 redraw_cmdline
= TRUE
;
7024 if (c1
== ' ' && c2
== ' ')
7025 clear_cmdline
= FALSE
; /* command line has been cleared */
7027 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7033 * Check if there should be a delay. Used before clearing or redrawing the
7034 * screen or the command line.
7037 check_for_delay(check_msg_scroll
)
7038 int check_msg_scroll
;
7040 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7042 && emsg_silent
== 0)
7045 ui_delay(1000L, TRUE
);
7046 emsg_on_display
= FALSE
;
7047 if (check_msg_scroll
)
7053 * screen_valid - allocate screen buffers if size changed
7054 * If "clear" is TRUE: clear screen if it has been resized.
7055 * Returns TRUE if there is a valid screen to write to.
7056 * Returns FALSE when starting up and screen not initialized yet.
7062 screenalloc(clear
); /* allocate screen buffers if size changed */
7063 return (ScreenLines
!= NULL
);
7067 * Resize the shell to Rows and Columns.
7068 * Allocate ScreenLines[] and associated items.
7070 * There may be some time between setting Rows and Columns and (re)allocating
7071 * ScreenLines[]. This happens when starting up and when (manually) changing
7072 * the shell size. Always use screen_Rows and screen_Columns to access items
7073 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7074 * final size of the shell is needed.
7080 int new_row
, old_row
;
7085 int outofmem
= FALSE
;
7087 schar_T
*new_ScreenLines
;
7089 u8char_T
*new_ScreenLinesUC
= NULL
;
7090 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7091 schar_T
*new_ScreenLines2
= NULL
;
7094 sattr_T
*new_ScreenAttrs
;
7095 unsigned *new_LineOffset
;
7096 char_u
*new_LineWraps
;
7098 short *new_TabPageIdxs
;
7101 static int entered
= FALSE
; /* avoid recursiveness */
7102 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7105 * Allocation of the screen buffers is done only when the size changes and
7106 * when Rows and Columns have been set and we have started doing full
7109 if ((ScreenLines
!= NULL
7110 && Rows
== screen_Rows
7111 && Columns
== screen_Columns
7113 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7114 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7115 && p_mco
== Screen_mco
7120 || (!full_screen
&& ScreenLines
== NULL
))
7124 * It's possible that we produce an out-of-memory message below, which
7125 * will cause this function to be called again. To break the loop, just
7133 * Note that the window sizes are updated before reallocating the arrays,
7134 * thus we must not redraw here!
7136 ++RedrawingDisabled
;
7138 win_new_shellsize(); /* fit the windows in the new sized shell */
7140 comp_col(); /* recompute columns for shown command and ruler */
7143 * We're changing the size of the screen.
7144 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7145 * - Move lines from the old arrays into the new arrays, clear extra
7146 * lines (unless the screen is going to be cleared).
7147 * - Free the old arrays.
7149 * If anything fails, make ScreenLines NULL, so we don't do anything!
7150 * Continuing with the old ScreenLines may result in a crash, because the
7153 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7156 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7157 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7159 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
) * MAX_MCO
);
7162 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7163 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7164 for (i
= 0; i
< p_mco
; ++i
)
7165 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc((long_u
)(
7166 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7168 if (enc_dbcs
== DBCS_JPNU
)
7169 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7170 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7172 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7173 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7174 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7175 Rows
* sizeof(unsigned)), FALSE
);
7176 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7178 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7181 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7183 if (win_alloc_lines(wp
) == FAIL
)
7193 for (i
= 0; i
< p_mco
; ++i
)
7194 if (new_ScreenLinesC
[i
] == NULL
)
7197 if (new_ScreenLines
== NULL
7199 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7200 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7202 || new_ScreenAttrs
== NULL
7203 || new_LineOffset
== NULL
7204 || new_LineWraps
== NULL
7206 || new_TabPageIdxs
== NULL
7210 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7212 /* guess the size */
7213 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7215 /* Remember we did this to avoid getting outofmem messages over
7216 * and over again. */
7217 done_outofmem_msg
= TRUE
;
7219 vim_free(new_ScreenLines
);
7220 new_ScreenLines
= NULL
;
7222 vim_free(new_ScreenLinesUC
);
7223 new_ScreenLinesUC
= NULL
;
7224 for (i
= 0; i
< p_mco
; ++i
)
7226 vim_free(new_ScreenLinesC
[i
]);
7227 new_ScreenLinesC
[i
] = NULL
;
7229 vim_free(new_ScreenLines2
);
7230 new_ScreenLines2
= NULL
;
7232 vim_free(new_ScreenAttrs
);
7233 new_ScreenAttrs
= NULL
;
7234 vim_free(new_LineOffset
);
7235 new_LineOffset
= NULL
;
7236 vim_free(new_LineWraps
);
7237 new_LineWraps
= NULL
;
7239 vim_free(new_TabPageIdxs
);
7240 new_TabPageIdxs
= NULL
;
7245 done_outofmem_msg
= FALSE
;
7247 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7249 new_LineOffset
[new_row
] = new_row
* Columns
;
7250 new_LineWraps
[new_row
] = FALSE
;
7253 * If the screen is not going to be cleared, copy as much as
7254 * possible from the old screen to the new one and clear the rest
7255 * (used when resizing the window at the "--more--" prompt or when
7256 * executing an external command, for the GUI).
7260 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7261 ' ', (size_t)Columns
* sizeof(schar_T
));
7265 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7266 0, (size_t)Columns
* sizeof(u8char_T
));
7267 for (i
= 0; i
< p_mco
; ++i
)
7268 (void)vim_memset(new_ScreenLinesC
[i
]
7269 + new_row
* Columns
,
7270 0, (size_t)Columns
* sizeof(u8char_T
));
7272 if (enc_dbcs
== DBCS_JPNU
)
7273 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7274 0, (size_t)Columns
* sizeof(schar_T
));
7276 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7277 0, (size_t)Columns
* sizeof(sattr_T
));
7278 old_row
= new_row
+ (screen_Rows
- Rows
);
7279 if (old_row
>= 0 && ScreenLines
!= NULL
)
7281 if (screen_Columns
< Columns
)
7282 len
= screen_Columns
;
7286 /* When switching to utf-8 don't copy characters, they
7287 * may be invalid now. Also when p_mco changes. */
7288 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7289 && p_mco
== Screen_mco
)
7291 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7292 ScreenLines
+ LineOffset
[old_row
],
7293 (size_t)len
* sizeof(schar_T
));
7295 if (enc_utf8
&& ScreenLinesUC
!= NULL
7296 && p_mco
== Screen_mco
)
7298 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7299 ScreenLinesUC
+ LineOffset
[old_row
],
7300 (size_t)len
* sizeof(u8char_T
));
7301 for (i
= 0; i
< p_mco
; ++i
)
7302 mch_memmove(new_ScreenLinesC
[i
]
7303 + new_LineOffset
[new_row
],
7304 ScreenLinesC
[i
] + LineOffset
[old_row
],
7305 (size_t)len
* sizeof(u8char_T
));
7307 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7308 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7309 ScreenLines2
+ LineOffset
[old_row
],
7310 (size_t)len
* sizeof(schar_T
));
7312 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7313 ScreenAttrs
+ LineOffset
[old_row
],
7314 (size_t)len
* sizeof(sattr_T
));
7318 /* Use the last line of the screen for the current line. */
7319 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7324 ScreenLines
= new_ScreenLines
;
7326 ScreenLinesUC
= new_ScreenLinesUC
;
7327 for (i
= 0; i
< p_mco
; ++i
)
7328 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7330 ScreenLines2
= new_ScreenLines2
;
7332 ScreenAttrs
= new_ScreenAttrs
;
7333 LineOffset
= new_LineOffset
;
7334 LineWraps
= new_LineWraps
;
7336 TabPageIdxs
= new_TabPageIdxs
;
7339 /* It's important that screen_Rows and screen_Columns reflect the actual
7340 * size of ScreenLines[]. Set them before calling anything. */
7342 old_Rows
= screen_Rows
;
7345 screen_Columns
= Columns
;
7347 must_redraw
= CLEAR
; /* need to clear the screen later */
7354 && ScreenLines
!= NULL
7355 && old_Rows
!= Rows
)
7357 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7359 * Adjust the position of the cursor, for when executing an external
7362 if (msg_row
>= Rows
) /* Rows got smaller */
7363 msg_row
= Rows
- 1; /* put cursor at last row */
7364 else if (Rows
> old_Rows
) /* Rows got bigger */
7365 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7366 if (msg_col
>= Columns
) /* Columns got smaller */
7367 msg_col
= Columns
- 1; /* put cursor at last column */
7372 --RedrawingDisabled
;
7376 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7386 vim_free(ScreenLinesUC
);
7387 for (i
= 0; i
< Screen_mco
; ++i
)
7388 vim_free(ScreenLinesC
[i
]);
7389 vim_free(ScreenLines2
);
7391 vim_free(ScreenLines
);
7392 vim_free(ScreenAttrs
);
7393 vim_free(LineOffset
);
7394 vim_free(LineWraps
);
7396 vim_free(TabPageIdxs
);
7403 check_for_delay(FALSE
);
7404 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7405 screenclear2(); /* clear the screen */
7413 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7415 || (gui
.in_use
&& gui
.starting
)
7423 screen_attr
= -1; /* force setting the Normal colors */
7424 screen_stop_highlight(); /* don't want highlighting here */
7426 #ifdef FEAT_CLIPBOARD
7427 /* disable selection without redrawing it */
7428 clip_scroll_selection(9999);
7431 /* blank out ScreenLines */
7432 for (i
= 0; i
< Rows
; ++i
)
7434 lineclear(LineOffset
[i
], (int)Columns
);
7435 LineWraps
[i
] = FALSE
;
7438 if (can_clear(T_CL
))
7440 out_str(T_CL
); /* clear the display */
7441 clear_cmdline
= FALSE
;
7442 mode_displayed
= FALSE
;
7446 /* can't clear the screen, mark all chars with invalid attributes */
7447 for (i
= 0; i
< Rows
; ++i
)
7448 lineinvalid(LineOffset
[i
], (int)Columns
);
7449 clear_cmdline
= TRUE
;
7452 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7454 win_rest_invalid(firstwin
);
7455 redraw_cmdline
= TRUE
;
7457 redraw_tabline
= TRUE
;
7459 if (must_redraw
== CLEAR
) /* no need to clear again */
7460 must_redraw
= NOT_VALID
;
7462 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7464 screen_start(); /* don't know where cursor is now */
7465 msg_scrolled
= 0; /* can't scroll back */
7471 * Clear one line in ScreenLines.
7474 lineclear(off
, width
)
7478 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7481 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7482 (size_t)width
* sizeof(u8char_T
));
7484 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7488 * Mark one line in ScreenLines invalid by setting the attributes to an
7492 lineinvalid(off
, width
)
7496 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7499 #ifdef FEAT_VERTSPLIT
7501 * Copy part of a Screenline for vertically split window "wp".
7504 linecopy(to
, from
, wp
)
7509 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7510 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7512 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7513 wp
->w_width
* sizeof(schar_T
));
7519 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7520 wp
->w_width
* sizeof(u8char_T
));
7521 for (i
= 0; i
< p_mco
; ++i
)
7522 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7523 wp
->w_width
* sizeof(u8char_T
));
7525 if (enc_dbcs
== DBCS_JPNU
)
7526 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7527 wp
->w_width
* sizeof(schar_T
));
7529 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7530 wp
->w_width
* sizeof(sattr_T
));
7535 * Return TRUE if clearing with term string "p" would work.
7536 * It can't work when the string is empty or it won't set the right background.
7542 return (*p
!= NUL
&& (t_colors
<= 1
7546 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7550 * Reset cursor position. Use whenever cursor was moved because of outputting
7551 * something directly to the screen (shell commands) or a terminal control
7557 screen_cur_row
= screen_cur_col
= 9999;
7561 * Move the cursor to position "row","col" in the screen.
7562 * This tries to find the most efficient way to move, minimizing the number of
7563 * characters sent to the terminal.
7580 #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */
7581 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7586 #define PLAN_WRITE 4
7587 /* Can't use ScreenLines unless initialized */
7588 if (ScreenLines
== NULL
)
7591 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7593 /* Check for valid position. */
7594 if (row
< 0) /* window without text lines? */
7596 if (row
>= screen_Rows
)
7597 row
= screen_Rows
- 1;
7598 if (col
>= screen_Columns
)
7599 col
= screen_Columns
- 1;
7601 /* check if no cursor movement is allowed in highlight mode */
7602 if (screen_attr
&& *T_MS
== NUL
)
7603 noinvcurs
= HIGHL_COST
;
7606 goto_cost
= GOTO_COST
+ noinvcurs
;
7609 * Plan how to do the positioning:
7610 * 1. Use CR to move it to column 0, same row.
7611 * 2. Use T_LE to move it a few columns to the left.
7612 * 3. Use NL to move a few lines down, column 0.
7613 * 4. Move a few columns to the right with T_ND or by writing chars.
7615 * Don't do this if the cursor went beyond the last column, the cursor
7616 * position is unknown then (some terminals wrap, some don't )
7618 * First check if the highlighting attibutes allow us to write
7619 * characters to move the cursor to the right.
7621 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
7624 * If the cursor is in the same row, bigger col, we can use CR
7627 bs
= NULL
; /* init for GCC */
7629 if (row
== screen_cur_row
&& col
< screen_cur_col
)
7631 /* "le" is preferred over "bc", because "bc" is obsolete */
7633 bs
= T_LE
; /* "cursor left" */
7635 bs
= T_BC
; /* "backspace character (old) */
7637 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
7640 if (col
+ 1 < cost
) /* using CR is less characters */
7644 cost
= 1; /* CR is just one character */
7651 if (noinvcurs
) /* will stop highlighting */
7659 * If the cursor is above where we want to be, we can use CR LF.
7661 else if (row
> screen_cur_row
)
7665 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
7666 if (noinvcurs
) /* will stop highlighting */
7674 * If the cursor is in the same row, smaller col, just use write.
7679 wouldbe_col
= screen_cur_col
;
7684 * Check if any characters that need to be written have the
7685 * correct attributes. Also avoid UTF-8 characters.
7687 i
= col
- wouldbe_col
;
7690 if (cost
< goto_cost
&& i
> 0)
7693 * Check if the attributes are correct without additionally
7694 * stopping highlighting.
7696 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
7697 while (i
&& *p
++ == attr
)
7702 * Try if it works when highlighting is stopped here.
7707 while (i
&& *p
++ == 0)
7711 cost
= 999; /* different attributes, don't do it */
7716 /* Don't use an UTF-8 char for positioning, it's slow. */
7717 for (i
= wouldbe_col
; i
< col
; ++i
)
7718 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
7728 * We can do it without term_windgoto()!
7730 if (cost
< goto_cost
)
7732 if (plan
== PLAN_LE
)
7735 screen_stop_highlight();
7736 while (screen_cur_col
> col
)
7742 else if (plan
== PLAN_CR
)
7745 screen_stop_highlight();
7749 else if (plan
== PLAN_NL
)
7752 screen_stop_highlight();
7753 while (screen_cur_row
< row
)
7761 i
= col
- screen_cur_col
;
7765 * Use cursor-right if it's one character only. Avoids
7766 * removing a line of pixels from the last bold char, when
7767 * using the bold trick in the GUI.
7769 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
7778 off
= LineOffset
[row
] + screen_cur_col
;
7781 if (ScreenAttrs
[off
] != screen_attr
)
7782 screen_stop_highlight();
7786 out_char(ScreenLines
[off
]);
7788 if (enc_dbcs
== DBCS_JPNU
7789 && ScreenLines
[off
] == 0x8e)
7790 out_char(ScreenLines2
[off
]);
7801 if (cost
>= goto_cost
)
7804 screen_stop_highlight();
7805 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
7807 term_cursor_right(col
- screen_cur_col
);
7809 term_windgoto(row
, col
);
7811 screen_cur_row
= row
;
7812 screen_cur_col
= col
;
7817 * Set cursor to its position in the current window.
7825 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
7826 W_WINCOL(curwin
) + (
7827 #ifdef FEAT_RIGHTLEFT
7828 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
7830 has_mbyte
? (*mb_ptr2cells
)(ml_get_cursor()) :
7840 * insert 'line_count' lines at 'row' in window 'wp'
7841 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
7842 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
7844 * Returns FAIL if the lines are not inserted, OK for success.
7847 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
7860 wp
->w_lines_valid
= 0;
7862 if (wp
->w_height
< 5)
7865 if (line_count
> wp
->w_height
- row
)
7866 line_count
= wp
->w_height
- row
;
7868 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
7869 if (retval
!= MAYBE
)
7873 * If there is a next window or a status line, we first try to delete the
7874 * lines at the bottom to avoid messing what is after the window.
7875 * If this fails and there are following windows, don't do anything to avoid
7876 * messing up those windows, better just redraw.
7880 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
7882 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
7883 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
7885 else if (wp
->w_next
)
7890 * if no lines deleted, blank the lines that will end up below the window
7895 wp
->w_redr_status
= TRUE
;
7897 redraw_cmdline
= TRUE
;
7898 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
7899 lastrow
= nextrow
+ line_count
;
7902 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
7903 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
7907 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
7910 /* deletion will have messed up other windows */
7914 wp
->w_redr_status
= TRUE
;
7916 win_rest_invalid(W_NEXT(wp
));
7925 * delete "line_count" window lines at "row" in window "wp"
7926 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
7927 * If "mayclear" is TRUE the screen will be cleared if it is faster than
7929 * Return OK for success, FAIL if the lines are not deleted.
7932 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
7942 wp
->w_lines_valid
= 0;
7944 if (line_count
> wp
->w_height
- row
)
7945 line_count
= wp
->w_height
- row
;
7947 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
7948 if (retval
!= MAYBE
)
7951 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
7952 (int)Rows
, FALSE
, NULL
) == FAIL
)
7957 * If there are windows or status lines below, try to put them at the
7958 * correct place. If we can't do that, they have to be redrawn.
7960 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
7962 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
7963 line_count
, (int)Rows
, NULL
) == FAIL
)
7965 wp
->w_redr_status
= TRUE
;
7966 win_rest_invalid(wp
->w_next
);
7970 * If this is the last window and there is no status line, redraw the
7971 * command line later.
7975 redraw_cmdline
= TRUE
;
7980 * Common code for win_ins_lines() and win_del_lines().
7981 * Returns OK or FAIL when the work has been done.
7982 * Returns MAYBE when not finished yet.
7985 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
7994 if (!redrawing() || line_count
<= 0)
7997 /* only a few lines left: redraw is faster */
7998 if (mayclear
&& Rows
- line_count
< 5
7999 #ifdef FEAT_VERTSPLIT
8000 && wp
->w_width
== Columns
8004 screenclear(); /* will set wp->w_lines_valid to 0 */
8009 * Delete all remaining lines
8011 if (row
+ line_count
>= wp
->w_height
)
8013 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8014 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8020 * when scrolling, the message on the command line should be cleared,
8021 * otherwise it will stay there forever.
8023 clear_cmdline
= TRUE
;
8026 * If the terminal can set a scroll region, use that.
8027 * Always do this in a vertically split window. This will redraw from
8028 * ScreenLines[] when t_CV isn't defined. That's faster than using
8030 * Don't use a scroll region when we are going to redraw the text, writing
8031 * a character in the lower right corner of the scroll region causes a
8032 * scroll-up in the DJGPP version.
8035 #ifdef FEAT_VERTSPLIT
8036 || W_WIDTH(wp
) != Columns
8040 #ifdef FEAT_VERTSPLIT
8041 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8043 scroll_region_set(wp
, row
);
8045 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8046 wp
->w_height
- row
, FALSE
, wp
);
8048 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8049 wp
->w_height
- row
, wp
);
8050 #ifdef FEAT_VERTSPLIT
8051 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8053 scroll_region_reset();
8058 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8066 * window 'wp' and everything after it is messed up, mark it for redraw
8069 win_rest_invalid(wp
)
8078 redraw_win_later(wp
, NOT_VALID
);
8080 wp
->w_redr_status
= TRUE
;
8084 redraw_cmdline
= TRUE
;
8088 * The rest of the routines in this file perform screen manipulations. The
8089 * given operation is performed physically on the screen. The corresponding
8090 * change is also made to the internal screen image. In this way, the editor
8091 * anticipates the effect of editing changes on the appearance of the screen.
8092 * That way, when we call screenupdate a complete redraw isn't usually
8093 * necessary. Another advantage is that we can keep adding code to anticipate
8094 * screen changes, and in the meantime, everything still works.
8098 * types for inserting or deleting lines
8108 #define USE_REDRAW 9
8111 * insert lines on the screen and update ScreenLines[]
8112 * 'end' is the line after the scrolled part. Normally it is Rows.
8113 * When scrolling region used 'off' is the offset from the top for the region.
8114 * 'row' and 'end' are relative to the start of the region.
8116 * return FAIL for failure, OK for success.
8119 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8124 win_T
*wp
; /* NULL or window to use width from */
8132 int can_ce
= can_clear(T_CE
);
8136 * - there is no valid screen
8137 * - the screen has to be redrawn completely
8138 * - the line count is less than one
8139 * - the line count is more than 'ttyscroll'
8141 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8145 * There are seven ways to insert lines:
8146 * 0. When in a vertically split window and t_CV isn't set, redraw the
8147 * characters from ScreenLines[].
8148 * 1. Use T_CD (clear to end of display) if it exists and the result of
8149 * the insert is just empty lines
8150 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8151 * present or line_count > 1. It looks better if we do all the inserts
8153 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8154 * insert is just empty lines and T_CE is not present or line_count >
8156 * 4. Use T_AL (insert line) if it exists.
8157 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8159 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8161 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8162 * the 'da' flag is not set or we have clear line capability.
8163 * 8. redraw the characters from ScreenLines[].
8165 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8166 * the scrollbar for the window. It does have insert line, use that if it
8169 result_empty
= (row
+ line_count
>= end
);
8170 #ifdef FEAT_VERTSPLIT
8171 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8175 if (can_clear(T_CD
) && result_empty
)
8177 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8179 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8181 else if (*T_AL
!= NUL
)
8183 else if (can_ce
&& result_empty
)
8185 else if (*T_DL
!= NUL
&& result_empty
)
8187 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8193 * For clearing the lines screen_del_lines() is used. This will also take
8194 * care of t_db if necessary.
8196 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8197 type
== USE_T_CE
|| type
== USE_T_DL
)
8198 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8201 * If text is retained below the screen, first clear or delete as many
8202 * lines at the bottom of the window as are about to be inserted so that
8203 * the deleted lines won't later surface during a screen_del_lines.
8206 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8208 #ifdef FEAT_CLIPBOARD
8209 /* Remove a modeless selection when inserting lines halfway the screen
8210 * or not the full width of the screen. */
8212 # ifdef FEAT_VERTSPLIT
8213 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8216 clip_clear_selection();
8218 clip_scroll_selection(-line_count
);
8222 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8223 * scrolling is actually carried out. */
8224 gui_dont_update_cursor();
8227 if (*T_CCS
!= NUL
) /* cursor relative to region */
8230 cursor_row
= row
+ off
;
8233 * Shift LineOffset[] line_count down to reflect the inserted lines.
8234 * Clear the inserted lines in ScreenLines[].
8238 for (i
= 0; i
< line_count
; ++i
)
8240 #ifdef FEAT_VERTSPLIT
8241 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8243 /* need to copy part of a line */
8245 while ((j
-= line_count
) >= row
)
8246 linecopy(j
+ line_count
, j
, wp
);
8248 if (can_clear((char_u
*)" "))
8249 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8251 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8252 LineWraps
[j
] = FALSE
;
8258 temp
= LineOffset
[j
];
8259 while ((j
-= line_count
) >= row
)
8261 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8262 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8264 LineOffset
[j
+ line_count
] = temp
;
8265 LineWraps
[j
+ line_count
] = FALSE
;
8266 if (can_clear((char_u
*)" "))
8267 lineclear(temp
, (int)Columns
);
8269 lineinvalid(temp
, (int)Columns
);
8273 screen_stop_highlight();
8274 windgoto(cursor_row
, 0);
8276 #ifdef FEAT_VERTSPLIT
8277 /* redraw the characters */
8278 if (type
== USE_REDRAW
)
8279 redraw_block(row
, end
, wp
);
8282 if (type
== USE_T_CAL
)
8284 term_append_lines(line_count
);
8285 screen_start(); /* don't know where cursor is now */
8289 for (i
= 0; i
< line_count
; i
++)
8291 if (type
== USE_T_AL
)
8293 if (i
&& cursor_row
!= 0)
8294 windgoto(cursor_row
, 0);
8297 else /* type == USE_T_SR */
8299 screen_start(); /* don't know where cursor is now */
8304 * With scroll-reverse and 'da' flag set we need to clear the lines that
8305 * have been scrolled down into the region.
8307 if (type
== USE_T_SR
&& *T_DA
)
8309 for (i
= 0; i
< line_count
; ++i
)
8311 windgoto(off
+ i
, 0);
8313 screen_start(); /* don't know where cursor is now */
8318 gui_can_update_cursor();
8320 out_flush(); /* always flush after a scroll */
8326 * delete lines on the screen and update ScreenLines[]
8327 * 'end' is the line after the scrolled part. Normally it is Rows.
8328 * When scrolling region used 'off' is the offset from the top for the region.
8329 * 'row' and 'end' are relative to the start of the region.
8331 * Return OK for success, FAIL if the lines are not deleted.
8335 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8340 int force
; /* even when line_count > p_ttyscroll */
8341 win_T
*wp
; /* NULL or window to use width from */
8348 int result_empty
; /* result is empty until end of region */
8349 int can_delete
; /* deleting line codes can be used */
8354 * - there is no valid screen
8355 * - the screen has to be redrawn completely
8356 * - the line count is less than one
8357 * - the line count is more than 'ttyscroll'
8359 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8360 (!force
&& line_count
> p_ttyscroll
))
8364 * Check if the rest of the current region will become empty.
8366 result_empty
= row
+ line_count
>= end
;
8369 * We can delete lines only when 'db' flag not set or when 'ce' option
8372 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8375 * There are six ways to delete lines:
8376 * 0. When in a vertically split window and t_CV isn't set, redraw the
8377 * characters from ScreenLines[].
8378 * 1. Use T_CD if it exists and the result is empty.
8379 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8380 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8381 * none of the other ways work.
8382 * 4. Use T_CE (erase line) if the result is empty.
8383 * 5. Use T_DL (delete line) if it exists.
8384 * 6. redraw the characters from ScreenLines[].
8386 #ifdef FEAT_VERTSPLIT
8387 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8391 if (can_clear(T_CD
) && result_empty
)
8393 #if defined(__BEOS__) && defined(BEOS_DR8)
8395 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8396 * its internal termcap... this works okay for tests which test *T_DB !=
8397 * NUL. It has the disadvantage that the user cannot use any :set t_*
8398 * command to get T_DB (back) to empty_option, only :set term=... will do
8400 * Anyway, this hack will hopefully go away with the next OS release.
8403 else if (row
== 0 && T_DB
== empty_option
8404 && (line_count
== 1 || *T_CDL
== NUL
))
8406 else if (row
== 0 && (
8408 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8409 * up, so use delete-line command */
8415 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8417 else if (can_clear(T_CE
) && result_empty
8418 #ifdef FEAT_VERTSPLIT
8419 && (wp
== NULL
|| wp
->w_width
== Columns
)
8423 else if (*T_DL
!= NUL
&& can_delete
)
8425 else if (*T_CDL
!= NUL
&& can_delete
)
8430 #ifdef FEAT_CLIPBOARD
8431 /* Remove a modeless selection when deleting lines halfway the screen or
8432 * not the full width of the screen. */
8434 # ifdef FEAT_VERTSPLIT
8435 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8438 clip_clear_selection();
8440 clip_scroll_selection(line_count
);
8444 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8445 * scrolling is actually carried out. */
8446 gui_dont_update_cursor();
8449 if (*T_CCS
!= NUL
) /* cursor relative to region */
8456 cursor_row
= row
+ off
;
8457 cursor_end
= end
+ off
;
8461 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8462 * Clear the inserted lines in ScreenLines[].
8466 for (i
= 0; i
< line_count
; ++i
)
8468 #ifdef FEAT_VERTSPLIT
8469 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8471 /* need to copy part of a line */
8473 while ((j
+= line_count
) <= end
- 1)
8474 linecopy(j
- line_count
, j
, wp
);
8476 if (can_clear((char_u
*)" "))
8477 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8479 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8480 LineWraps
[j
] = FALSE
;
8485 /* whole width, moving the line pointers is faster */
8487 temp
= LineOffset
[j
];
8488 while ((j
+= line_count
) <= end
- 1)
8490 LineOffset
[j
- line_count
] = LineOffset
[j
];
8491 LineWraps
[j
- line_count
] = LineWraps
[j
];
8493 LineOffset
[j
- line_count
] = temp
;
8494 LineWraps
[j
- line_count
] = FALSE
;
8495 if (can_clear((char_u
*)" "))
8496 lineclear(temp
, (int)Columns
);
8498 lineinvalid(temp
, (int)Columns
);
8502 screen_stop_highlight();
8504 #ifdef FEAT_VERTSPLIT
8505 /* redraw the characters */
8506 if (type
== USE_REDRAW
)
8507 redraw_block(row
, end
, wp
);
8510 if (type
== USE_T_CD
) /* delete the lines */
8512 windgoto(cursor_row
, 0);
8514 screen_start(); /* don't know where cursor is now */
8516 else if (type
== USE_T_CDL
)
8518 windgoto(cursor_row
, 0);
8519 term_delete_lines(line_count
);
8520 screen_start(); /* don't know where cursor is now */
8523 * Deleting lines at top of the screen or scroll region: Just scroll
8524 * the whole screen (scroll region) up by outputting newlines on the
8527 else if (type
== USE_NL
)
8529 windgoto(cursor_end
- 1, 0);
8530 for (i
= line_count
; --i
>= 0; )
8531 out_char('\n'); /* cursor will remain on same line */
8535 for (i
= line_count
; --i
>= 0; )
8537 if (type
== USE_T_DL
)
8539 windgoto(cursor_row
, 0);
8540 out_str(T_DL
); /* delete a line */
8542 else /* type == USE_T_CE */
8544 windgoto(cursor_row
+ i
, 0);
8545 out_str(T_CE
); /* erase a line */
8547 screen_start(); /* don't know where cursor is now */
8552 * If the 'db' flag is set, we need to clear the lines that have been
8553 * scrolled up at the bottom of the region.
8555 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8557 for (i
= line_count
; i
> 0; --i
)
8559 windgoto(cursor_end
- i
, 0);
8560 out_str(T_CE
); /* erase a line */
8561 screen_start(); /* don't know where cursor is now */
8566 gui_can_update_cursor();
8568 out_flush(); /* always flush after a scroll */
8575 * show the current mode and ruler
8577 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8578 * If clear_cmdline is FALSE there may be a message there that needs to be
8579 * cleared only if a mode is shown.
8580 * Return the length of the message (0 if no message).
8590 #ifdef FEAT_INS_EXPAND
8594 do_mode
= ((p_smd
&& msg_silent
== 0)
8595 && ((State
& INSERT
)
8601 if (do_mode
|| Recording
)
8604 * Don't show mode right now, when not redrawing or inside a mapping.
8605 * Call char_avail() only when we are going to show something, because
8606 * it takes a bit of time.
8608 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
8610 redraw_cmdline
= TRUE
; /* show mode later */
8614 nwr_save
= need_wait_return
;
8616 /* wait a bit before overwriting an important message */
8617 check_for_delay(FALSE
);
8619 /* if the cmdline is more than one line high, erase top lines */
8620 need_clear
= clear_cmdline
;
8621 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
8622 msg_clr_cmdline(); /* will reset clear_cmdline */
8624 /* Position on the last line in the window, column 0 */
8627 attr
= hl_attr(HLF_CM
); /* Highlight mode */
8630 MSG_PUTS_ATTR("--", attr
);
8631 #if defined(FEAT_XIM)
8632 if (xic
!= NULL
&& im_get_status() && !p_imdisable
8633 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
8634 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
8635 MSG_PUTS_ATTR(" IM", attr
);
8637 MSG_PUTS_ATTR(" XIM", attr
);
8640 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
8643 if (hangul_input_state_get())
8644 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
8647 #ifdef FEAT_INS_EXPAND
8648 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
8650 /* These messages can get long, avoid a wrap in a narrow
8651 * window. Prefer showing edit_submode_extra. */
8652 length
= (Rows
- msg_row
) * Columns
- 3;
8653 if (edit_submode_extra
!= NULL
)
8654 length
-= vim_strsize(edit_submode_extra
);
8657 if (edit_submode_pre
!= NULL
)
8658 length
-= vim_strsize(edit_submode_pre
);
8659 if (length
- vim_strsize(edit_submode
) > 0)
8661 if (edit_submode_pre
!= NULL
)
8662 msg_puts_attr(edit_submode_pre
, attr
);
8663 msg_puts_attr(edit_submode
, attr
);
8665 if (edit_submode_extra
!= NULL
)
8667 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
8668 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
8669 sub_attr
= hl_attr(edit_submode_highl
);
8672 msg_puts_attr(edit_submode_extra
, sub_attr
);
8680 #ifdef FEAT_VREPLACE
8681 if (State
& VREPLACE_FLAG
)
8682 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
8685 if (State
& REPLACE_FLAG
)
8686 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
8687 else if (State
& INSERT
)
8689 #ifdef FEAT_RIGHTLEFT
8691 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
8693 MSG_PUTS_ATTR(_(" INSERT"), attr
);
8695 else if (restart_edit
== 'I')
8696 MSG_PUTS_ATTR(_(" (insert)"), attr
);
8697 else if (restart_edit
== 'R')
8698 MSG_PUTS_ATTR(_(" (replace)"), attr
);
8699 else if (restart_edit
== 'V')
8700 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
8701 #ifdef FEAT_RIGHTLEFT
8703 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
8706 MSG_PUTS_ATTR(farsi_text_5
, attr
);
8710 if (State
& LANGMAP
)
8713 if (curwin
->w_p_arab
)
8714 MSG_PUTS_ATTR(_(" Arabic"), attr
);
8717 MSG_PUTS_ATTR(_(" (lang)"), attr
);
8720 if ((State
& INSERT
) && p_paste
)
8721 MSG_PUTS_ATTR(_(" (paste)"), attr
);
8728 /* Don't concatenate separate words to avoid translation
8730 switch ((VIsual_select
? 4 : 0)
8731 + (VIsual_mode
== Ctrl_V
) * 2
8732 + (VIsual_mode
== 'V'))
8734 case 0: p
= N_(" VISUAL"); break;
8735 case 1: p
= N_(" VISUAL LINE"); break;
8736 case 2: p
= N_(" VISUAL BLOCK"); break;
8737 case 4: p
= N_(" SELECT"); break;
8738 case 5: p
= N_(" SELECT LINE"); break;
8739 default: p
= N_(" SELECT BLOCK"); break;
8741 MSG_PUTS_ATTR(_(p
), attr
);
8744 MSG_PUTS_ATTR(" --", attr
);
8750 #ifdef FEAT_INS_EXPAND
8751 && edit_submode
== NULL
/* otherwise it gets too long */
8755 MSG_PUTS_ATTR(_("recording"), attr
);
8759 mode_displayed
= TRUE
;
8760 if (need_clear
|| clear_cmdline
)
8762 msg_didout
= FALSE
; /* overwrite this message */
8765 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
8767 else if (clear_cmdline
&& msg_silent
== 0)
8768 /* Clear the whole command line. Will reset "clear_cmdline". */
8771 #ifdef FEAT_CMDL_INFO
8773 /* In Visual mode the size of the selected area must be redrawn. */
8778 /* If the last window has no status line, the ruler is after the mode
8779 * message and must be redrawn */
8781 # ifdef FEAT_WINDOWS
8782 && lastwin
->w_status_height
== 0
8785 win_redr_ruler(lastwin
, TRUE
);
8787 redraw_cmdline
= FALSE
;
8788 clear_cmdline
= FALSE
;
8794 * Position for a mode message.
8804 * Delete mode message. Used when ESC is typed which is expected to end
8805 * Insert mode (but Insert mode didn't end yet!).
8806 * Caller should check "mode_displayed".
8813 * Don't delete it right now, when not redrawing or insided a mapping.
8815 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
8816 redraw_cmdline
= TRUE
; /* delete mode later */
8821 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
8826 #if defined(FEAT_WINDOWS)
8828 * Draw the tab pages line at the top of the Vim window.
8845 int attr_sel
= hl_attr(HLF_TPS
);
8846 int attr_nosel
= hl_attr(HLF_TP
);
8847 int attr_fill
= hl_attr(HLF_TPF
);
8850 int use_sep_chars
= (t_colors
< 8
8856 redraw_tabline
= FALSE
;
8858 #ifdef FEAT_GUI_TABLINE
8859 /* Take care of a GUI tabline. */
8860 if (gui_use_tabline())
8862 gui_update_tabline();
8867 if (tabline_height() < 1)
8870 #if defined(FEAT_STL_OPT)
8872 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
8873 for (scol
= 0; scol
< Columns
; ++scol
)
8874 TabPageIdxs
[scol
] = 0;
8876 /* Use the 'tabline' option if it's set. */
8879 int save_called_emsg
= called_emsg
;
8881 /* Check for an error. If there is one we would loop in redrawing the
8882 * screen. Avoid that by making 'tabline' empty. */
8883 called_emsg
= FALSE
;
8884 win_redr_custom(NULL
, FALSE
);
8886 set_string_option_direct((char_u
*)"tabline", -1,
8887 (char_u
*)"", OPT_FREE
, SID_ERROR
);
8888 called_emsg
|= save_called_emsg
;
8893 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
8896 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
8903 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
8908 if (tp
->tp_topframe
== topframe
)
8910 if (use_sep_chars
&& col
> 0)
8911 screen_putchar('|', 0, col
++, attr
);
8913 if (tp
->tp_topframe
!= topframe
)
8916 screen_putchar(' ', 0, col
++, attr
);
8925 cwp
= tp
->tp_curwin
;
8926 wp
= tp
->tp_firstwin
;
8930 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
8931 if (bufIsChanged(wp
->w_buffer
))
8933 if (modified
|| wincount
> 1)
8937 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
8938 len
= (int)STRLEN(NameBuff
);
8939 if (col
+ len
>= Columns
- 3)
8941 screen_puts_len(NameBuff
, len
, 0, col
,
8942 #if defined(FEAT_SYN_HL)
8943 hl_combine_attr(attr
, hl_attr(HLF_T
))
8951 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
8952 screen_putchar(' ', 0, col
++, attr
);
8955 room
= scol
- col
+ tabwidth
- 1;
8958 /* Get buffer name in NameBuff[] */
8959 get_trans_bufname(cwp
->w_buffer
);
8960 shorten_dir(NameBuff
);
8961 len
= vim_strsize(NameBuff
);
8967 len
-= ptr2cells(p
);
8977 if (len
> Columns
- col
- 1)
8978 len
= Columns
- col
- 1;
8980 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
8983 screen_putchar(' ', 0, col
++, attr
);
8985 /* Store the tab page number in TabPageIdxs[], so that
8986 * jump_to_mouse() knows where each one is. */
8989 TabPageIdxs
[scol
++] = tabcount
;
8996 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
8998 /* Put an "X" for closing the current tab if there are several. */
8999 if (first_tabpage
->tp_next
!= NULL
)
9001 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9002 TabPageIdxs
[Columns
- 1] = -999;
9006 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9008 redraw_tabline
= FALSE
;
9012 * Get buffer name for "buf" into NameBuff[].
9013 * Takes care of special buffer names and translates special characters.
9016 get_trans_bufname(buf
)
9019 if (buf_spname(buf
) != NULL
)
9020 STRCPY(NameBuff
, buf_spname(buf
));
9022 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9023 trans_characters(NameBuff
, MAXPATHL
);
9027 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9029 * Get the character to use in a status line. Get its attributes in "*attr".
9032 fillchar_status(attr
, is_curwin
)
9039 *attr
= hl_attr(HLF_S
);
9044 *attr
= hl_attr(HLF_SNC
);
9047 /* Use fill when there is highlighting, and highlighting of current
9048 * window differs, or the fillchars differ, or this is not the
9050 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9051 || !is_curwin
|| firstwin
== lastwin
)
9052 || (fill_stl
!= fill_stlnc
)))
9060 #ifdef FEAT_VERTSPLIT
9062 * Get the character to use in a separator between vertically split windows.
9063 * Get its attributes in "*attr".
9069 *attr
= hl_attr(HLF_C
);
9070 if (*attr
== 0 && fill_vert
== ' ')
9078 * Return TRUE if redrawing should currently be done.
9083 return (!RedrawingDisabled
9084 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9088 * Return TRUE if printing messages should currently be done.
9093 return (!(p_lz
&& char_avail() && !KeyTyped
));
9097 * Show current status info in ruler and various other places
9098 * If always is FALSE, only show ruler if position has changed.
9104 if (!always
&& !redrawing())
9106 #ifdef FEAT_INS_EXPAND
9109 # ifdef FEAT_WINDOWS
9110 /* Don't redraw right now, do it later. */
9111 curwin
->w_redr_status
= TRUE
;
9116 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9117 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9119 redraw_custum_statusline(curwin
);
9123 #ifdef FEAT_CMDL_INFO
9124 win_redr_ruler(curwin
, always
);
9129 # ifdef FEAT_STL_OPT
9130 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9131 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9138 #ifdef FEAT_CMDL_INFO
9140 win_redr_ruler(wp
, always
)
9148 int empty_line
= FALSE
;
9152 #ifdef FEAT_VERTSPLIT
9155 int width
= Columns
;
9156 # define WITH_OFF(x) x
9157 # define WITH_WIDTH(x) x
9159 # define WITH_OFF(x) 0
9160 # define WITH_WIDTH(x) Columns
9161 # define this_ru_col ru_col
9164 /* If 'ruler' off or redrawing disabled, don't do anything */
9169 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9170 * after deleting lines, before cursor.lnum is corrected.
9172 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9175 #ifdef FEAT_INS_EXPAND
9176 /* Don't draw the ruler while doing insert-completion, it might overwrite
9177 * the (long) mode message. */
9178 # ifdef FEAT_WINDOWS
9179 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9181 if (edit_submode
!= NULL
)
9183 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9191 int save_called_emsg
= called_emsg
;
9193 called_emsg
= FALSE
;
9194 win_redr_custom(wp
, TRUE
);
9196 set_string_option_direct((char_u
*)"rulerformat", -1,
9197 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9198 called_emsg
|= save_called_emsg
;
9204 * Check if not in Insert mode and the line is empty (will show "0-1").
9206 if (!(State
& INSERT
)
9207 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9211 * Only draw the ruler when something changed.
9213 validate_virtcol_win(wp
);
9216 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9217 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9218 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9219 #ifdef FEAT_VIRTUALEDIT
9220 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9222 || wp
->w_topline
!= wp
->w_ru_topline
9223 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9225 || wp
->w_topfill
!= wp
->w_ru_topfill
9227 || empty_line
!= wp
->w_ru_empty
)
9231 if (wp
->w_status_height
)
9233 row
= W_WINROW(wp
) + wp
->w_height
;
9234 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9235 # ifdef FEAT_VERTSPLIT
9237 width
= W_WIDTH(wp
);
9246 #ifdef FEAT_VERTSPLIT
9252 /* In list mode virtcol needs to be recomputed */
9253 virtcol
= wp
->w_virtcol
;
9254 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9256 wp
->w_p_list
= FALSE
;
9257 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9258 wp
->w_p_list
= TRUE
;
9262 * Some sprintfs return the length, some return a pointer.
9263 * To avoid portability problems we use strlen() here.
9265 sprintf((char *)buffer
, "%ld,",
9266 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9268 : (long)(wp
->w_cursor
.lnum
));
9269 col_print(buffer
+ STRLEN(buffer
),
9270 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9274 * Add a "50%" if there is room for it.
9275 * On the last line, don't print in the last column (scrolls the
9276 * screen up on some terminals).
9278 i
= (int)STRLEN(buffer
);
9279 get_rel_pos(wp
, buffer
+ i
+ 1);
9280 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9282 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9285 #ifdef FEAT_VERTSPLIT
9286 this_ru_col
= ru_col
- (Columns
- width
);
9287 if (this_ru_col
< 0)
9290 /* Never use more than half the window/screen width, leave the other
9291 * half for the filename. */
9292 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9293 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9294 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9296 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9300 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9303 buffer
[i
++] = fillchar
;
9306 get_rel_pos(wp
, buffer
+ i
);
9308 /* Truncate at window boundary. */
9313 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9315 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9316 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9325 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9326 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9328 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9330 screen_fill(row
, row
+ 1,
9331 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9332 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9333 fillchar
, fillchar
, attr
);
9334 /* don't redraw the cmdline because of showing the ruler */
9336 wp
->w_ru_cursor
= wp
->w_cursor
;
9337 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9338 wp
->w_ru_empty
= empty_line
;
9339 wp
->w_ru_topline
= wp
->w_topline
;
9340 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9342 wp
->w_ru_topfill
= wp
->w_topfill
;
9348 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9350 * Return the width of the 'number' column.
9351 * Caller may need to check if 'number' is set.
9352 * Otherwise it depends on 'numberwidth' and the line count.
9361 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9362 if (lnum
== wp
->w_nrwidth_line_count
)
9363 return wp
->w_nrwidth_width
;
9364 wp
->w_nrwidth_line_count
= lnum
;
9373 /* 'numberwidth' gives the minimal width plus one */
9374 if (n
< wp
->w_p_nuw
- 1)
9375 n
= wp
->w_p_nuw
- 1;
9377 wp
->w_nrwidth_width
= n
;