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 and
29 * ScreenLinesC[][] is not used. When the character occupies two display
30 * cells the next byte in ScreenLines[] is 0.
31 * ScreenLinesC[][] contain up to 'maxcombine' composing characters
32 * (drawn on top of the first character). There is 0 after the last one used.
33 * ScreenLines2[] is only used for euc-jp to store the second byte if the
34 * first byte is 0x8e (single-width character).
36 * The screen_*() functions write to the screen and handle updating
39 * update_screen() is the function that updates all windows and status lines.
40 * It is called form the main loop when must_redraw is non-zero. It may be
41 * called from other places when an immediate screen update is needed.
43 * The part of the buffer that is displayed in a window is set with:
44 * - w_topline (first buffer line in window)
45 * - w_topfill (filler line above the first line)
46 * - w_leftcol (leftmost window cell in window),
47 * - w_skipcol (skipped window cells of first line)
49 * Commands that only move the cursor around in a window, do not need to take
50 * action to update the display. The main loop will check if w_topline is
51 * valid and update it (scroll the window) when needed.
53 * Commands that scroll a window change w_topline and must call
54 * check_cursor() to move the cursor into the visible part of the window, and
55 * call redraw_later(VALID) to have the window displayed by update_screen()
58 * Commands that change text in the buffer must call changed_bytes() or
59 * changed_lines() to mark the area that changed and will require updating
60 * later. The main loop will call update_screen(), which will update each
61 * window that shows the changed buffer. This assumes text above the change
62 * can remain displayed as it is. Text after the change may need updating for
63 * scrolling, folding and syntax highlighting.
65 * Commands that change how a window is displayed (e.g., setting 'list') or
66 * invalidate the contents of a window in another way (e.g., change fold
67 * settings), must call redraw_later(NOT_VALID) to have the whole window
68 * redisplayed by update_screen() later.
70 * Commands that change how a buffer is displayed (e.g., setting 'tabstop')
71 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the
72 * buffer redisplayed by update_screen() later.
74 * Commands that change highlighting and possibly cause a scroll too must call
75 * redraw_later(SOME_VALID) to update the whole window but still use scrolling
76 * to avoid redrawing everything. But the length of displayed lines must not
77 * change, use NOT_VALID then.
79 * Commands that move the window position must call redraw_later(NOT_VALID).
80 * TODO: should minimize redrawing by scrolling when possible.
82 * Commands that change everything (e.g., resizing the screen) must call
83 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR).
85 * Things that are handled indirectly:
86 * - When messages scroll the screen up, msg_scrolled will be set and
87 * update_screen() called to redraw.
93 * The attributes that are actually active for writing to the screen.
95 static int screen_attr
= 0;
98 * Positioning the cursor is reduced by remembering the last position.
99 * Mostly used by windgoto() and screen_char().
101 static int screen_cur_row
, screen_cur_col
; /* last known cursor position */
103 #ifdef FEAT_SEARCH_EXTRA
104 static match_T search_hl
; /* used for 'hlsearch' highlight matching */
108 static foldinfo_T win_foldinfo
; /* info for 'foldcolumn' */
112 * Buffer for one screen line (characters and attributes).
114 static schar_T
*current_ScreenLine
;
116 static void win_update
__ARGS((win_T
*wp
));
117 static void win_draw_end
__ARGS((win_T
*wp
, int c1
, int c2
, int row
, int endrow
, hlf_T hl
));
119 static void fold_line
__ARGS((win_T
*wp
, long fold_count
, foldinfo_T
*foldinfo
, linenr_T lnum
, int row
));
120 static void fill_foldcolumn
__ARGS((char_u
*p
, win_T
*wp
, int closed
, linenr_T lnum
));
121 static void copy_text_attr
__ARGS((int off
, char_u
*buf
, int len
, int attr
));
123 static int win_line
__ARGS((win_T
*, linenr_T
, int, int, int nochange
));
124 static int char_needs_redraw
__ARGS((int off_from
, int off_to
, int cols
));
125 #ifdef FEAT_RIGHTLEFT
126 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
, int rlflag
));
127 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl))
129 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
));
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c))
132 #ifdef FEAT_VERTSPLIT
133 static void draw_vsep_win
__ARGS((win_T
*wp
, int row
));
136 static void redraw_custom_statusline
__ARGS((win_T
*wp
));
138 #ifdef FEAT_SEARCH_EXTRA
139 #define SEARCH_HL_PRIORITY 0
140 static void start_search_hl
__ARGS((void));
141 static void end_search_hl
__ARGS((void));
142 static void prepare_search_hl
__ARGS((win_T
*wp
, linenr_T lnum
));
143 static void next_search_hl
__ARGS((win_T
*win
, match_T
*shl
, linenr_T lnum
, colnr_T mincol
));
145 static void screen_start_highlight
__ARGS((int attr
));
146 static void screen_char
__ARGS((unsigned off
, int row
, int col
));
148 static void screen_char_2
__ARGS((unsigned off
, int row
, int col
));
150 static void screenclear2
__ARGS((void));
151 static void lineclear
__ARGS((unsigned off
, int width
));
152 static void lineinvalid
__ARGS((unsigned off
, int width
));
153 #ifdef FEAT_VERTSPLIT
154 static void linecopy
__ARGS((int to
, int from
, win_T
*wp
));
155 static void redraw_block
__ARGS((int row
, int end
, win_T
*wp
));
157 static int win_do_lines
__ARGS((win_T
*wp
, int row
, int line_count
, int mayclear
, int del
));
158 static void win_rest_invalid
__ARGS((win_T
*wp
));
159 static void msg_pos_mode
__ARGS((void));
160 #if defined(FEAT_WINDOWS)
161 static void draw_tabline
__ARGS((void));
163 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
164 static int fillchar_status
__ARGS((int *attr
, int is_curwin
));
166 #ifdef FEAT_VERTSPLIT
167 static int fillchar_vsep
__ARGS((int *attr
));
170 static void win_redr_custom
__ARGS((win_T
*wp
, int draw_ruler
));
172 #ifdef FEAT_CMDL_INFO
173 static void win_redr_ruler
__ARGS((win_T
*wp
, int always
));
176 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
177 /* Ugly global: overrule attribute used by screen_char() */
178 static int screen_char_attr
= 0;
182 * Redraw the current window later, with update_screen(type).
183 * Set must_redraw only if not already set to a higher value.
184 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
190 redraw_win_later(curwin
, type
);
194 redraw_win_later(wp
, type
)
198 if (wp
->w_redr_type
< type
)
200 wp
->w_redr_type
= type
;
201 if (type
>= NOT_VALID
)
202 wp
->w_lines_valid
= 0;
203 if (must_redraw
< type
) /* must_redraw is the maximum of all windows */
209 * Force a complete redraw later. Also resets the highlighting. To be used
210 * after executing a shell command that messes up the screen.
215 redraw_all_later(CLEAR
);
218 /* Use a code that will reset gui.highlight_mask in
219 * gui_stop_highlight(). */
220 screen_attr
= HL_ALL
+ 1;
223 /* Use attributes that is very unlikely to appear in text. */
224 screen_attr
= HL_BOLD
| HL_UNDERLINE
| HL_INVERSE
;
228 * Mark all windows to be redrawn later.
231 redraw_all_later(type
)
238 redraw_win_later(wp
, type
);
243 * Mark all windows that are editing the current buffer to be updated later.
246 redraw_curbuf_later(type
)
249 redraw_buf_later(curbuf
, type
);
253 redraw_buf_later(buf
, type
)
261 if (wp
->w_buffer
== buf
)
262 redraw_win_later(wp
, type
);
267 * Changed something in the current window, at buffer line "lnum", that
268 * requires that line and possibly other lines to be redrawn.
269 * Used when entering/leaving Insert mode with the cursor on a folded line.
270 * Used to remove the "$" from a change command.
271 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
272 * may become invalid and the whole window will have to be redrawn.
275 redrawWinline(lnum
, invalid
)
277 int invalid UNUSED
; /* window line height is invalid now */
283 if (curwin
->w_redraw_top
== 0 || curwin
->w_redraw_top
> lnum
)
284 curwin
->w_redraw_top
= lnum
;
285 if (curwin
->w_redraw_bot
== 0 || curwin
->w_redraw_bot
< lnum
)
286 curwin
->w_redraw_bot
= lnum
;
292 /* A w_lines[] entry for this lnum has become invalid. */
293 i
= find_wl_entry(curwin
, lnum
);
295 curwin
->w_lines
[i
].wl_valid
= FALSE
;
301 * update all windows that are editing the current buffer
307 redraw_curbuf_later(type
);
314 * Based on the current value of curwin->w_topline, transfer a screenfull
315 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
322 static int did_intro
= FALSE
;
323 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
327 /* Don't do anything if the screen structures are (not yet) valid. */
328 if (!screen_valid(TRUE
))
333 if (type
< must_redraw
) /* use maximal type */
336 /* must_redraw is reset here, so that when we run into some weird
337 * reason to redraw while busy redrawing (e.g., asynchronous
338 * scrolling), or update_topline() in win_update() will cause a
339 * scroll, the screen will be redrawn later or in win_update(). */
343 /* Need to update w_lines[]. */
344 if (curwin
->w_lines_valid
== 0 && type
< NOT_VALID
)
347 /* Postpone the redrawing when it's not needed and when being called
349 if (!redrawing() || updating_screen
)
351 redraw_later(type
); /* remember type for next time */
353 if (type
> INVERTED_ALL
)
354 curwin
->w_lines_valid
= 0; /* don't use w_lines[].wl_size now */
358 updating_screen
= TRUE
;
360 ++display_tick
; /* let syntax code know we're in a next round of
361 * display updating */
365 * if the screen was scrolled up when displaying a message, scroll it down
369 clear_cmdline
= TRUE
;
370 if (msg_scrolled
> Rows
- 5) /* clearing is faster */
372 else if (type
!= CLEAR
)
374 check_for_delay(FALSE
);
375 if (screen_ins_lines(0, 0, msg_scrolled
, (int)Rows
, NULL
) == FAIL
)
379 if (W_WINROW(wp
) < msg_scrolled
)
381 if (W_WINROW(wp
) + wp
->w_height
> msg_scrolled
382 && wp
->w_redr_type
< REDRAW_TOP
383 && wp
->w_lines_valid
> 0
384 && wp
->w_topline
== wp
->w_lines
[0].wl_lnum
)
386 wp
->w_upd_rows
= msg_scrolled
- W_WINROW(wp
);
387 wp
->w_redr_type
= REDRAW_TOP
;
391 wp
->w_redr_type
= NOT_VALID
;
393 if (W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
)
395 wp
->w_redr_status
= TRUE
;
400 redraw_cmdline
= TRUE
;
402 redraw_tabline
= TRUE
;
406 need_wait_return
= FALSE
;
409 /* reset cmdline_row now (may have been changed temporarily) */
412 /* Check for changed highlighting */
413 if (need_highlight_changed
)
416 if (type
== CLEAR
) /* first clear screen */
418 screenclear(); /* will reset clear_cmdline */
422 if (clear_cmdline
) /* going to clear cmdline (done below) */
423 check_for_delay(FALSE
);
425 #ifdef FEAT_LINEBREAK
426 /* Force redraw when width of 'number' or 'relativenumber' column
428 if (curwin
->w_redr_type
< NOT_VALID
429 && curwin
->w_nrwidth
!= ((curwin
->w_p_nu
|| curwin
->w_p_rnu
)
430 ? number_width(curwin
) : 0))
431 curwin
->w_redr_type
= NOT_VALID
;
435 * Only start redrawing if there is really something to do.
437 if (type
== INVERTED
)
439 if (curwin
->w_redr_type
< type
441 && curwin
->w_lines
[0].wl_valid
443 && curwin
->w_topfill
== curwin
->w_old_topfill
444 && curwin
->w_botfill
== curwin
->w_old_botfill
446 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
450 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
451 && curwin
->w_old_visual_mode
== VIsual_mode
452 && (curwin
->w_valid
& VALID_VIRTCOL
)
453 && curwin
->w_old_curswant
== curwin
->w_curswant
)
456 curwin
->w_redr_type
= type
;
459 /* Redraw the tab pages line if needed. */
460 if (redraw_tabline
|| type
>= NOT_VALID
)
466 * Correct stored syntax highlighting info for changes in each displayed
467 * buffer. Each buffer must only be done once.
471 if (wp
->w_buffer
->b_mod_set
)
476 /* Check if we already did this buffer. */
477 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
478 if (wwp
->w_buffer
== wp
->w_buffer
)
485 syntax_present(wp
->w_buffer
))
486 syn_stack_apply_changes(wp
->w_buffer
);
492 * Go from top to bottom through the windows, redrawing the ones that need
495 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
498 #ifdef FEAT_SEARCH_EXTRA
499 search_hl
.rm
.regprog
= NULL
;
503 if (wp
->w_redr_type
!= 0)
506 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
510 # ifdef FEAT_SEARCH_EXTRA
513 # ifdef FEAT_CLIPBOARD
514 /* When Visual area changed, may have to update selection. */
515 if (clip_star
.available
&& clip_isautosel())
516 clip_update_selection();
519 /* Remove the cursor before starting to do anything, because
520 * scrolling may make it difficult to redraw the text under
531 /* redraw status line after the window to minimize cursor movement */
532 if (wp
->w_redr_status
)
539 #if defined(FEAT_SEARCH_EXTRA)
544 /* Reset b_mod_set flags. Going through all windows is probably faster
545 * than going through all buffers (there could be many buffers). */
546 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
547 wp
->w_buffer
->b_mod_set
= FALSE
;
549 curbuf
->b_mod_set
= FALSE
;
552 updating_screen
= FALSE
;
554 gui_may_resize_shell();
557 /* Clear or redraw the command line. Done last, because scrolling may
558 * mess up the command line. */
559 if (clear_cmdline
|| redraw_cmdline
)
562 /* May put up an introductory message when not editing a file */
563 if (!did_intro
&& bufempty()
564 && curbuf
->b_fname
== NULL
566 && firstwin
->w_next
== NULL
568 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
569 intro_message(FALSE
);
573 /* Redraw the cursor and update the scrollbars when all screen updating is
577 out_flush(); /* required before updating the cursor */
579 gui_update_cursor(FALSE
, FALSE
);
580 gui_update_scrollbars(FALSE
);
585 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
586 static void update_prepare
__ARGS((void));
587 static void update_finish
__ARGS((void));
590 * Prepare for updating one or more windows.
591 * Caller must check for "updating_screen" already set to avoid recursiveness.
597 updating_screen
= TRUE
;
599 /* Remove the cursor before starting to do anything, because scrolling may
600 * make it difficult to redraw the text under it. */
604 #ifdef FEAT_SEARCH_EXTRA
610 * Finish updating one or more windows.
618 # ifdef FEAT_SEARCH_EXTRA
622 updating_screen
= FALSE
;
625 gui_may_resize_shell();
627 /* Redraw the cursor and update the scrollbars when all screen updating is
631 out_flush(); /* required before updating the cursor */
632 gui_update_cursor(FALSE
, FALSE
);
633 gui_update_scrollbars(FALSE
);
639 #if defined(FEAT_SIGNS) || defined(PROTO)
641 update_debug_sign(buf
, lnum
)
649 win_foldinfo
.fi_level
= 0;
652 /* update/delete a specific mark */
655 if (buf
!= NULL
&& lnum
> 0)
657 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
658 && lnum
< wp
->w_botline
)
660 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
661 wp
->w_redraw_top
= lnum
;
662 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
663 wp
->w_redraw_bot
= lnum
;
664 redraw_win_later(wp
, VALID
);
668 redraw_win_later(wp
, VALID
);
669 if (wp
->w_redr_type
!= 0)
673 /* Return when there is nothing to do or screen updating already
675 if (!doit
|| updating_screen
)
678 /* update all windows that need updating */
682 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
684 if (wp
->w_redr_type
!= 0)
686 if (wp
->w_redr_status
)
690 if (curwin
->w_redr_type
!= 0)
699 #if defined(FEAT_GUI) || defined(PROTO)
701 * Update a single window, its status line and maybe the command line msg.
702 * Used for the GUI scrollbar.
708 /* return if already busy updating */
714 #ifdef FEAT_CLIPBOARD
715 /* When Visual area changed, may have to update selection. */
716 if (clip_star
.available
&& clip_isautosel())
717 clip_update_selection();
723 /* When the screen was cleared redraw the tab pages line. */
727 if (wp
->w_redr_status
728 # ifdef FEAT_CMDL_INFO
732 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
743 * Update a single window.
745 * This may cause the windows below it also to be redrawn (when clearing the
746 * screen or scrolling lines).
748 * How the window is redrawn depends on wp->w_redr_type. Each type also
749 * implies the one below it.
750 * NOT_VALID redraw the whole window
751 * SOME_VALID redraw the whole window but do scroll when possible
752 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
753 * INVERTED redraw the changed part of the Visual area
754 * INVERTED_ALL redraw the whole Visual area
755 * VALID 1. scroll up/down to adjust for a changed w_topline
756 * 2. update lines at the top when scrolled down
757 * 3. redraw changed text:
758 * - if wp->w_buffer->b_mod_set set, update lines between
759 * b_mod_top and b_mod_bot.
760 * - if wp->w_redraw_top non-zero, redraw lines between
761 * wp->w_redraw_top and wp->w_redr_bot.
762 * - continue redrawing when syntax status is invalid.
763 * 4. if scrolled up, update lines at the bottom.
764 * This results in three areas that may need updating:
765 * top: from first row to top_end (when scrolled down)
766 * mid: from mid_start to mid_end (update inversion or changed text)
767 * bot: from bot_start to last row (when scrolled up)
773 buf_T
*buf
= wp
->w_buffer
;
775 int top_end
= 0; /* Below last row of the top area that needs
776 updating. 0 when no top area updating. */
777 int mid_start
= 999;/* first row of the mid area that needs
778 updating. 999 when no mid area updating. */
779 int mid_end
= 0; /* Below last row of the mid area that needs
780 updating. 0 when no mid area updating. */
781 int bot_start
= 999;/* first row of the bot area that needs
782 updating. 999 when no bot area updating */
784 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
785 w_topline got smaller a bit */
787 #ifdef FEAT_SEARCH_EXTRA
788 matchitem_T
*cur
; /* points to the match list */
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 cur
= wp
->w_match_head
;
855 cur
->hl
.rm
= cur
->match
;
856 if (cur
->hlg_id
== 0)
859 cur
->hl
.attr
= syn_id2attr(cur
->hlg_id
);
862 cur
->hl
.first_lnum
= 0;
864 /* Set the time limit to 'redrawtime'. */
865 profile_setlimit(p_rdt
, &(cur
->hl
.tm
));
871 search_hl
.first_lnum
= 0;
872 /* time limit is set at the toplevel, for all windows */
875 #ifdef FEAT_LINEBREAK
876 /* Force redraw when width of 'number' or 'relativenumber' column
878 i
= (wp
->w_p_nu
|| wp
->w_p_rnu
) ? number_width(wp
) : 0;
879 if (wp
->w_nrwidth
!= i
)
887 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
890 * When there are both inserted/deleted lines and specific lines to be
891 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
892 * everything (only happens when redrawing is off for while).
899 * Set mod_top to the first line that needs displaying because of
900 * changes. Set mod_bot to the first line after the changes.
902 mod_top
= wp
->w_redraw_top
;
903 if (wp
->w_redraw_bot
!= 0)
904 mod_bot
= wp
->w_redraw_bot
+ 1;
907 wp
->w_redraw_top
= 0; /* reset for next time */
908 wp
->w_redraw_bot
= 0;
911 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
913 mod_top
= buf
->b_mod_top
;
915 /* Need to redraw lines above the change that may be included
916 * in a pattern match. */
917 if (syntax_present(buf
))
919 mod_top
-= buf
->b_syn_sync_linebreaks
;
925 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
926 mod_bot
= buf
->b_mod_bot
;
928 #ifdef FEAT_SEARCH_EXTRA
929 /* When 'hlsearch' is on and using a multi-line search pattern, a
930 * change in one line may make the Search highlighting in a
931 * previous line invalid. Simple solution: redraw all visible
932 * lines above the change.
933 * Same for a match pattern.
935 if (search_hl
.rm
.regprog
!= NULL
936 && re_multiline(search_hl
.rm
.regprog
))
940 cur
= wp
->w_match_head
;
943 if (cur
->match
.regprog
!= NULL
944 && re_multiline(cur
->match
.regprog
))
955 if (mod_top
!= 0 && hasAnyFolding(wp
))
957 linenr_T lnumt
, lnumb
;
960 * A change in a line can cause lines above it to become folded or
961 * unfolded. Find the top most buffer line that may be affected.
962 * If the line was previously folded and displayed, get the first
963 * line of that fold. If the line is folded now, get the first
964 * folded line. Use the minimum of these two.
967 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
968 * the line below it. If there is no valid entry, use w_topline.
969 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
970 * to this line. If there is no valid entry, use MAXLNUM. */
971 lnumt
= wp
->w_topline
;
973 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
974 if (wp
->w_lines
[i
].wl_valid
)
976 if (wp
->w_lines
[i
].wl_lastlnum
< mod_top
)
977 lnumt
= wp
->w_lines
[i
].wl_lastlnum
+ 1;
978 if (lnumb
== MAXLNUM
&& wp
->w_lines
[i
].wl_lnum
>= mod_bot
)
980 lnumb
= wp
->w_lines
[i
].wl_lnum
;
981 /* When there is a fold column it might need updating
982 * in the next line ("J" just above an open fold). */
988 (void)hasFoldingWin(wp
, mod_top
, &mod_top
, NULL
, TRUE
, NULL
);
992 /* Now do the same for the bottom line (one above mod_bot). */
994 (void)hasFoldingWin(wp
, mod_bot
, NULL
, &mod_bot
, TRUE
, NULL
);
1001 /* When a change starts above w_topline and the end is below
1002 * w_topline, start redrawing at w_topline.
1003 * If the end of the change is above w_topline: do like no change was
1004 * made, but redraw the first line to find changes in syntax. */
1005 if (mod_top
!= 0 && mod_top
< wp
->w_topline
)
1007 if (mod_bot
> wp
->w_topline
)
1008 mod_top
= wp
->w_topline
;
1010 else if (syntax_present(buf
))
1015 /* When line numbers are displayed need to redraw all lines below
1016 * inserted/deleted lines. */
1017 if (mod_top
!= 0 && buf
->b_mod_xlines
!= 0 && wp
->w_p_nu
)
1022 * When only displaying the lines at the top, set top_end. Used when
1023 * window has scrolled down for msg_scrolled.
1025 if (type
== REDRAW_TOP
)
1028 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
1030 j
+= wp
->w_lines
[i
].wl_size
;
1031 if (j
>= wp
->w_upd_rows
)
1038 /* not found (cannot happen?): redraw everything */
1041 /* top area defined, the rest is VALID */
1045 /* Trick: we want to avoid clearing the screen twice. screenclear() will
1046 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1047 * non-zero and thus not FALSE) will indicate that screenclear() was not
1050 screen_cleared
= MAYBE
;
1053 * If there are no changes on the screen that require a complete redraw,
1054 * handle three cases:
1055 * 1: we are off the top of the screen by a few lines: scroll down
1056 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1057 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1058 * w_lines[] that needs updating.
1060 if ((type
== VALID
|| type
== SOME_VALID
1061 || type
== INVERTED
|| type
== INVERTED_ALL
)
1063 && !wp
->w_botfill
&& !wp
->w_old_botfill
1067 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1070 * w_topline is the first changed line, the scrolling will be done
1074 else if (wp
->w_lines
[0].wl_valid
1075 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1077 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1078 && wp
->w_topfill
> wp
->w_old_topfill
)
1083 * New topline is above old topline: May scroll down.
1086 if (hasAnyFolding(wp
))
1090 /* count the number of lines we are off, counting a sequence
1091 * of folded lines as one */
1093 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1096 if (j
>= wp
->w_height
- 2)
1098 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1103 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1104 if (j
< wp
->w_height
- 2) /* not too far off */
1106 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1108 /* insert extra lines for previously invisible filler lines */
1109 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1110 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1111 - wp
->w_old_topfill
;
1113 if (i
< wp
->w_height
- 2) /* less than a screen off */
1116 * Try to insert the correct number of lines.
1117 * If not the last window, delete the lines at the bottom.
1118 * win_ins_lines may fail when the terminal can't do it.
1121 check_for_delay(FALSE
);
1122 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1124 if (wp
->w_lines_valid
!= 0)
1126 /* Need to update rows that are new, stop at the
1127 * first one that scrolled down. */
1130 scrolled_down
= TRUE
;
1133 /* Move the entries that were scrolled, disable
1134 * the entries for the lines to be redrawn. */
1135 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1136 wp
->w_lines_valid
= wp
->w_height
;
1137 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1138 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1140 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1144 mid_start
= 0; /* redraw all lines */
1147 mid_start
= 0; /* redraw all lines */
1150 mid_start
= 0; /* redraw all lines */
1155 * New topline is at or below old topline: May scroll up.
1156 * When topline didn't change, find first entry in w_lines[] that
1160 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1163 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1165 if (wp
->w_lines
[i
].wl_valid
1166 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1171 row
+= wp
->w_lines
[i
].wl_size
;
1175 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1182 * Try to delete the correct number of lines.
1183 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1186 /* If the topline didn't change, delete old filler lines,
1187 * otherwise delete filler lines of the new topline... */
1188 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1189 row
+= wp
->w_old_topfill
;
1191 row
+= diff_check_fill(wp
, wp
->w_topline
);
1192 /* ... but don't delete new filler lines. */
1193 row
-= wp
->w_topfill
;
1197 check_for_delay(FALSE
);
1198 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1199 bot_start
= wp
->w_height
- row
;
1201 mid_start
= 0; /* redraw all lines */
1203 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1206 * Skip the lines (below the deleted lines) that are still
1207 * valid and don't need redrawing. Copy their info
1208 * upwards, to compensate for the deleted lines. Set
1209 * bot_start to the first row that needs redrawing.
1215 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1216 /* stop at line that didn't fit, unless it is still
1217 * valid (no lines deleted) */
1218 if (row
> 0 && bot_start
+ row
1219 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1221 wp
->w_lines_valid
= idx
+ 1;
1224 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1226 /* stop at the last valid entry in w_lines[].wl_size */
1227 if (++j
>= wp
->w_lines_valid
)
1229 wp
->w_lines_valid
= idx
;
1234 /* Correct the first entry for filler lines at the top
1235 * when it won't get updated below. */
1236 if (wp
->w_p_diff
&& bot_start
> 0)
1237 wp
->w_lines
[0].wl_size
=
1238 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1245 /* When starting redraw in the first line, redraw all lines. When
1246 * there is only one window it's probably faster to clear the screen
1250 mid_end
= wp
->w_height
;
1251 if (lastwin
== firstwin
)
1253 /* Clear the screen when it was not done by win_del_lines() or
1254 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1256 if (screen_cleared
!= TRUE
)
1259 /* The screen was cleared, redraw the tab pages line. */
1266 /* When win_del_lines() or win_ins_lines() caused the screen to be
1267 * cleared (only happens for the first window) or when screenclear()
1268 * was called directly above, "must_redraw" will have been set to
1269 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1270 if (screen_cleared
== TRUE
)
1275 /* Not VALID or INVERTED: redraw all lines. */
1277 mid_end
= wp
->w_height
;
1280 if (type
== SOME_VALID
)
1282 /* SOME_VALID: redraw all lines. */
1284 mid_end
= wp
->w_height
;
1289 /* check if we are updating or removing the inverted part */
1290 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1291 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1298 && (VIsual_mode
!= wp
->w_old_visual_mode
1299 || type
== INVERTED_ALL
))
1302 * If the type of Visual selection changed, redraw the whole
1303 * selection. Also when the ownership of the X selection is
1306 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1308 from
= curwin
->w_cursor
.lnum
;
1314 to
= curwin
->w_cursor
.lnum
;
1316 /* redraw more when the cursor moved as well */
1317 if (wp
->w_old_cursor_lnum
< from
)
1318 from
= wp
->w_old_cursor_lnum
;
1319 if (wp
->w_old_cursor_lnum
> to
)
1320 to
= wp
->w_old_cursor_lnum
;
1321 if (wp
->w_old_visual_lnum
< from
)
1322 from
= wp
->w_old_visual_lnum
;
1323 if (wp
->w_old_visual_lnum
> to
)
1324 to
= wp
->w_old_visual_lnum
;
1329 * Find the line numbers that need to be updated: The lines
1330 * between the old cursor position and the current cursor
1331 * position. Also check if the Visual position changed.
1333 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1335 from
= curwin
->w_cursor
.lnum
;
1336 to
= wp
->w_old_cursor_lnum
;
1340 from
= wp
->w_old_cursor_lnum
;
1341 to
= curwin
->w_cursor
.lnum
;
1342 if (from
== 0) /* Visual mode just started */
1346 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1347 || VIsual
.col
!= wp
->w_old_visual_col
)
1349 if (wp
->w_old_visual_lnum
< from
1350 && wp
->w_old_visual_lnum
!= 0)
1351 from
= wp
->w_old_visual_lnum
;
1352 if (wp
->w_old_visual_lnum
> to
)
1353 to
= wp
->w_old_visual_lnum
;
1354 if (VIsual
.lnum
< from
)
1356 if (VIsual
.lnum
> to
)
1362 * If in block mode and changed column or curwin->w_curswant:
1364 * First compute the actual start and end column.
1366 if (VIsual_mode
== Ctrl_V
)
1370 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1372 if (curwin
->w_curswant
== MAXCOL
)
1375 if (fromc
!= wp
->w_old_cursor_fcol
1376 || toc
!= wp
->w_old_cursor_lcol
)
1378 if (from
> VIsual
.lnum
)
1380 if (to
< VIsual
.lnum
)
1383 wp
->w_old_cursor_fcol
= fromc
;
1384 wp
->w_old_cursor_lcol
= toc
;
1389 /* Use the line numbers of the old Visual area. */
1390 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1392 from
= wp
->w_old_cursor_lnum
;
1393 to
= wp
->w_old_visual_lnum
;
1397 from
= wp
->w_old_visual_lnum
;
1398 to
= wp
->w_old_cursor_lnum
;
1403 * There is no need to update lines above the top of the window.
1405 if (from
< wp
->w_topline
)
1406 from
= wp
->w_topline
;
1409 * If we know the value of w_botline, use it to restrict the update to
1410 * the lines that are visible in the window.
1412 if (wp
->w_valid
& VALID_BOTLINE
)
1414 if (from
>= wp
->w_botline
)
1415 from
= wp
->w_botline
- 1;
1416 if (to
>= wp
->w_botline
)
1417 to
= wp
->w_botline
- 1;
1421 * Find the minimal part to be updated.
1422 * Watch out for scrolling that made entries in w_lines[] invalid.
1423 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1424 * top_end; need to redraw from top_end to the "to" line.
1425 * A middle mouse click with a Visual selection may change the text
1426 * above the Visual area and reset wl_valid, do count these for
1427 * mid_end (in srow).
1431 lnum
= wp
->w_topline
;
1435 mid_start
= top_end
;
1438 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1440 if (wp
->w_lines
[idx
].wl_valid
)
1441 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1442 else if (!scrolled_down
)
1443 srow
+= wp
->w_lines
[idx
].wl_size
;
1445 # ifdef FEAT_FOLDING
1446 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1447 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1453 mid_end
= wp
->w_height
;
1454 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1456 if (wp
->w_lines
[idx
].wl_valid
1457 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1459 /* Only update until first row of this line */
1463 srow
+= wp
->w_lines
[idx
].wl_size
;
1468 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1470 wp
->w_old_visual_mode
= VIsual_mode
;
1471 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1472 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1473 wp
->w_old_visual_col
= VIsual
.col
;
1474 wp
->w_old_curswant
= curwin
->w_curswant
;
1478 wp
->w_old_visual_mode
= 0;
1479 wp
->w_old_cursor_lnum
= 0;
1480 wp
->w_old_visual_lnum
= 0;
1481 wp
->w_old_visual_col
= 0;
1483 #endif /* FEAT_VISUAL */
1485 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1486 /* reset got_int, otherwise regexp won't work */
1487 save_got_int
= got_int
;
1491 win_foldinfo
.fi_level
= 0;
1495 * Update all the window rows.
1497 idx
= 0; /* first entry in w_lines[].wl_size */
1500 lnum
= wp
->w_topline
; /* first line shown in window */
1503 /* stop updating when reached the end of the window (check for _past_
1504 * the end of the window is at the end of the loop) */
1505 if (row
== wp
->w_height
)
1511 /* stop updating when hit the end of the file */
1512 if (lnum
> buf
->b_ml
.ml_line_count
)
1518 /* Remember the starting row of the line that is going to be dealt
1519 * with. It is used further down when the line doesn't fit. */
1523 * Update a line when it is in an area that needs updating, when it
1524 * has changes or w_lines[idx] is invalid.
1525 * bot_start may be halfway a wrapped line after using
1526 * win_del_lines(), check if the current line includes it.
1527 * When syntax folding is being used, the saved syntax states will
1528 * already have been updated, we can't see where the syntax state is
1529 * the same again, just update until the end of the window.
1532 || (row
>= mid_start
&& row
< mid_end
)
1533 #ifdef FEAT_SEARCH_EXTRA
1536 || idx
>= wp
->w_lines_valid
1537 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1543 || did_update
== DID_FOLD
1544 || (did_update
== DID_LINE
1545 && syntax_present(buf
)
1547 # ifdef FEAT_FOLDING
1548 (foldmethodIsSyntax(wp
)
1549 && hasAnyFolding(wp
)) ||
1551 syntax_check_changed(lnum
)))
1555 #ifdef FEAT_SEARCH_EXTRA
1556 if (lnum
== mod_top
)
1561 * When at start of changed lines: May scroll following lines
1562 * up or down to minimize redrawing.
1563 * Don't do this when the change continues until the end.
1564 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1567 && mod_bot
!= MAXLNUM
1568 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1575 /* Count the old number of window rows, using w_lines[], which
1576 * should still contain the sizes for the lines as they are
1577 * currently displayed. */
1578 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1580 /* Only valid lines have a meaningful wl_lnum. Invalid
1581 * lines are part of the changed area. */
1582 if (wp
->w_lines
[i
].wl_valid
1583 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1585 old_rows
+= wp
->w_lines
[i
].wl_size
;
1587 if (wp
->w_lines
[i
].wl_valid
1588 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1590 /* Must have found the last valid entry above mod_bot.
1591 * Add following invalid entries. */
1593 while (i
< wp
->w_lines_valid
1594 && !wp
->w_lines
[i
].wl_valid
)
1595 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1601 if (i
>= wp
->w_lines_valid
)
1603 /* We can't find a valid line below the changed lines,
1604 * need to redraw until the end of the window.
1605 * Inserting/deleting lines has no use. */
1610 /* Able to count old number of rows: Count new window
1611 * rows, and may insert/delete lines */
1613 for (l
= lnum
; l
< mod_bot
; ++l
)
1616 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1621 if (l
== wp
->w_topline
)
1622 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1626 new_rows
+= plines_win(wp
, l
, TRUE
);
1628 if (new_rows
> wp
->w_height
- row
- 2)
1630 /* it's getting too much, must redraw the rest */
1635 xtra_rows
= new_rows
- old_rows
;
1638 /* May scroll text up. If there is not enough
1639 * remaining text or scrolling fails, must redraw the
1640 * rest. If scrolling works, must redraw the text
1641 * below the scrolled text. */
1642 if (row
- xtra_rows
>= wp
->w_height
- 2)
1646 check_for_delay(FALSE
);
1647 if (win_del_lines(wp
, row
,
1648 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1651 bot_start
= wp
->w_height
+ xtra_rows
;
1654 else if (xtra_rows
> 0)
1656 /* May scroll text down. If there is not enough
1657 * remaining text of scrolling fails, must redraw the
1659 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1663 check_for_delay(FALSE
);
1664 if (win_ins_lines(wp
, row
+ old_rows
,
1665 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1667 else if (top_end
> row
+ old_rows
)
1668 /* Scrolled the part at the top that requires
1670 top_end
+= xtra_rows
;
1674 /* When not updating the rest, may need to move w_lines[]
1676 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1680 int x
= row
+ new_rows
;
1682 /* move entries in w_lines[] upwards */
1685 /* stop at last valid entry in w_lines[] */
1686 if (i
>= wp
->w_lines_valid
)
1688 wp
->w_lines_valid
= j
;
1691 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1692 /* stop at a line that won't fit */
1693 if (x
+ (int)wp
->w_lines
[j
].wl_size
1696 wp
->w_lines_valid
= j
+ 1;
1699 x
+= wp
->w_lines
[j
++].wl_size
;
1707 /* move entries in w_lines[] downwards */
1709 wp
->w_lines_valid
+= j
;
1710 if (wp
->w_lines_valid
> wp
->w_height
)
1711 wp
->w_lines_valid
= wp
->w_height
;
1712 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1713 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1715 /* The w_lines[] entries for inserted lines are
1716 * now invalid, but wl_size may be used above.
1720 wp
->w_lines
[i
].wl_size
= 0;
1721 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1730 * When lines are folded, display one line for all of them.
1731 * Otherwise, display normally (can be several display lines when
1734 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1735 if (fold_count
!= 0)
1737 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1740 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1741 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1743 did_update
= DID_FOLD
;
1748 if (idx
< wp
->w_lines_valid
1749 && wp
->w_lines
[idx
].wl_valid
1750 && wp
->w_lines
[idx
].wl_lnum
== lnum
1751 && lnum
> wp
->w_topline
1752 && !(dy_flags
& DY_LASTLINE
)
1753 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1755 && diff_check_fill(wp
, lnum
) == 0
1759 /* This line is not going to fit. Don't draw anything here,
1760 * will draw "@ " lines below. */
1761 row
= wp
->w_height
+ 1;
1765 #ifdef FEAT_SEARCH_EXTRA
1766 prepare_search_hl(wp
, lnum
);
1769 /* Let the syntax stuff know we skipped a few lines. */
1770 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1771 && syntax_present(buf
))
1772 syntax_end_parsing(syntax_last_parsed
+ 1);
1778 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1781 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1782 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1785 did_update
= DID_LINE
;
1786 syntax_last_parsed
= lnum
;
1790 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1791 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1792 if (row
> wp
->w_height
) /* past end of screen */
1794 /* we may need the size of that too long line later on */
1795 if (dollar_vcol
== 0)
1796 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1800 if (dollar_vcol
== 0)
1801 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1804 lnum
+= fold_count
+ 1;
1811 /* This line does not need updating, advance to the next one */
1812 row
+= wp
->w_lines
[idx
++].wl_size
;
1813 if (row
> wp
->w_height
) /* past end of screen */
1816 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1821 did_update
= DID_NONE
;
1825 if (lnum
> buf
->b_ml
.ml_line_count
)
1832 * End of loop over all window lines.
1836 if (idx
> wp
->w_lines_valid
)
1837 wp
->w_lines_valid
= idx
;
1841 * Let the syntax stuff know we stop parsing here.
1843 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1844 syntax_end_parsing(syntax_last_parsed
+ 1);
1848 * If we didn't hit the end of the file, and we didn't finish the last
1849 * line we were working on, then the line didn't fit.
1851 wp
->w_empty_rows
= 0;
1853 wp
->w_filler_rows
= 0;
1855 if (!eof
&& !didline
)
1857 if (lnum
== wp
->w_topline
)
1860 * Single line that does not fit!
1861 * Don't overwrite it, it can be edited.
1863 wp
->w_botline
= lnum
+ 1;
1866 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1868 /* Window ends in filler lines. */
1869 wp
->w_botline
= lnum
;
1870 wp
->w_filler_rows
= wp
->w_height
- srow
;
1873 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1876 * Last line isn't finished: Display "@@@" at the end.
1878 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1879 W_WINROW(wp
) + wp
->w_height
,
1880 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1881 '@', '@', hl_attr(HLF_AT
));
1882 set_empty_rows(wp
, srow
);
1883 wp
->w_botline
= lnum
;
1887 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1888 wp
->w_botline
= lnum
;
1893 #ifdef FEAT_VERTSPLIT
1894 draw_vsep_win(wp
, row
);
1896 if (eof
) /* we hit the end of the file */
1898 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1900 j
= diff_check_fill(wp
, wp
->w_botline
);
1901 if (j
> 0 && !wp
->w_botfill
)
1904 * Display filler lines at the end of the file
1906 if (char2cells(fill_diff
) > 1)
1910 if (row
+ j
> wp
->w_height
)
1911 j
= wp
->w_height
- row
;
1912 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1917 else if (dollar_vcol
== 0)
1918 wp
->w_botline
= lnum
;
1920 /* make sure the rest of the screen is blank */
1921 /* put '~'s on rows that aren't part of the file. */
1922 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1925 /* Reset the type of redrawing required, the window has been updated. */
1926 wp
->w_redr_type
= 0;
1928 wp
->w_old_topfill
= wp
->w_topfill
;
1929 wp
->w_old_botfill
= wp
->w_botfill
;
1932 if (dollar_vcol
== 0)
1935 * There is a trick with w_botline. If we invalidate it on each
1936 * change that might modify it, this will cause a lot of expensive
1937 * calls to plines() in update_topline() each time. Therefore the
1938 * value of w_botline is often approximated, and this value is used to
1939 * compute the value of w_topline. If the value of w_botline was
1940 * wrong, check that the value of w_topline is correct (cursor is on
1941 * the visible part of the text). If it's not, we need to redraw
1942 * again. Mostly this just means scrolling up a few lines, so it
1943 * doesn't look too bad. Only do this for the current window (where
1944 * changes are relevant).
1946 wp
->w_valid
|= VALID_BOTLINE
;
1947 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1950 curwin
->w_valid
&= ~VALID_TOPLINE
;
1951 update_topline(); /* may invalidate w_botline again */
1952 if (must_redraw
!= 0)
1954 /* Don't update for changes in buffer again. */
1955 i
= curbuf
->b_mod_set
;
1956 curbuf
->b_mod_set
= FALSE
;
1959 curbuf
->b_mod_set
= i
;
1965 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1966 /* restore got_int, unless CTRL-C was hit while redrawing */
1968 got_int
= save_got_int
;
1973 static int draw_signcolumn
__ARGS((win_T
*wp
));
1976 * Return TRUE when window "wp" has a column to draw signs in.
1982 return (wp
->w_buffer
->b_signlist
!= NULL
1983 # ifdef FEAT_NETBEANS_INTG
1991 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1992 * as the filler character.
1995 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
2003 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
2010 #ifdef FEAT_RIGHTLEFT
2013 /* No check for cmdline window: should never be right-left. */
2014 # ifdef FEAT_FOLDING
2019 /* draw the fold column at the right */
2020 if (n
> W_WIDTH(wp
))
2022 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2023 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
2024 ' ', ' ', hl_attr(HLF_FC
));
2028 if (draw_signcolumn(wp
))
2032 /* draw the sign column left of the fold column */
2033 if (nn
> W_WIDTH(wp
))
2035 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2036 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2037 ' ', ' ', hl_attr(HLF_SC
));
2041 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2042 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2043 c2
, c2
, hl_attr(hl
));
2044 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2045 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2046 c1
, c2
, hl_attr(hl
));
2052 if (cmdwin_type
!= 0 && wp
== curwin
)
2054 /* draw the cmdline character in the leftmost column */
2056 if (n
> wp
->w_width
)
2058 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2059 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2060 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2064 if (wp
->w_p_fdc
> 0)
2066 int nn
= n
+ wp
->w_p_fdc
;
2068 /* draw the fold column at the left */
2069 if (nn
> W_WIDTH(wp
))
2071 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2072 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2073 ' ', ' ', hl_attr(HLF_FC
));
2078 if (draw_signcolumn(wp
))
2082 /* draw the sign column after the fold column */
2083 if (nn
> W_WIDTH(wp
))
2085 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2086 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2087 ' ', ' ', hl_attr(HLF_SC
));
2091 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2092 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2093 c1
, c2
, hl_attr(hl
));
2095 set_empty_rows(wp
, row
);
2100 * Display one folded line.
2103 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2106 foldinfo_T
*foldinfo
;
2112 linenr_T lnume
= lnum
+ fold_count
- 1;
2118 int off
= (int)(current_ScreenLine
- ScreenLines
);
2121 /* Build the fold line:
2122 * 1. Add the cmdwin_type for the command-line window
2123 * 2. Add the 'foldcolumn'
2124 * 3. Add the 'number' or 'relativenumber' column
2125 * 4. Compose the text
2127 * 6. set highlighting for the Visual area an other text
2132 * 1. Add the cmdwin_type for the command-line window
2133 * Ignores 'rightleft', this window is never right-left.
2136 if (cmdwin_type
!= 0 && wp
== curwin
)
2138 ScreenLines
[off
] = cmdwin_type
;
2139 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2142 ScreenLinesUC
[off
] = 0;
2149 * 2. Add the 'foldcolumn'
2152 if (fdc
> W_WIDTH(wp
) - col
)
2153 fdc
= W_WIDTH(wp
) - col
;
2156 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2157 #ifdef FEAT_RIGHTLEFT
2162 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2164 /* reverse the fold column */
2165 for (i
= 0; i
< fdc
; ++i
)
2166 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2170 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2174 #ifdef FEAT_RIGHTLEFT
2175 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2176 for (ri = 0; ri < l; ++ri) \
2177 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2179 for (ri = 0; ri < l; ++ri) \
2180 ScreenAttrs[off + (p) + ri] = v
2182 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2183 ScreenAttrs[off + (p) + ri] = v
2186 /* Set all attributes of the 'number' or 'relativenumber' column and the
2188 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2191 /* If signs are being displayed, add two spaces. */
2192 if (draw_signcolumn(wp
))
2194 len
= W_WIDTH(wp
) - col
;
2199 # ifdef FEAT_RIGHTLEFT
2201 /* the line number isn't reversed */
2202 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2203 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2206 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2213 * 3. Add the 'number' or 'relativenumber' column
2215 if (wp
->w_p_nu
|| wp
->w_p_rnu
)
2217 len
= W_WIDTH(wp
) - col
;
2220 int w
= number_width(wp
);
2230 /* 'relativenumber', don't use negative numbers */
2231 num
= (long)abs((int)get_cursor_rel_lnum(wp
, lnum
));
2233 sprintf((char *)buf
, "%*ld ", w
, num
);
2234 #ifdef FEAT_RIGHTLEFT
2236 /* the line number isn't reversed */
2237 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2241 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2247 * 4. Compose the folded-line string with 'foldtext', if set.
2249 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2251 txtcol
= col
; /* remember where text starts */
2254 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2255 * Right-left text is put in columns 0 - number-col, normal text is put
2256 * in columns number-col - window-width.
2262 int u8c
, u8cc
[MAX_MCO
];
2268 int prev_c
= 0; /* previous Arabic character */
2269 int prev_c1
= 0; /* first composing char for prev_c */
2272 # ifdef FEAT_RIGHTLEFT
2279 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2280 for (p
= text
; *p
!= NUL
; )
2282 cells
= (*mb_ptr2cells
)(p
);
2283 c_len
= (*mb_ptr2len
)(p
);
2284 if (col
+ cells
> W_WIDTH(wp
)
2285 # ifdef FEAT_RIGHTLEFT
2286 - (wp
->w_p_rl
? col
: 0)
2290 ScreenLines
[idx
] = *p
;
2293 u8c
= utfc_ptr2char(p
, u8cc
);
2294 if (*p
< 0x80 && u8cc
[0] == 0)
2296 ScreenLinesUC
[idx
] = 0;
2304 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2306 /* Do Arabic shaping. */
2311 /* The idea of what is the previous and next
2312 * character depends on 'rightleft'. */
2317 nc
= utf_ptr2char(p
+ c_len
);
2322 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2328 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2330 ScreenLines
[idx
] = firstbyte
;
2335 /* Non-BMP character: display as ? or fullwidth ?. */
2338 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2341 ScreenLinesUC
[idx
] = u8c
;
2342 for (i
= 0; i
< Screen_mco
; ++i
)
2344 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2350 ScreenLines
[idx
+ 1] = 0;
2352 else if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2353 /* double-byte single width character */
2354 ScreenLines2
[idx
] = p
[1];
2356 /* double-width character */
2357 ScreenLines
[idx
+ 1] = p
[1];
2366 len
= (int)STRLEN(text
);
2367 if (len
> W_WIDTH(wp
) - col
)
2368 len
= W_WIDTH(wp
) - col
;
2371 #ifdef FEAT_RIGHTLEFT
2373 STRNCPY(current_ScreenLine
, text
, len
);
2376 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2381 /* Fill the rest of the line with the fold filler */
2382 #ifdef FEAT_RIGHTLEFT
2386 while (col
< W_WIDTH(wp
)
2387 #ifdef FEAT_RIGHTLEFT
2388 - (wp
->w_p_rl
? txtcol
: 0)
2395 if (fill_fold
>= 0x80)
2397 ScreenLinesUC
[off
+ col
] = fill_fold
;
2398 ScreenLinesC
[0][off
+ col
] = 0;
2401 ScreenLinesUC
[off
+ col
] = 0;
2404 ScreenLines
[off
+ col
++] = fill_fold
;
2411 * 6. set highlighting for the Visual area an other text.
2412 * If all folded lines are in the Visual area, highlight the line.
2415 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2417 if (ltoreq(curwin
->w_cursor
, VIsual
))
2419 /* Visual is after curwin->w_cursor */
2420 top
= &curwin
->w_cursor
;
2425 /* Visual is before curwin->w_cursor */
2427 bot
= &curwin
->w_cursor
;
2429 if (lnum
>= top
->lnum
2430 && lnume
<= bot
->lnum
2431 && (VIsual_mode
!= 'v'
2432 || ((lnum
> top
->lnum
2433 || (lnum
== top
->lnum
2435 && (lnume
< bot
->lnum
2436 || (lnume
== bot
->lnum
2437 && (bot
->col
- (*p_sel
== 'e'))
2438 >= (colnr_T
)STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2440 if (VIsual_mode
== Ctrl_V
)
2442 /* Visual block mode: highlight the chars part of the block */
2443 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2445 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2446 len
= wp
->w_old_cursor_lcol
;
2448 len
= W_WIDTH(wp
) - txtcol
;
2449 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2450 len
- (int)wp
->w_old_cursor_fcol
);
2455 /* Set all attributes of the text */
2456 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2463 /* Show 'cursorcolumn' in the fold line. */
2466 txtcol
+= wp
->w_virtcol
;
2468 txtcol
-= wp
->w_skipcol
;
2470 txtcol
-= wp
->w_leftcol
;
2471 if (txtcol
>= 0 && txtcol
< W_WIDTH(wp
))
2472 ScreenAttrs
[off
+ txtcol
] = hl_combine_attr(
2473 ScreenAttrs
[off
+ txtcol
], hl_attr(HLF_CUC
));
2477 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2478 (int)W_WIDTH(wp
), FALSE
);
2481 * Update w_cline_height and w_cline_folded if the cursor line was
2482 * updated (saves a call to plines() later).
2485 && lnum
<= curwin
->w_cursor
.lnum
2486 && lnume
>= curwin
->w_cursor
.lnum
)
2488 curwin
->w_cline_row
= row
;
2489 curwin
->w_cline_height
= 1;
2490 curwin
->w_cline_folded
= TRUE
;
2491 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2496 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2499 copy_text_attr(off
, buf
, len
, attr
)
2507 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2510 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2512 for (i
= 0; i
< len
; ++i
)
2513 ScreenAttrs
[off
+ i
] = attr
;
2517 * Fill the foldcolumn at "p" for window "wp".
2518 * Only to be called when 'foldcolumn' > 0.
2521 fill_foldcolumn(p
, wp
, closed
, lnum
)
2524 int closed
; /* TRUE of FALSE */
2525 linenr_T lnum
; /* current line number */
2532 /* Init to all spaces. */
2533 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2535 level
= win_foldinfo
.fi_level
;
2538 /* If there is only one column put more info in it. */
2539 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2541 /* If the column is too narrow, we start at the lowest level that
2542 * fits and use numbers to indicated the depth. */
2543 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2544 if (first_level
< 1)
2547 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2549 if (win_foldinfo
.fi_lnum
== lnum
2550 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2552 else if (first_level
== 1)
2554 else if (first_level
+ i
<= 9)
2555 p
[i
] = '0' + first_level
+ i
;
2558 if (first_level
+ i
== level
)
2563 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2565 #endif /* FEAT_FOLDING */
2568 * Display line "lnum" of window 'wp' on the screen.
2569 * Start at row "startrow", stop when "endrow" is reached.
2570 * wp->w_virtcol needs to be valid.
2572 * Return the number of last row the line occupies.
2575 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2580 int nochange UNUSED
; /* not updating for changed text */
2582 int col
; /* visual column on screen */
2583 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2584 int c
= 0; /* init for GCC */
2585 long vcol
= 0; /* virtual column (for tabs) */
2586 long vcol_prev
= -1; /* "vcol" of previous character */
2587 char_u
*line
; /* current line */
2588 char_u
*ptr
; /* current position in "line" */
2589 int row
; /* row in the window, excl w_winrow */
2590 int screen_row
; /* row on the screen, incl w_winrow */
2592 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2593 int n_extra
= 0; /* number of extra chars */
2594 char_u
*p_extra
= NULL
; /* string of extra chars, plus NUL */
2595 int c_extra
= NUL
; /* extra chars, all the same */
2596 int extra_attr
= 0; /* attributes when n_extra != 0 */
2597 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2598 displaying lcs_eol at end-of-line */
2599 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2600 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2602 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2603 int saved_n_extra
= 0;
2604 char_u
*saved_p_extra
= NULL
;
2605 int saved_c_extra
= 0;
2606 int saved_char_attr
= 0;
2608 int n_attr
= 0; /* chars with special attr */
2609 int saved_attr2
= 0; /* char_attr saved for n_attr */
2610 int n_attr3
= 0; /* chars with overruling special attr */
2611 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2613 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2615 int fromcol
, tocol
; /* start/end of inverting */
2616 int fromcol_prev
= -2; /* start of inverting after cursor */
2617 int noinvcur
= FALSE
; /* don't invert the cursor */
2620 int lnum_in_visual_area
= FALSE
;
2625 int char_attr
= 0; /* attributes for next character */
2626 int attr_pri
= FALSE
; /* char_attr has priority */
2627 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2629 int attr
= 0; /* attributes for area highlighting */
2630 int area_attr
= 0; /* attributes desired by highlighting */
2631 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2633 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2634 int syntax_attr
= 0; /* attributes desired by syntax */
2635 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2637 int eol_hl_off
= 0; /* 1 if highlighted char after EOL */
2640 int has_spell
= FALSE
; /* this buffer has spell checking */
2641 # define SPWORDLEN 150
2642 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2643 int nextlinecol
= 0; /* column where nextline[] starts */
2644 int nextline_idx
= 0; /* index in nextline[] where next line
2646 int spell_attr
= 0; /* attributes desired by spelling */
2647 int word_end
= 0; /* last byte with same spell_attr */
2648 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2649 static int checked_col
= 0; /* column in "checked_lnum" up to which
2650 * there are no spell errors */
2651 static int cap_col
= -1; /* column to check for Cap word */
2652 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2653 int cur_checked_col
= 0; /* checked column for current line */
2655 int extra_check
; /* has syntax or linebreak */
2657 int multi_attr
= 0; /* attributes desired by multibyte */
2658 int mb_l
= 1; /* multi-byte byte length */
2659 int mb_c
= 0; /* decoded multi-byte character */
2660 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2661 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2664 int filler_lines
; /* nr of filler lines to be drawn */
2665 int filler_todo
; /* nr of filler lines still to do + 1 */
2666 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2667 int change_start
= MAXCOL
; /* first col of changed area */
2668 int change_end
= -1; /* last col of changed area */
2670 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2671 #ifdef FEAT_LINEBREAK
2672 int need_showbreak
= FALSE
;
2674 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2675 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2677 int line_attr
= 0; /* attribute for the whole line */
2679 #ifdef FEAT_SEARCH_EXTRA
2680 matchitem_T
*cur
; /* points to the match list */
2681 match_T
*shl
; /* points to search_hl or a match */
2682 int shl_flag
; /* flag to indicate whether search_hl
2683 has been processed or not */
2684 int prevcol_hl_flag
; /* flag to indicate whether prevcol
2685 equals startcol of search_hl or one
2689 int prev_c
= 0; /* previous Arabic character */
2690 int prev_c1
= 0; /* first composing char for prev_c */
2692 #if defined(LINE_ATTR)
2693 int did_line_attr
= 0;
2696 /* draw_state: items that are drawn in sequence: */
2697 #define WL_START 0 /* nothing done yet */
2699 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2701 # define WL_CMDLINE WL_START
2704 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2706 # define WL_FOLD WL_CMDLINE
2709 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2711 # define WL_SIGN WL_FOLD /* column for signs */
2713 #define WL_NR WL_SIGN + 1 /* line number */
2714 #ifdef FEAT_LINEBREAK
2715 # define WL_BRI WL_NR + 1 /* 'breakindent' */
2717 # define WL_BRI WL_NR
2719 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2720 # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */
2722 # define WL_SBR WL_BRI
2724 #define WL_LINE WL_SBR + 1 /* text in the line */
2725 int draw_state
= WL_START
; /* what to draw next */
2726 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2727 int feedback_col
= 0;
2728 int feedback_old_attr
= -1;
2732 if (startrow
> endrow
) /* past the end already! */
2736 screen_row
= row
+ W_WINROW(wp
);
2739 * To speed up the loop below, set extra_check when there is linebreak,
2740 * trailing white space and/or syntax processing to be done.
2742 #ifdef FEAT_LINEBREAK
2743 extra_check
= wp
->w_p_lbr
;
2748 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2750 /* Prepare for syntax highlighting in this line. When there is an
2751 * error, stop syntax highlighting. */
2752 save_did_emsg
= did_emsg
;
2754 syntax_start(wp
, lnum
);
2756 wp
->w_buffer
->b_syn_error
= TRUE
;
2759 did_emsg
= save_did_emsg
;
2768 && *wp
->w_buffer
->b_p_spl
!= NUL
2769 && wp
->w_buffer
->b_langp
.ga_len
> 0
2770 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2772 /* Prepare for spell checking. */
2776 /* Get the start of the next line, so that words that wrap to the next
2777 * line are found too: "et<line-break>al.".
2778 * Trick: skip a few chars for C/shell/Vim comments */
2779 nextline
[SPWORDLEN
] = NUL
;
2780 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2782 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2783 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2786 /* When a word wrapped from the previous line the start of the current
2788 if (lnum
== checked_lnum
)
2789 cur_checked_col
= checked_col
;
2792 /* When there was a sentence end in the previous line may require a
2793 * word starting with capital in this line. In line 1 always check
2794 * the first word. */
2795 if (lnum
!= capcol_lnum
)
2804 * handle visual active in this window
2809 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2811 /* Visual is after curwin->w_cursor */
2812 if (ltoreq(curwin
->w_cursor
, VIsual
))
2814 top
= &curwin
->w_cursor
;
2817 else /* Visual is before curwin->w_cursor */
2820 bot
= &curwin
->w_cursor
;
2822 lnum_in_visual_area
= (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
);
2823 if (VIsual_mode
== Ctrl_V
) /* block mode */
2825 if (lnum_in_visual_area
)
2827 fromcol
= wp
->w_old_cursor_fcol
;
2828 tocol
= wp
->w_old_cursor_lcol
;
2831 else /* non-block mode */
2833 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2835 else if (lnum
== top
->lnum
)
2837 if (VIsual_mode
== 'V') /* linewise */
2841 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2842 if (gchar_pos(top
) == NUL
)
2843 tocol
= fromcol
+ 1;
2846 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2848 if (*p_sel
== 'e' && bot
->col
== 0
2849 #ifdef FEAT_VIRTUALEDIT
2857 else if (bot
->col
== MAXCOL
)
2863 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2866 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2874 /* Check if the character under the cursor should not be inverted */
2875 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2883 /* if inverting in this line set area_highlighting */
2886 area_highlighting
= TRUE
;
2887 attr
= hl_attr(HLF_V
);
2888 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2889 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2890 attr
= hl_attr(HLF_VNC
);
2896 * handle 'incsearch' and ":s///c" highlighting
2899 #endif /* FEAT_VISUAL */
2902 && lnum
>= curwin
->w_cursor
.lnum
2903 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2905 if (lnum
== curwin
->w_cursor
.lnum
)
2906 getvcol(curwin
, &(curwin
->w_cursor
),
2907 (colnr_T
*)&fromcol
, NULL
, NULL
);
2910 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2913 pos
.col
= search_match_endcol
;
2914 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2918 /* do at least one character; happens when past end of line */
2919 if (fromcol
== tocol
)
2920 tocol
= fromcol
+ 1;
2921 area_highlighting
= TRUE
;
2922 attr
= hl_attr(HLF_I
);
2926 filler_lines
= diff_check(wp
, lnum
);
2927 if (filler_lines
< 0)
2929 if (filler_lines
== -1)
2931 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2932 diff_hlf
= HLF_ADD
; /* added line */
2933 else if (change_start
== 0)
2934 diff_hlf
= HLF_TXD
; /* changed text */
2936 diff_hlf
= HLF_CHD
; /* changed line */
2939 diff_hlf
= HLF_ADD
; /* added line */
2941 area_highlighting
= TRUE
;
2943 if (lnum
== wp
->w_topline
)
2944 filler_lines
= wp
->w_topfill
;
2945 filler_todo
= filler_lines
;
2950 /* If this line has a sign with line highlighting set line_attr. */
2951 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2953 line_attr
= sign_get_attr((int)v
, TRUE
);
2955 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2956 /* Highlight the current line in the quickfix window. */
2957 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2958 line_attr
= hl_attr(HLF_L
);
2961 area_highlighting
= TRUE
;
2964 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2970 /* For checking first word with a capital skip white space. */
2972 cap_col
= (int)(skipwhite(line
) - line
);
2974 /* To be able to spell-check over line boundaries copy the end of the
2975 * current line into nextline[]. Above the start of the next line was
2976 * copied to nextline[SPWORDLEN]. */
2977 if (nextline
[SPWORDLEN
] == NUL
)
2979 /* No next line or it is empty. */
2980 nextlinecol
= MAXCOL
;
2985 v
= (long)STRLEN(line
);
2988 /* Short line, use it completely and append the start of the
2991 mch_memmove(nextline
, line
, (size_t)v
);
2992 STRMOVE(nextline
+ v
, nextline
+ SPWORDLEN
);
2993 nextline_idx
= v
+ 1;
2997 /* Long line, use only the last SPWORDLEN bytes. */
2998 nextlinecol
= v
- SPWORDLEN
;
2999 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
3000 nextline_idx
= SPWORDLEN
+ 1;
3006 /* find start of trailing whitespace */
3007 if (wp
->w_p_list
&& lcs_trail
)
3009 trailcol
= (colnr_T
)STRLEN(ptr
);
3010 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
3012 trailcol
+= (colnr_T
) (ptr
- line
);
3017 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
3018 * first character to be displayed.
3027 char_u
*prev_ptr
= ptr
;
3029 while (vcol
< v
&& *ptr
!= NUL
)
3031 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
, lnum
);
3039 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3041 * - 'cuc' is set, or
3042 * - 'virtualedit' is set, or
3043 * - the visual mode is active,
3044 * the end of the line may be before the start of the displayed part.
3049 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3053 # ifdef FEAT_VIRTUALEDIT
3060 (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
3068 /* Handle a character that's not completely on the screen: Put ptr at
3069 * that character but skip the first few screen characters. */
3082 * Adjust for when the inverted text is before the screen,
3083 * and when the start of the inverted text is before the screen.
3087 else if (fromcol
>= 0 && fromcol
< vcol
)
3090 #ifdef FEAT_LINEBREAK
3091 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3093 need_showbreak
= TRUE
;
3096 /* When spell checking a word we need to figure out the start of the
3097 * word and if it's badly spelled or not. */
3101 colnr_T linecol
= (colnr_T
)(ptr
- line
);
3102 hlf_T spell_hlf
= HLF_COUNT
;
3105 wp
->w_cursor
.lnum
= lnum
;
3106 wp
->w_cursor
.col
= linecol
;
3107 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3109 /* spell_move_to() may call ml_get() and make "line" invalid */
3110 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3111 ptr
= line
+ linecol
;
3113 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3115 /* no bad word found at line start, don't check until end of a
3117 spell_hlf
= HLF_COUNT
;
3118 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
)
3123 /* bad word found, use attributes until end of word */
3124 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3126 /* Turn index into actual attributes. */
3127 if (spell_hlf
!= HLF_COUNT
)
3128 spell_attr
= highlight_attr
[spell_hlf
];
3133 /* Need to restart syntax highlighting for this line. */
3135 syntax_start(wp
, lnum
);
3142 * Correct highlighting for cursor that can't be disabled.
3143 * Avoids having to check this for each character.
3149 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3151 /* highlighting starts at cursor, let it start just after the
3153 fromcol_prev
= fromcol
;
3156 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3157 /* restart highlighting after the cursor */
3158 fromcol_prev
= wp
->w_virtcol
;
3160 if (fromcol
>= tocol
)
3164 #ifdef FEAT_SEARCH_EXTRA
3166 * Handle highlighting the last used search pattern and matches.
3167 * Do this for both search_hl and the match list.
3169 cur
= wp
->w_match_head
;
3171 while (cur
!= NULL
|| shl_flag
== FALSE
)
3173 if (shl_flag
== FALSE
)
3180 shl
->startcol
= MAXCOL
;
3181 shl
->endcol
= MAXCOL
;
3183 if (shl
->rm
.regprog
!= NULL
)
3185 v
= (long)(ptr
- line
);
3186 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3188 /* Need to get the line again, a multi-line regexp may have made it
3190 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3193 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3195 if (shl
->lnum
== lnum
)
3196 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3199 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3200 - shl
->rm
.startpos
[0].lnum
)
3201 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3203 shl
->endcol
= MAXCOL
;
3204 /* Highlight one character for an empty match. */
3205 if (shl
->startcol
== shl
->endcol
)
3208 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3209 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3214 if ((long)shl
->startcol
< v
) /* match at leftcol */
3216 shl
->attr_cur
= shl
->attr
;
3217 search_attr
= shl
->attr
;
3219 area_highlighting
= TRUE
;
3222 if (shl
!= &search_hl
&& cur
!= NULL
)
3228 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3229 * active, because it's not clear what is selected then. */
3230 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3232 line_attr
= hl_attr(HLF_CUL
);
3233 area_highlighting
= TRUE
;
3237 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3239 #ifdef FEAT_RIGHTLEFT
3242 /* Rightleft window: process the text in the normal direction, but put
3243 * it in current_ScreenLine[] from right to left. Start at the
3244 * rightmost column of the window. */
3245 col
= W_WIDTH(wp
) - 1;
3251 * Repeat for the whole displayed line.
3255 /* Skip this quickly when working on the text. */
3256 if (draw_state
!= WL_LINE
)
3259 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3261 draw_state
= WL_CMDLINE
;
3262 if (cmdwin_type
!= 0 && wp
== curwin
)
3264 /* Draw the cmdline character. */
3266 c_extra
= cmdwin_type
;
3267 char_attr
= hl_attr(HLF_AT
);
3273 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3275 draw_state
= WL_FOLD
;
3276 if (wp
->w_p_fdc
> 0)
3278 /* Draw the 'foldcolumn'. */
3279 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3280 n_extra
= wp
->w_p_fdc
;
3282 p_extra
[n_extra
] = NUL
;
3284 char_attr
= hl_attr(HLF_FC
);
3290 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3292 draw_state
= WL_SIGN
;
3293 /* Show the sign column when there are any signs in this
3294 * buffer or when using Netbeans. */
3295 if (draw_signcolumn(wp
)
3302 # ifdef FEAT_SIGN_ICONS
3306 /* Draw two cells with the sign value or blank. */
3308 char_attr
= hl_attr(HLF_SC
);
3311 if (row
== startrow
)
3313 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3315 # ifdef FEAT_SIGN_ICONS
3316 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3318 if (gui
.in_use
&& icon_sign
!= 0)
3320 /* Use the image in this position. */
3321 c_extra
= SIGN_BYTE
;
3322 # ifdef FEAT_NETBEANS_INTG
3323 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3324 c_extra
= MULTISIGN_BYTE
;
3326 char_attr
= icon_sign
;
3332 p_extra
= sign_get_text(text_sign
);
3333 if (p_extra
!= NULL
)
3336 n_extra
= (int)STRLEN(p_extra
);
3338 char_attr
= sign_get_attr(text_sign
, FALSE
);
3345 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3348 /* Display the absolute or relative line number. After the
3349 * first fill with blanks when the 'n' flag isn't in 'cpo' */
3350 if ((wp
->w_p_nu
|| wp
->w_p_rnu
)
3355 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3357 /* Draw the line number (empty space after wrapping). */
3370 /* 'relativenumber', don't use negative numbers */
3371 num
= (long)abs((int)get_cursor_rel_lnum(wp
,
3374 sprintf((char *)extra
, "%*ld ",
3375 number_width(wp
), num
);
3376 if (wp
->w_skipcol
> 0)
3377 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3379 #ifdef FEAT_RIGHTLEFT
3380 if (wp
->w_p_rl
) /* reverse line numbers */
3388 n_extra
= number_width(wp
) + 1;
3389 char_attr
= hl_attr(HLF_N
);
3391 /* When 'cursorline' is set highlight the line number of
3392 * the current line differently. */
3393 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3394 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3399 #ifdef FEAT_LINEBREAK
3400 /* draw 'breakindent': indent wrapped text accordingly */
3401 if (draw_state
== WL_BRI
-1 && n_extra
== 0){
3402 draw_state
= WL_BRI
;
3404 /* FIXME: handle (filler_todo > 0): or modify showbreak so that ---- lines are shorter by the amount needed? */
3406 if (wp
->w_p_bri
&& row
!= startrow
){ /* FIXME: what is startrow? Don't we need it as well?? */
3409 n_extra
= get_breakindent_win(wp
,lnum
);
3410 char_attr
= 0; /* was: hl_attr(HLF_AT); */
3411 /* FIXME: why do we need to adjust vcol if showbreak does not?? */
3413 /* FIXME: is this relevant here? copied shamelessly from showbreak */
3414 /* Correct end of highlighted area for 'breakindent',
3415 * required when 'linebreak' is also set. */
3423 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3424 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3426 draw_state
= WL_SBR
;
3428 if (filler_todo
> 0)
3430 /* Draw "deleted" diff line(s). */
3431 if (char2cells(fill_diff
) > 1)
3434 c_extra
= fill_diff
;
3435 # ifdef FEAT_RIGHTLEFT
3440 n_extra
= W_WIDTH(wp
) - col
;
3441 char_attr
= hl_attr(HLF_DED
);
3444 # ifdef FEAT_LINEBREAK
3445 if (*p_sbr
!= NUL
&& need_showbreak
)
3447 /* Draw 'showbreak' at the start of each broken line. */
3450 n_extra
= (int)STRLEN(p_sbr
);
3451 char_attr
= hl_attr(HLF_AT
);
3452 need_showbreak
= FALSE
;
3453 /* Correct end of highlighted area for 'showbreak',
3454 * required when 'linebreak' is also set. */
3462 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3464 draw_state
= WL_LINE
;
3467 /* Continue item from end of wrapped line. */
3468 n_extra
= saved_n_extra
;
3469 c_extra
= saved_c_extra
;
3470 p_extra
= saved_p_extra
;
3471 char_attr
= saved_char_attr
;
3478 /* When still displaying '$' of change command, stop at cursor */
3479 if (dollar_vcol
!= 0 && wp
== curwin
3480 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3486 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3488 /* Pretend we have finished updating the window. Except when
3489 * 'cursorcolumn' is set. */
3492 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3499 if (draw_state
== WL_LINE
&& area_highlighting
)
3501 /* handle Visual or match highlighting in this line */
3504 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3505 && (*mb_ptr2cells
)(ptr
) > 1)
3507 || ((int)vcol_prev
== fromcol_prev
3508 && vcol_prev
< vcol
/* not at margin */
3510 area_attr
= attr
; /* start highlighting */
3511 else if (area_attr
!= 0
3513 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3514 area_attr
= 0; /* stop highlighting */
3516 #ifdef FEAT_SEARCH_EXTRA
3520 * Check for start/end of search pattern match.
3521 * After end, check for start/end of next match.
3522 * When another match, have to check for start again.
3523 * Watch out for matching an empty string!
3524 * Do this for 'search_hl' and the match list (ordered by
3527 v
= (long)(ptr
- line
);
3528 cur
= wp
->w_match_head
;
3530 while (cur
!= NULL
|| shl_flag
== FALSE
)
3532 if (shl_flag
== FALSE
3534 && cur
->priority
> SEARCH_HL_PRIORITY
)
3542 while (shl
->rm
.regprog
!= NULL
)
3544 if (shl
->startcol
!= MAXCOL
3545 && v
>= (long)shl
->startcol
3546 && v
< (long)shl
->endcol
)
3548 shl
->attr_cur
= shl
->attr
;
3550 else if (v
== (long)shl
->endcol
)
3554 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3556 /* Need to get the line again, a multi-line regexp
3557 * may have made it invalid. */
3558 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3561 if (shl
->lnum
== lnum
)
3563 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3564 if (shl
->rm
.endpos
[0].lnum
== 0)
3565 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3567 shl
->endcol
= MAXCOL
;
3569 if (shl
->startcol
== shl
->endcol
)
3571 /* highlight empty match, try again after
3575 shl
->endcol
+= (*mb_ptr2len
)(line
3582 /* Loop to check if the match starts at the
3583 * current position */
3589 if (shl
!= &search_hl
&& cur
!= NULL
)
3593 /* Use attributes from match with highest priority among
3594 * 'search_hl' and the match list. */
3595 search_attr
= search_hl
.attr_cur
;
3596 cur
= wp
->w_match_head
;
3598 while (cur
!= NULL
|| shl_flag
== FALSE
)
3600 if (shl_flag
== FALSE
3602 && cur
->priority
> SEARCH_HL_PRIORITY
)
3610 if (shl
->attr_cur
!= 0)
3611 search_attr
= shl
->attr_cur
;
3612 if (shl
!= &search_hl
&& cur
!= NULL
)
3619 if (diff_hlf
!= (hlf_T
)0)
3621 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
3623 diff_hlf
= HLF_TXD
; /* changed text */
3624 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
3626 diff_hlf
= HLF_CHD
; /* changed line */
3627 line_attr
= hl_attr(diff_hlf
);
3631 /* Decide which of the highlight attributes to use. */
3634 char_attr
= area_attr
;
3635 else if (search_attr
!= 0)
3636 char_attr
= search_attr
;
3638 /* Use line_attr when not in the Visual or 'incsearch' area
3639 * (area_attr may be 0 when "noinvcur" is set). */
3640 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3641 || vcol
< fromcol
|| vcol_prev
< fromcol_prev
3643 char_attr
= line_attr
;
3650 char_attr
= syntax_attr
;
3658 * Get the next character to put on the screen.
3661 * The "p_extra" points to the extra stuff that is inserted to
3662 * represent special characters (non-printable stuff) and other
3663 * things. When all characters are the same, c_extra is used.
3664 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3665 * "p_extra[n_extra]".
3666 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3674 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3675 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3694 /* If the UTF-8 character is more than one byte:
3695 * Decode it into "mb_c". */
3696 mb_l
= (*mb_ptr2len
)(p_extra
);
3702 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3709 /* if this is a DBCS character, put it in "mb_c" */
3710 mb_l
= MB_BYTE2LEN(c
);
3711 if (mb_l
>= n_extra
)
3714 mb_c
= (c
<< 8) + p_extra
[1];
3716 if (mb_l
== 0) /* at the NUL at end-of-line */
3719 /* If a double-width char doesn't fit display a '>' in the
3722 # ifdef FEAT_RIGHTLEFT
3723 wp
->w_p_rl
? (col
<= 0) :
3725 (col
>= W_WIDTH(wp
) - 1))
3726 && (*mb_char2cells
)(mb_c
) == 2)
3732 multi_attr
= hl_attr(HLF_AT
);
3733 /* put the pointer back to output the double-width
3734 * character at the start of the next line. */
3740 n_extra
-= mb_l
- 1;
3741 p_extra
+= mb_l
- 1;
3752 * Get a character from the line itself.
3761 /* If the UTF-8 character is more than one byte: Decode it
3763 mb_l
= (*mb_ptr2len
)(ptr
);
3767 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3768 /* Overlong encoded ASCII or ASCII with composing char
3769 * is displayed normally, except a NUL. */
3774 /* At start of the line we can have a composing char.
3775 * Draw it as a space with a composing char. */
3776 if (utf_iscomposing(mb_c
))
3780 for (i
= Screen_mco
- 1; i
> 0; --i
)
3781 u8cc
[i
] = u8cc
[i
- 1];
3787 if ((mb_l
== 1 && c
>= 0x80)
3788 || (mb_l
>= 1 && mb_c
== 0)
3789 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3796 * Illegal UTF-8 byte: display as <xx>.
3797 * Non-BMP character : display as ? or fullwidth ?.
3803 transchar_hex(extra
, mb_c
);
3804 # ifdef FEAT_RIGHTLEFT
3805 if (wp
->w_p_rl
) /* reverse */
3810 else if (utf_char2cells(mb_c
) != 2)
3813 /* 0xff1f in UTF-8: full-width '?' */
3814 STRCPY(extra
, "\357\274\237");
3819 mb_c
= mb_ptr2char_adv(&p_extra
);
3820 mb_utf8
= (c
>= 0x80);
3821 n_extra
= (int)STRLEN(p_extra
);
3823 if (area_attr
== 0 && search_attr
== 0)
3825 n_attr
= n_extra
+ 1;
3826 extra_attr
= hl_attr(HLF_8
);
3827 saved_attr2
= char_attr
; /* save current attr */
3830 else if (mb_l
== 0) /* at the NUL at end-of-line */
3833 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3835 /* Do Arabic shaping. */
3839 /* The idea of what is the previous and next
3840 * character depends on 'rightleft'. */
3845 nc
= utf_ptr2char(ptr
+ mb_l
);
3850 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3856 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3864 mb_l
= MB_BYTE2LEN(c
);
3865 if (mb_l
== 0) /* at the NUL at end-of-line */
3869 /* We assume a second byte below 32 is illegal.
3870 * Hopefully this is OK for all double-byte encodings!
3873 mb_c
= (c
<< 8) + ptr
[1];
3878 /* head byte at end of line */
3880 transchar_nonprint(extra
, c
);
3884 /* illegal tail byte */
3886 STRCPY(extra
, "XX");
3889 n_extra
= (int)STRLEN(extra
) - 1;
3892 if (area_attr
== 0 && search_attr
== 0)
3894 n_attr
= n_extra
+ 1;
3895 extra_attr
= hl_attr(HLF_8
);
3896 saved_attr2
= char_attr
; /* save current attr */
3902 /* If a double-width char doesn't fit display a '>' in the
3903 * last column; the character is displayed at the start of the
3906 # ifdef FEAT_RIGHTLEFT
3907 wp
->w_p_rl
? (col
<= 0) :
3909 (col
>= W_WIDTH(wp
) - 1))
3910 && (*mb_char2cells
)(mb_c
) == 2)
3916 multi_attr
= hl_attr(HLF_AT
);
3917 /* Put pointer back so that the character will be
3918 * displayed at the start of the next line. */
3921 else if (*ptr
!= NUL
)
3924 /* If a double-width char doesn't fit at the left side display
3925 * a '<' in the first column. */
3926 if (n_skip
> 0 && mb_l
> 1)
3931 if (area_attr
== 0 && search_attr
== 0)
3933 n_attr
= n_extra
+ 1;
3934 extra_attr
= hl_attr(HLF_AT
);
3935 saved_attr2
= char_attr
; /* save current attr */
3946 /* 'list' : change char 160 to lcs_nbsp. */
3947 if (wp
->w_p_list
&& (c
== 160
3949 || (mb_utf8
&& mb_c
== 160)
3954 if (area_attr
== 0 && search_attr
== 0)
3957 extra_attr
= hl_attr(HLF_8
);
3958 saved_attr2
= char_attr
; /* save current attr */
3962 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3976 int can_spell
= TRUE
;
3980 /* Get syntax attribute, unless still at the start of the line
3981 * (double-wide char that doesn't fit). */
3982 v
= (long)(ptr
- line
);
3983 if (has_syntax
&& v
> 0)
3985 /* Get the syntax attribute for the character. If there
3986 * is an error, disable syntax highlighting. */
3987 save_did_emsg
= did_emsg
;
3990 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3992 has_spell
? &can_spell
:
3998 wp
->w_buffer
->b_syn_error
= TRUE
;
4002 did_emsg
= save_did_emsg
;
4004 /* Need to get the line again, a multi-line regexp may
4005 * have made it invalid. */
4006 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
4010 char_attr
= syntax_attr
;
4012 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
4017 /* Check spelling (unless at the end of the line).
4018 * Only do this when there is no syntax highlighting, the
4019 * @Spell cluster is not used or the current syntax item
4020 * contains the @Spell cluster. */
4021 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
4026 char_attr
= syntax_attr
;
4034 char_u
*prev_ptr
, *p
;
4036 hlf_T spell_hlf
= HLF_COUNT
;
4040 prev_ptr
= ptr
- mb_l
;
4047 /* Use nextline[] if possible, it has the start of the
4048 * next line concatenated. */
4049 if ((prev_ptr
- line
) - nextlinecol
>= 0)
4050 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
4053 cap_col
-= (int)(prev_ptr
- line
);
4054 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
4058 /* In Insert mode only highlight a word that
4059 * doesn't touch the cursor. */
4060 if (spell_hlf
!= HLF_COUNT
4061 && (State
& INSERT
) != 0
4062 && wp
->w_cursor
.lnum
== lnum
4063 && wp
->w_cursor
.col
>=
4064 (colnr_T
)(prev_ptr
- line
)
4065 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
4067 spell_hlf
= HLF_COUNT
;
4068 spell_redraw_lnum
= lnum
;
4071 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
4072 && (p
- nextline
) + len
> nextline_idx
)
4074 /* Remember that the good word continues at the
4075 * start of the next line. */
4076 checked_lnum
= lnum
+ 1;
4077 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
4080 /* Turn index into actual attributes. */
4081 if (spell_hlf
!= HLF_COUNT
)
4082 spell_attr
= highlight_attr
[spell_hlf
];
4087 && (p
- nextline
) + cap_col
>= nextline_idx
)
4089 /* Remember that the word in the next line
4090 * must start with a capital. */
4091 capcol_lnum
= lnum
+ 1;
4092 cap_col
= (int)((p
- nextline
) + cap_col
4096 /* Compute the actual column. */
4097 cap_col
+= (int)(prev_ptr
- line
);
4101 if (spell_attr
!= 0)
4104 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
4106 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
4109 #ifdef FEAT_LINEBREAK
4111 * Found last space before word: check for line break.
4113 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
4116 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
4120 1), (colnr_T
)vcol
, NULL
, lnum
) - 1;
4127 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
4133 extra_attr
= hl_attr(HLF_8
);
4134 saved_attr2
= char_attr
; /* save current attr */
4138 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4151 * Handling of non-printable characters.
4153 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
4156 * when getting a character from the file, we may have to
4157 * turn it into something else on the way to putting it
4158 * into "ScreenLines".
4160 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
4162 /* tab amount depends on current column */
4164 n_extra
= tabstop_padding(vcol
, wp
->w_buffer
->b_p_ts
,
4165 wp
->w_buffer
->b_p_vts_ary
) - 1;
4167 n_extra
= (int)wp
->w_buffer
->b_p_ts
4168 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
4171 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4177 n_attr
= n_extra
+ 1;
4178 extra_attr
= hl_attr(HLF_8
);
4179 saved_attr2
= char_attr
; /* save current attr */
4182 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4197 && ((wp
->w_p_list
&& lcs_eol
> 0)
4198 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4201 && VIsual_mode
!= Ctrl_V
4204 # ifdef FEAT_RIGHTLEFT
4205 wp
->w_p_rl
? (col
>= 0) :
4207 (col
< W_WIDTH(wp
)))
4209 && lnum
== wp
->w_cursor
.lnum
4210 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4211 && lcs_eol_one
>= 0)
4213 /* Display a '$' after the line or highlight an extra
4214 * character if the line break is included. */
4215 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4216 /* For a diff line the highlighting continues after the
4220 diff_hlf
== (hlf_T
)0
4231 #ifdef FEAT_VIRTUALEDIT
4232 /* In virtualedit, visual selections may extend
4233 * beyond end of line. */
4234 if (area_highlighting
&& virtual_active()
4235 && tocol
!= MAXCOL
&& vcol
< tocol
)
4240 p_extra
= at_end_str
;
4250 --ptr
; /* put it back at the NUL */
4253 extra_attr
= hl_attr(HLF_AT
);
4258 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4265 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4270 p_extra
= transchar(c
);
4271 #ifdef FEAT_RIGHTLEFT
4272 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4273 rl_mirror(p_extra
); /* reverse "<12>" */
4275 n_extra
= byte2cells(c
) - 1;
4280 n_attr
= n_extra
+ 1;
4281 extra_attr
= hl_attr(HLF_8
);
4282 saved_attr2
= char_attr
; /* save current attr */
4285 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4288 #ifdef FEAT_VIRTUALEDIT
4289 else if (VIsual_active
4290 && (VIsual_mode
== Ctrl_V
4291 || VIsual_mode
== 'v')
4296 # ifdef FEAT_RIGHTLEFT
4297 wp
->w_p_rl
? (col
>= 0) :
4299 (col
< W_WIDTH(wp
))))
4302 --ptr
; /* put it back at the NUL */
4305 #if defined(LINE_ATTR)
4308 diff_hlf
!= (hlf_T
)0 ||
4312 # ifdef FEAT_RIGHTLEFT
4313 wp
->w_p_rl
? (col
>= 0) :
4315 (col
< W_WIDTH(wp
))))
4317 /* Highlight until the right side of the window */
4319 --ptr
; /* put it back at the NUL */
4321 /* Remember we do the char for line highlighting. */
4324 /* don't do search HL for the rest of the line */
4325 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4326 char_attr
= line_attr
;
4328 if (diff_hlf
== HLF_TXD
)
4331 if (attr
== 0 || char_attr
!= attr
)
4332 char_attr
= hl_attr(diff_hlf
);
4340 /* Don't override visual selection highlighting. */
4342 && draw_state
== WL_LINE
4344 char_attr
= extra_attr
;
4346 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4347 /* XIM don't send preedit_start and preedit_end, but they send
4348 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4349 * im_is_preediting() here. */
4351 && lnum
== wp
->w_cursor
.lnum
4354 && im_is_preediting()
4355 && draw_state
== WL_LINE
)
4359 if (preedit_end_col
== MAXCOL
)
4360 getvcol(curwin
, &(wp
->w_cursor
), &tcol
, NULL
, NULL
);
4362 tcol
= preedit_end_col
;
4363 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4365 if (feedback_old_attr
< 0)
4368 feedback_old_attr
= char_attr
;
4370 char_attr
= im_get_feedback_attr(feedback_col
);
4372 char_attr
= feedback_old_attr
;
4375 else if (feedback_old_attr
>= 0)
4377 char_attr
= feedback_old_attr
;
4378 feedback_old_attr
= -1;
4384 * Handle the case where we are in column 0 but not on the first
4385 * character of the line and the user wants us to show us a
4386 * special character (via 'listchars' option "precedes:<char>".
4388 if (lcs_prec_todo
!= NUL
4389 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4393 && draw_state
> WL_NR
4397 lcs_prec_todo
= NUL
;
4400 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4407 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4411 saved_attr3
= char_attr
; /* save current attr */
4412 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4418 * At end of the text line or just after the last character.
4421 #if defined(LINE_ATTR)
4422 || did_line_attr
== 1
4426 #ifdef FEAT_SEARCH_EXTRA
4427 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4429 /* we're not really at that column when skipping some text */
4430 if ((long)(wp
->w_p_wrap
? wp
->w_skipcol
: wp
->w_leftcol
) > prevcol
)
4434 /* invert at least one char, used for Visual and empty line or
4435 * highlight match at end of line. If it's beyond the last
4436 * char on the screen, just overwrite that one (tricky!) Not
4437 * needed when a '$' was displayed for 'list'. */
4438 #ifdef FEAT_SEARCH_EXTRA
4439 prevcol_hl_flag
= FALSE
;
4440 if (prevcol
== (long)search_hl
.startcol
)
4441 prevcol_hl_flag
= TRUE
;
4444 cur
= wp
->w_match_head
;
4447 if (prevcol
== (long)cur
->hl
.startcol
)
4449 prevcol_hl_flag
= TRUE
;
4456 if (lcs_eol
== lcs_eol_one
4457 && ((area_attr
!= 0 && vcol
== fromcol
4459 && (VIsual_mode
!= Ctrl_V
4460 || lnum
== VIsual
.lnum
4461 || lnum
== curwin
->w_cursor
.lnum
)
4464 #ifdef FEAT_SEARCH_EXTRA
4465 /* highlight 'hlsearch' match at end of line */
4466 || (prevcol_hl_flag
== TRUE
4467 # if defined(LINE_ATTR)
4468 && did_line_attr
<= 1
4476 #ifdef FEAT_RIGHTLEFT
4485 if (col
>= W_WIDTH(wp
))
4490 /* At the window boundary, highlight the last character
4491 * instead (better than nothing). */
4497 /* Add a blank character to highlight. */
4498 ScreenLines
[off
] = ' ';
4501 ScreenLinesUC
[off
] = 0;
4504 #ifdef FEAT_SEARCH_EXTRA
4507 /* Use attributes from match with highest priority among
4508 * 'search_hl' and the match list. */
4509 char_attr
= search_hl
.attr
;
4510 cur
= wp
->w_match_head
;
4512 while (cur
!= NULL
|| shl_flag
== FALSE
)
4514 if (shl_flag
== FALSE
4516 && cur
->priority
> SEARCH_HL_PRIORITY
)
4524 if ((ptr
- line
) - 1 == (long)shl
->startcol
)
4525 char_attr
= shl
->attr
;
4526 if (shl
!= &search_hl
&& cur
!= NULL
)
4531 ScreenAttrs
[off
] = char_attr
;
4532 #ifdef FEAT_RIGHTLEFT
4552 * At end of the text line.
4557 if (eol_hl_off
> 0 && vcol
- eol_hl_off
== (long)wp
->w_virtcol
4558 && lnum
== wp
->w_cursor
.lnum
)
4560 /* highlight last char after line */
4566 /* Highlight 'cursorcolumn' past end of the line. */
4571 /* check if line ends before left margin */
4572 if (vcol
< v
+ col
- win_col_off(wp
))
4574 vcol
= v
+ col
- win_col_off(wp
);
4576 && (int)wp
->w_virtcol
>= vcol
- eol_hl_off
4577 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4579 && lnum
!= wp
->w_cursor
.lnum
4580 # ifdef FEAT_RIGHTLEFT
4585 while (col
< W_WIDTH(wp
))
4587 ScreenLines
[off
] = ' ';
4590 ScreenLinesUC
[off
] = 0;
4593 if (vcol
== (long)wp
->w_virtcol
)
4595 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4598 ScreenAttrs
[off
++] = 0;
4604 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4609 * Update w_cline_height and w_cline_folded if the cursor line was
4610 * updated (saves a call to plines() later).
4612 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4614 curwin
->w_cline_row
= startrow
;
4615 curwin
->w_cline_height
= row
- startrow
;
4617 curwin
->w_cline_folded
= FALSE
;
4619 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4625 /* line continues beyond line end */
4632 #ifdef FEAT_RIGHTLEFT
4633 wp
->w_p_rl
? col
== 0 :
4635 col
== W_WIDTH(wp
) - 1)
4637 || (wp
->w_p_list
&& lcs_eol_one
> 0)
4638 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4641 char_attr
= hl_attr(HLF_AT
);
4644 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4656 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4657 * highlight the cursor position itself. */
4658 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4659 && lnum
!= wp
->w_cursor
.lnum
4660 && draw_state
== WL_LINE
4661 && !lnum_in_visual_area
)
4663 vcol_save_attr
= char_attr
;
4664 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4667 vcol_save_attr
= -1;
4671 * Store character to be displayed.
4672 * Skip characters that are left of the screen for 'nowrap'.
4675 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4678 * Store the character.
4680 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4681 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4683 /* A double-wide character is: put first halve in left cell. */
4688 ScreenLines
[off
] = c
;
4690 if (enc_dbcs
== DBCS_JPNU
)
4692 if ((mb_c
& 0xff00) == 0x8e00)
4693 ScreenLines
[off
] = 0x8e;
4694 ScreenLines2
[off
] = mb_c
& 0xff;
4702 ScreenLinesUC
[off
] = mb_c
;
4703 if ((c
& 0xff) == 0)
4704 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4705 for (i
= 0; i
< Screen_mco
; ++i
)
4707 ScreenLinesC
[i
][off
] = u8cc
[i
];
4713 ScreenLinesUC
[off
] = 0;
4717 ScreenAttrs
[off
] = multi_attr
;
4722 ScreenAttrs
[off
] = char_attr
;
4725 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4727 /* Need to fill two screen columns. */
4731 /* UTF-8: Put a 0 in the second screen char. */
4732 ScreenLines
[off
] = 0;
4734 /* DBCS: Put second byte in the second screen char. */
4735 ScreenLines
[off
] = mb_c
& 0xff;
4737 /* When "tocol" is halfway a character, set it to the end of
4738 * the character, otherwise highlighting won't stop. */
4741 #ifdef FEAT_RIGHTLEFT
4744 /* now it's time to backup one cell */
4751 #ifdef FEAT_RIGHTLEFT
4767 /* Only advance the "vcol" when after the 'number' or 'relativenumber'
4769 if (draw_state
> WL_NR
4777 if (vcol_save_attr
>= 0)
4778 char_attr
= vcol_save_attr
;
4781 /* restore attributes after "predeces" in 'listchars' */
4782 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4783 char_attr
= saved_attr3
;
4785 /* restore attributes after last 'listchars' or 'number' char */
4786 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4787 char_attr
= saved_attr2
;
4790 * At end of screen line and there is more to come: Display the line
4791 * so far. If there is no more to display it is caught above.
4794 #ifdef FEAT_RIGHTLEFT
4795 wp
->w_p_rl
? (col
< 0) :
4797 (col
>= W_WIDTH(wp
)))
4802 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4803 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4806 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4811 /* When not wrapping and finished diff lines, or when displayed
4812 * '$' and highlighting until last column, break here. */
4817 ) || lcs_eol_one
== -1)
4820 /* When the window is too narrow draw all "@" lines. */
4821 if (draw_state
!= WL_LINE
4827 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4828 #ifdef FEAT_VERTSPLIT
4829 draw_vsep_win(wp
, row
);
4834 /* When line got too long for screen break here. */
4841 if (screen_cur_row
== screen_row
- 1
4845 && W_WIDTH(wp
) == Columns
)
4847 /* Remember that the line wraps, used for modeless copy. */
4848 LineWraps
[screen_row
- 1] = TRUE
;
4851 * Special trick to make copy/paste of wrapped lines work with
4852 * xterm/screen: write an extra character beyond the end of
4853 * the line. This will work with all terminal types
4854 * (regardless of the xn,am settings).
4855 * Only do this on a fast tty.
4856 * Only do this if the cursor is on the current line
4857 * (something has been written in it).
4858 * Don't do this for the GUI.
4859 * Don't do this for double-width characters.
4860 * Don't do this for a window not at the right screen border.
4868 && ((*mb_off2cells
)(LineOffset
[screen_row
],
4869 LineOffset
[screen_row
] + screen_Columns
)
4871 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4873 LineOffset
[screen_row
] + screen_Columns
)
4878 /* First make sure we are at the end of the screen line,
4879 * then output the same character again to let the
4880 * terminal know about the wrap. If the terminal doesn't
4881 * auto-wrap, we overwrite the character. */
4882 if (screen_cur_col
!= W_WIDTH(wp
))
4883 screen_char(LineOffset
[screen_row
- 1]
4884 + (unsigned)Columns
- 1,
4885 screen_row
- 1, (int)(Columns
- 1));
4888 /* When there is a multi-byte character, just output a
4889 * space to keep it simple. */
4890 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4891 screen_row
- 1] + (Columns
- 1)]) > 1)
4895 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4897 /* force a redraw of the first char on the next line */
4898 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4899 screen_start(); /* don't know where cursor is now */
4904 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4905 #ifdef FEAT_RIGHTLEFT
4908 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4913 /* reset the drawing state for the start of a wrapped line */
4914 draw_state
= WL_START
;
4915 saved_n_extra
= n_extra
;
4916 saved_p_extra
= p_extra
;
4917 saved_c_extra
= c_extra
;
4918 saved_char_attr
= char_attr
;
4920 lcs_prec_todo
= lcs_prec
;
4921 #ifdef FEAT_LINEBREAK
4923 if (filler_todo
<= 0)
4925 need_showbreak
= TRUE
;
4929 /* When the filler lines are actually below the last line of the
4930 * file, don't draw the line itself, break here. */
4931 if (filler_todo
== 0 && wp
->w_botfill
)
4936 } /* for every character in the line */
4939 /* After an empty line check first word for capital. */
4940 if (*skipwhite(line
) == NUL
)
4942 capcol_lnum
= lnum
+ 1;
4951 static int comp_char_differs
__ARGS((int, int));
4954 * Return if the composing characters at "off_from" and "off_to" differ.
4955 * Only to be used when ScreenLinesUC[off_from] != 0.
4958 comp_char_differs(off_from
, off_to
)
4964 for (i
= 0; i
< Screen_mco
; ++i
)
4966 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4968 if (ScreenLinesC
[i
][off_from
] == 0)
4976 * Check whether the given character needs redrawing:
4977 * - the (first byte of the) character is different
4978 * - the attributes are different
4979 * - the character is multi-byte and the next byte is different
4980 * - the character is two cells wide and the second cell differs.
4983 char_needs_redraw(off_from
, off_to
, cols
)
4989 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4990 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4994 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4995 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4996 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4997 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4998 != ScreenLines
[off_to
+ 1])))
5000 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
5001 || (ScreenLinesUC
[off_from
] != 0
5002 && comp_char_differs(off_from
, off_to
))
5003 || (cols
> 1 && ScreenLines
[off_from
+ 1]
5004 != ScreenLines
[off_to
+ 1])))
5012 * Move one "cooked" screen line to the screen, but only the characters that
5013 * have actually changed. Handle insert/delete character.
5014 * "coloff" gives the first column on the screen for this line.
5015 * "endcol" gives the columns where valid characters are.
5016 * "clear_width" is the width of the window. It's > 0 if the rest of the line
5017 * needs to be cleared, negative otherwise.
5018 * "rlflag" is TRUE in a rightleft window:
5019 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
5020 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
5023 screen_line(row
, coloff
, endcol
, clear_width
5024 #ifdef FEAT_RIGHTLEFT
5032 #ifdef FEAT_RIGHTLEFT
5039 unsigned max_off_from
;
5040 unsigned max_off_to
;
5043 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
5046 int force
= FALSE
; /* force update rest of the line */
5047 int redraw_this
/* bool: does character need redraw? */
5049 = TRUE
/* For GUI when while-loop empty */
5052 int redraw_next
; /* redraw_this for next character */
5054 int clear_next
= FALSE
;
5055 int char_cells
; /* 1: normal char */
5056 /* 2: occupies two display cells */
5057 # define CHAR_CELLS char_cells
5059 # define CHAR_CELLS 1
5062 # ifdef FEAT_CLIPBOARD
5063 clip_may_clear_selection(row
, row
);
5066 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
5067 off_to
= LineOffset
[row
] + coloff
;
5069 max_off_from
= off_from
+ screen_Columns
;
5070 max_off_to
= LineOffset
[row
] + screen_Columns
;
5073 #ifdef FEAT_RIGHTLEFT
5076 /* Clear rest first, because it's left of the text. */
5077 if (clear_width
> 0)
5079 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
5080 && ScreenAttrs
[off_to
] == 0
5082 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5090 screen_fill(row
, row
+ 1, col
+ coloff
,
5091 endcol
+ coloff
+ 1, ' ', ' ', 0);
5094 off_to
= LineOffset
[row
] + col
+ coloff
;
5096 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
5098 #endif /* FEAT_RIGHTLEFT */
5100 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
5102 while (col
< endcol
)
5105 if (has_mbyte
&& (col
+ 1 < endcol
))
5106 char_cells
= (*mb_off2cells
)(off_from
, max_off_from
);
5111 redraw_this
= redraw_next
;
5112 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
5113 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
5116 /* If the next character was bold, then redraw the current character to
5117 * remove any pixels that might have spilt over into us. This only
5118 * happens in the GUI.
5120 if (redraw_next
&& gui
.in_use
)
5122 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
5124 hl
= syn_attr2attr(hl
);
5133 * Special handling when 'xs' termcap flag set (hpterm):
5134 * Attributes for characters are stored at the position where the
5135 * cursor is when writing the highlighting code. The
5136 * start-highlighting code must be written with the cursor on the
5137 * first highlighted character. The stop-highlighting code must
5138 * be written with the cursor just after the last highlighted
5140 * Overwriting a character doesn't remove it's highlighting. Need
5141 * to clear the rest of the line, and force redrawing it
5149 && ScreenAttrs
[off_to
] != 0
5150 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
5153 * Need to remove highlighting attributes here.
5155 windgoto(row
, col
+ coloff
);
5156 out_str(T_CE
); /* clear rest of this screen line */
5157 screen_start(); /* don't know where cursor is now */
5158 force
= TRUE
; /* force redraw of rest of the line */
5159 redraw_next
= TRUE
; /* or else next char would miss out */
5162 * If the previous character was highlighted, need to stop
5163 * highlighting at this character.
5165 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
5167 screen_attr
= ScreenAttrs
[off_to
- 1];
5168 term_windgoto(row
, col
+ coloff
);
5169 screen_stop_highlight();
5172 screen_attr
= 0; /* highlighting has stopped */
5177 /* Check if overwriting a double-byte with a single-byte or
5178 * the other way around requires another character to be
5179 * redrawn. For UTF-8 this isn't needed, because comparing
5180 * ScreenLinesUC[] is sufficient. */
5183 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5185 /* Writing a single-cell character over a double-cell
5186 * character: need to redraw the next cell. */
5187 ScreenLines
[off_to
+ 1] = 0;
5190 else if (char_cells
== 2
5192 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5193 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)
5195 /* Writing the second half of a double-cell character over
5196 * a double-cell character: need to redraw the second
5198 ScreenLines
[off_to
+ 2] = 0;
5202 if (enc_dbcs
== DBCS_JPNU
)
5203 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
5205 /* When writing a single-width character over a double-width
5206 * character and at the end of the redrawn text, need to clear out
5207 * the right halve of the old character.
5208 * Also required when writing the right halve of a double-width
5209 * char over the left halve of an existing one. */
5210 if (has_mbyte
&& col
+ char_cells
== endcol
5211 && ((char_cells
== 1
5212 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5214 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5215 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)))
5219 ScreenLines
[off_to
] = ScreenLines
[off_from
];
5223 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
5224 if (ScreenLinesUC
[off_from
] != 0)
5228 for (i
= 0; i
< Screen_mco
; ++i
)
5229 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
5232 if (char_cells
== 2)
5233 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
5236 #if defined(FEAT_GUI) || defined(UNIX)
5237 /* The bold trick makes a single column of pixels appear in the
5238 * next character. When a bold character is removed, the next
5239 * character should be redrawn too. This happens for our own GUI
5240 * and for some xterms. */
5245 # if defined(FEAT_GUI) && defined(UNIX)
5253 hl
= ScreenAttrs
[off_to
];
5255 hl
= syn_attr2attr(hl
);
5260 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5262 /* For simplicity set the attributes of second half of a
5263 * double-wide character equal to the first half. */
5264 if (char_cells
== 2)
5265 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5267 if (enc_dbcs
!= 0 && char_cells
== 2)
5268 screen_char_2(off_to
, row
, col
+ coloff
);
5271 screen_char(off_to
, row
, col
+ coloff
);
5277 && col
+ coloff
> 0)
5279 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5282 * Don't output stop-highlight when moving the cursor, it will
5283 * stop the highlighting when it should continue.
5287 else if (screen_attr
!= 0)
5288 screen_stop_highlight();
5291 off_to
+= CHAR_CELLS
;
5292 off_from
+= CHAR_CELLS
;
5299 /* Clear the second half of a double-wide character of which the left
5300 * half was overwritten with a single-wide character. */
5301 ScreenLines
[off_to
] = ' ';
5303 ScreenLinesUC
[off_to
] = 0;
5304 screen_char(off_to
, row
, col
+ coloff
);
5309 #ifdef FEAT_RIGHTLEFT
5318 /* blank out the rest of the line */
5319 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5320 && ScreenAttrs
[off_to
] == 0
5322 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5329 if (col
< clear_width
)
5333 * In the GUI, clearing the rest of the line may leave pixels
5334 * behind if the first character cleared was bold. Some bold
5335 * fonts spill over the left. In this case we redraw the previous
5336 * character too. If we didn't skip any blanks above, then we
5337 * only redraw if the character wasn't already redrawn anyway.
5339 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5341 hl
= ScreenAttrs
[off_to
];
5342 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5347 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5348 * that its width is 2. */
5349 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5350 else if (enc_dbcs
!= 0)
5352 /* find previous character by counting from first
5353 * column and get its width. */
5354 unsigned off
= LineOffset
[row
];
5355 unsigned max_off
= LineOffset
[row
] + screen_Columns
;
5357 while (off
< off_to
)
5359 prev_cells
= (*mb_off2cells
)(off
, max_off
);
5364 if (enc_dbcs
!= 0 && prev_cells
> 1)
5365 screen_char_2(off_to
- prev_cells
, row
,
5366 col
+ coloff
- prev_cells
);
5369 screen_char(off_to
- prev_cells
, row
,
5370 col
+ coloff
- prev_cells
);
5374 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5376 #ifdef FEAT_VERTSPLIT
5377 off_to
+= clear_width
- col
;
5383 if (clear_width
> 0)
5385 #ifdef FEAT_VERTSPLIT
5386 /* For a window that's left of another, draw the separator char. */
5387 if (col
+ coloff
< Columns
)
5391 c
= fillchar_vsep(&hl
);
5392 if (ScreenLines
[off_to
] != c
5394 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5395 != (c
>= 0x80 ? c
: 0))
5397 || ScreenAttrs
[off_to
] != hl
)
5399 ScreenLines
[off_to
] = c
;
5400 ScreenAttrs
[off_to
] = hl
;
5406 ScreenLinesUC
[off_to
] = c
;
5407 ScreenLinesC
[0][off_to
] = 0;
5410 ScreenLinesUC
[off_to
] = 0;
5413 screen_char(off_to
, row
, col
+ coloff
);
5418 LineWraps
[row
] = FALSE
;
5422 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5424 * Mirror text "str" for right-left displaying.
5425 * Only works for single-byte characters (e.g., numbers).
5434 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5443 #if defined(FEAT_WINDOWS) || defined(PROTO)
5445 * mark all status lines for redraw; used after first :cd
5452 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5453 if (wp
->w_status_height
)
5455 wp
->w_redr_status
= TRUE
;
5456 redraw_later(VALID
);
5461 * mark all status lines of the current buffer for redraw
5464 status_redraw_curbuf()
5468 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5469 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5471 wp
->w_redr_status
= TRUE
;
5472 redraw_later(VALID
);
5477 * Redraw all status lines that need to be redrawn.
5480 redraw_statuslines()
5484 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5485 if (wp
->w_redr_status
)
5486 win_redr_status(wp
);
5492 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5494 * Redraw all status lines at the bottom of frame "frp".
5497 win_redraw_last_status(frp
)
5500 if (frp
->fr_layout
== FR_LEAF
)
5501 frp
->fr_win
->w_redr_status
= TRUE
;
5502 else if (frp
->fr_layout
== FR_ROW
)
5504 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5505 win_redraw_last_status(frp
);
5507 else /* frp->fr_layout == FR_COL */
5509 frp
= frp
->fr_child
;
5510 while (frp
->fr_next
!= NULL
)
5512 win_redraw_last_status(frp
);
5517 #ifdef FEAT_VERTSPLIT
5519 * Draw the verticap separator right of window "wp" starting with line "row".
5522 draw_vsep_win(wp
, row
)
5529 if (wp
->w_vsep_width
)
5531 /* draw the vertical separator right of this window */
5532 c
= fillchar_vsep(&hl
);
5533 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5534 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5540 #ifdef FEAT_WILDMENU
5541 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5542 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5545 * Get the length of an item as it will be shown in the status line.
5548 status_match_len(xp
, s
)
5555 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5556 || xp
->xp_context
== EXPAND_MENUNAMES
);
5558 /* Check for menu separators - replace with '|'. */
5559 if (emenu
&& menu_is_separator(s
))
5565 s
+= skip_status_match_char(xp
, s
);
5566 len
+= ptr2cells(s
);
5574 * Return the number of characters that should be skipped in a status match.
5575 * These are backslashes used for escaping. Do show backslashes in help tags.
5578 skip_status_match_char(xp
, s
)
5582 if ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5584 || ((xp
->xp_context
== EXPAND_MENUS
5585 || xp
->xp_context
== EXPAND_MENUNAMES
)
5586 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5590 #ifndef BACKSLASH_IN_FILENAME
5591 if (xp
->xp_shell
&& csh_like_shell() && s
[1] == '\\' && s
[2] == '!')
5600 * Show wildchar matches in the status line.
5601 * Show at least the "match" item.
5602 * We start at item 'first_match' in the list and show all matches that fit.
5604 * If inversion is possible we use it. Else '=' characters are used.
5607 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5610 char_u
**matches
; /* list of matches */
5614 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5618 int clen
; /* length in screen cells */
5622 int highlight
= TRUE
;
5623 char_u
*selstart
= NULL
;
5624 int selstart_col
= 0;
5625 char_u
*selend
= NULL
;
5626 static int first_match
= 0;
5627 int add_left
= FALSE
;
5632 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5636 if (matches
== NULL
) /* interrupted completion? */
5641 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5644 buf
= alloc((unsigned)Columns
+ 1);
5648 if (match
== -1) /* don't show match but original text */
5653 /* count 1 for the ending ">" */
5654 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5657 else if (match
< first_match
)
5659 /* jumping left, as far as we can go */
5660 first_match
= match
;
5665 /* check if match fits on the screen */
5666 for (i
= first_match
; i
< match
; ++i
)
5667 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5668 if (first_match
> 0)
5670 /* jumping right, put match at the left */
5671 if ((long)clen
> Columns
)
5673 first_match
= match
;
5674 /* if showing the last match, we can add some on the left */
5676 for (i
= match
; i
< num_matches
; ++i
)
5678 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5679 if ((long)clen
>= Columns
)
5682 if (i
== num_matches
)
5687 while (first_match
> 0)
5689 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5690 if ((long)clen
>= Columns
)
5695 fillchar
= fillchar_status(&attr
, TRUE
);
5697 if (first_match
== 0)
5710 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5714 selstart
= buf
+ len
;
5715 selstart_col
= clen
;
5719 /* Check for menu separators - replace with '|' */
5721 emenu
= (xp
->xp_context
== EXPAND_MENUS
5722 || xp
->xp_context
== EXPAND_MENUNAMES
);
5723 if (emenu
&& menu_is_separator(s
))
5725 STRCPY(buf
+ len
, transchar('|'));
5726 l
= (int)STRLEN(buf
+ len
);
5732 for ( ; *s
!= NUL
; ++s
)
5734 s
+= skip_status_match_char(xp
, s
);
5735 clen
+= ptr2cells(s
);
5737 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5739 STRNCPY(buf
+ len
, s
, l
);
5746 STRCPY(buf
+ len
, transchar_byte(*s
));
5747 len
+= (int)STRLEN(buf
+ len
);
5753 *(buf
+ len
++) = ' ';
5754 *(buf
+ len
++) = ' ';
5756 if (++i
== num_matches
)
5760 if (i
!= num_matches
)
5762 *(buf
+ len
++) = '>';
5768 row
= cmdline_row
- 1;
5771 if (wild_menu_showing
== 0)
5773 if (msg_scrolled
> 0)
5775 /* Put the wildmenu just above the command line. If there is
5776 * no room, scroll the screen one line up. */
5777 if (cmdline_row
== Rows
- 1)
5779 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5787 wild_menu_showing
= WM_SCROLLED
;
5791 /* Create status line if needed by setting 'laststatus' to 2.
5792 * Set 'winminheight' to zero to avoid that the window is
5794 if (lastwin
->w_status_height
== 0)
5802 wild_menu_showing
= WM_SHOWN
;
5806 screen_puts(buf
, row
, 0, attr
);
5807 if (selstart
!= NULL
&& highlight
)
5810 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5813 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5816 #ifdef FEAT_VERTSPLIT
5817 win_redraw_last_status(topframe
);
5819 lastwin
->w_redr_status
= TRUE
;
5825 #if defined(FEAT_WINDOWS) || defined(PROTO)
5827 * Redraw the status line of window wp.
5829 * If inversion is possible we use it. Else '=' characters are used.
5841 static int busy
= FALSE
;
5843 /* It's possible to get here recursively when 'statusline' (indirectly)
5844 * invokes ":redrawstatus". Simply ignore the call then. */
5849 wp
->w_redr_status
= FALSE
;
5850 if (wp
->w_status_height
== 0)
5852 /* no status line, can only be last window */
5853 redraw_cmdline
= TRUE
;
5855 else if (!redrawing()
5856 #ifdef FEAT_INS_EXPAND
5857 /* don't update status line when popup menu is visible and may be
5863 /* Don't redraw right now, do it later. */
5864 wp
->w_redr_status
= TRUE
;
5867 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5869 /* redraw custom status line */
5870 redraw_custom_statusline(wp
);
5875 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5877 get_trans_bufname(wp
->w_buffer
);
5879 len
= (int)STRLEN(p
);
5881 if (wp
->w_buffer
->b_help
5882 #ifdef FEAT_QUICKFIX
5885 || bufIsChanged(wp
->w_buffer
)
5886 || wp
->w_buffer
->b_p_ro
)
5888 if (wp
->w_buffer
->b_help
)
5890 STRCPY(p
+ len
, _("[Help]"));
5891 len
+= (int)STRLEN(p
+ len
);
5893 #ifdef FEAT_QUICKFIX
5896 STRCPY(p
+ len
, _("[Preview]"));
5897 len
+= (int)STRLEN(p
+ len
);
5900 if (bufIsChanged(wp
->w_buffer
))
5902 STRCPY(p
+ len
, "[+]");
5905 if (wp
->w_buffer
->b_p_ro
)
5907 STRCPY(p
+ len
, "[RO]");
5911 #ifndef FEAT_VERTSPLIT
5912 this_ru_col
= ru_col
;
5913 if (this_ru_col
< (Columns
+ 1) / 2)
5914 this_ru_col
= (Columns
+ 1) / 2;
5916 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5917 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5918 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5919 if (this_ru_col
<= 1)
5921 p
= (char_u
*)"<"; /* No room for file name! */
5931 /* Count total number of display cells. */
5932 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5933 clen
+= (*mb_ptr2cells
)(p
+ i
);
5934 /* Find first character that will fit.
5935 * Going from start to end is much faster for DBCS. */
5936 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5937 i
+= (*mb_ptr2len
)(p
+ i
))
5938 clen
-= (*mb_ptr2cells
)(p
+ i
);
5950 if (len
> this_ru_col
- 1)
5952 p
+= len
- (this_ru_col
- 1);
5954 len
= this_ru_col
- 1;
5957 row
= W_WINROW(wp
) + wp
->w_height
;
5958 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5959 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5960 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5962 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5963 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5964 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5965 - 1 + W_WINCOL(wp
)), attr
);
5967 #ifdef FEAT_CMDL_INFO
5968 win_redr_ruler(wp
, TRUE
);
5972 #ifdef FEAT_VERTSPLIT
5974 * May need to draw the character below the vertical separator.
5976 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5978 if (stl_connected(wp
))
5979 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5981 fillchar
= fillchar_vsep(&attr
);
5982 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5991 * Redraw the status line according to 'statusline' and take care of any
5992 * errors encountered.
5995 redraw_custom_statusline(wp
)
5998 static int entered
= FALSE
;
5999 int save_called_emsg
= called_emsg
;
6001 /* When called recursively return. This can happen when the statusline
6002 * contains an expression that triggers a redraw. */
6007 called_emsg
= FALSE
;
6008 win_redr_custom(wp
, FALSE
);
6011 /* When there is an error disable the statusline, otherwise the
6012 * display is messed up with errors and a redraw triggers the problem
6013 * again and again. */
6014 set_string_option_direct((char_u
*)"statusline", -1,
6015 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
6016 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
6018 called_emsg
|= save_called_emsg
;
6023 # ifdef FEAT_VERTSPLIT
6025 * Return TRUE if the status line of window "wp" is connected to the status
6026 * line of the window right of it. If not, then it's a vertical separator.
6027 * Only call if (wp->w_vsep_width != 0).
6036 while (fr
->fr_parent
!= NULL
)
6038 if (fr
->fr_parent
->fr_layout
== FR_COL
)
6040 if (fr
->fr_next
!= NULL
)
6045 if (fr
->fr_next
!= NULL
)
6054 #endif /* FEAT_WINDOWS */
6056 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
6058 * Get the value to show for the language mappings, active 'keymap'.
6061 get_keymap_str(wp
, buf
, len
)
6063 char_u
*buf
; /* buffer for the result */
6064 int len
; /* length of buffer */
6068 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
6073 buf_T
*old_curbuf
= curbuf
;
6074 win_T
*old_curwin
= curwin
;
6077 curbuf
= wp
->w_buffer
;
6079 STRCPY(buf
, "b:keymap_name"); /* must be writable */
6081 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
6083 curbuf
= old_curbuf
;
6084 curwin
= old_curwin
;
6085 if (p
== NULL
|| *p
== NUL
)
6089 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
6090 p
= wp
->w_buffer
->b_p_keymap
;
6093 p
= (char_u
*)"lang";
6095 if ((int)(STRLEN(p
) + 3) < len
)
6096 sprintf((char *)buf
, "<%s>", p
);
6103 return buf
[0] != NUL
;
6107 #if defined(FEAT_STL_OPT) || defined(PROTO)
6109 * Redraw the status line or ruler of window "wp".
6110 * When "wp" is NULL redraw the tab pages line from 'tabline'.
6113 win_redr_custom(wp
, draw_ruler
)
6115 int draw_ruler
; /* TRUE or FALSE */
6126 char_u buf
[MAXPATHL
];
6129 struct stl_hlrec hltab
[STL_MAX_ITEM
];
6130 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
6131 int use_sandbox
= FALSE
;
6133 /* setup environment for the task at hand */
6136 /* Use 'tabline'. Always at the first line of the screen. */
6140 attr
= hl_attr(HLF_TPF
);
6143 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
6148 row
= W_WINROW(wp
) + wp
->w_height
;
6149 fillchar
= fillchar_status(&attr
, wp
== curwin
);
6150 maxwidth
= W_WIDTH(wp
);
6155 /* advance past any leading group spec - implicit in ru_col */
6160 if (atoi((char *)stl
))
6161 while (VIM_ISDIGIT(*stl
))
6166 #ifdef FEAT_VERTSPLIT
6167 col
= ru_col
- (Columns
- W_WIDTH(wp
));
6168 if (col
< (W_WIDTH(wp
) + 1) / 2)
6169 col
= (W_WIDTH(wp
) + 1) / 2;
6172 if (col
> (Columns
+ 1) / 2)
6173 col
= (Columns
+ 1) / 2;
6175 maxwidth
= W_WIDTH(wp
) - col
;
6177 if (!wp
->w_status_height
)
6181 --maxwidth
; /* writing in last column may cause scrolling */
6187 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
6192 if (*wp
->w_p_stl
!= NUL
)
6197 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
6198 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
6202 #ifdef FEAT_VERTSPLIT
6203 col
+= W_WINCOL(wp
);
6210 /* Make a copy, because the statusline may include a function call that
6211 * might change the option value and free the memory. */
6212 stl
= vim_strsave(stl
);
6213 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
6216 fillchar
, maxwidth
, hltab
, tabtab
);
6218 len
= (int)STRLEN(buf
);
6220 while (width
< maxwidth
&& len
< (int)sizeof(buf
) - 1)
6223 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
6225 buf
[len
++] = fillchar
;
6232 * Draw each snippet with the specified highlighting.
6236 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
6238 len
= (int)(hltab
[n
].start
- p
);
6239 screen_puts_len(p
, len
, row
, col
, curattr
);
6240 col
+= vim_strnsize(p
, len
);
6243 if (hltab
[n
].userhl
== 0)
6245 else if (hltab
[n
].userhl
< 0)
6246 curattr
= syn_id2attr(-hltab
[n
].userhl
);
6248 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
6249 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
6252 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
6254 screen_puts(p
, row
, col
, curattr
);
6258 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6263 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
6265 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
6267 TabPageIdxs
[col
++] = fillchar
;
6268 p
= tabtab
[n
].start
;
6269 fillchar
= tabtab
[n
].userhl
;
6271 while (col
< Columns
)
6272 TabPageIdxs
[col
++] = fillchar
;
6276 #endif /* FEAT_STL_OPT */
6279 * Output a single character directly to the screen and update ScreenLines.
6282 screen_putchar(c
, row
, col
, attr
)
6288 char_u buf
[MB_MAXBYTES
+ 1];
6290 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6297 screen_puts(buf
, row
, col
, attr
);
6301 * Get a single character directly from ScreenLines into "bytes[]".
6302 * Also return its attribute in *attrp;
6305 screen_getbytes(row
, col
, bytes
, attrp
)
6313 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6315 off
= LineOffset
[row
] + col
;
6316 *attrp
= ScreenAttrs
[off
];
6317 bytes
[0] = ScreenLines
[off
];
6321 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6322 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6323 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6325 bytes
[0] = ScreenLines
[off
];
6326 bytes
[1] = ScreenLines2
[off
];
6329 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6331 bytes
[1] = ScreenLines
[off
+ 1];
6339 static int screen_comp_differs
__ARGS((int, int*));
6342 * Return TRUE if composing characters for screen posn "off" differs from
6343 * composing characters in "u8cc".
6344 * Only to be used when ScreenLinesUC[off] != 0.
6347 screen_comp_differs(off
, u8cc
)
6353 for (i
= 0; i
< Screen_mco
; ++i
)
6355 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6365 * Put string '*text' on the screen at position 'row' and 'col', with
6366 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6367 * Note: only outputs within one row, message is truncated at screen boundary!
6368 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6371 screen_puts(text
, row
, col
, attr
)
6377 screen_puts_len(text
, -1, row
, col
, attr
);
6381 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6385 screen_puts_len(text
, len
, row
, col
, attr
)
6398 int mbyte_cells
= 1;
6401 int clear_next_cell
= FALSE
;
6403 int prev_c
= 0; /* previous Arabic character */
6408 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6409 int force_redraw_this
;
6410 int force_redraw_next
= FALSE
;
6414 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6416 off
= LineOffset
[row
] + col
;
6419 /* When drawing over the right halve of a double-wide char clear out the
6420 * left halve. Only needed in a terminal. */
6421 if (has_mbyte
&& col
> 0 && col
< screen_Columns
6425 && mb_fix_col(col
, row
) != col
)
6427 ScreenLines
[off
- 1] = ' ';
6428 ScreenAttrs
[off
- 1] = 0;
6431 ScreenLinesUC
[off
- 1] = 0;
6432 ScreenLinesC
[0][off
- 1] = 0;
6434 /* redraw the previous cell, make it empty */
6435 screen_char(off
- 1, row
, col
- 1);
6436 /* force the cell at "col" to be redrawn */
6437 force_redraw_next
= TRUE
;
6442 max_off
= LineOffset
[row
] + screen_Columns
;
6444 while (col
< screen_Columns
6445 && (len
< 0 || (int)(ptr
- text
) < len
)
6450 /* check if this is the first byte of a multibyte */
6453 if (enc_utf8
&& len
> 0)
6454 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6456 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6457 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6459 else if (enc_dbcs
!= 0)
6460 mbyte_cells
= mbyte_blen
;
6464 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6465 (int)((text
+ len
) - ptr
));
6467 u8c
= utfc_ptr2char(ptr
, u8cc
);
6468 mbyte_cells
= utf_char2cells(u8c
);
6470 /* Non-BMP character: display as ? or fullwidth ?. */
6473 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6475 attr
= hl_attr(HLF_8
);
6479 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6481 /* Do Arabic shaping. */
6482 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6484 /* Past end of string to be displayed. */
6490 nc
= utfc_ptr2char_len(ptr
+ mbyte_blen
, pcc
,
6491 (int)((text
+ len
) - ptr
- mbyte_blen
));
6496 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6501 if (col
+ mbyte_cells
> screen_Columns
)
6503 /* Only 1 cell left, but character requires 2 cells:
6504 * display a '>' in the last column to avoid wrapping. */
6512 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6513 force_redraw_this
= force_redraw_next
;
6514 force_redraw_next
= FALSE
;
6517 need_redraw
= ScreenLines
[off
] != c
6519 || (mbyte_cells
== 2
6520 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6521 || (enc_dbcs
== DBCS_JPNU
6523 && ScreenLines2
[off
] != ptr
[1])
6525 && (ScreenLinesUC
[off
] !=
6526 (u8char_T
)(c
< 0x80 && u8cc
[0] == 0 ? 0 : u8c
)
6527 || (ScreenLinesUC
[off
] != 0
6528 && screen_comp_differs(off
, u8cc
))))
6530 || ScreenAttrs
[off
] != attr
6534 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6535 || force_redraw_this
6539 #if defined(FEAT_GUI) || defined(UNIX)
6540 /* The bold trick makes a single row of pixels appear in the next
6541 * character. When a bold character is removed, the next
6542 * character should be redrawn too. This happens for our own GUI
6543 * and for some xterms. */
6544 if (need_redraw
&& ScreenLines
[off
] != ' ' && (
6548 # if defined(FEAT_GUI) && defined(UNIX)
6556 int n
= ScreenAttrs
[off
];
6559 n
= syn_attr2attr(n
);
6561 force_redraw_next
= TRUE
;
6565 /* When at the end of the text and overwriting a two-cell
6566 * character with a one-cell character, need to clear the next
6567 * cell. Also when overwriting the left halve of a two-cell char
6568 * with the right halve of a two-cell char. Do this only once
6569 * (mb_off2cells() may return 2 on the right halve). */
6570 if (clear_next_cell
)
6571 clear_next_cell
= FALSE
;
6573 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6574 : ptr
+ mbyte_blen
>= text
+ len
)
6575 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6576 || (mbyte_cells
== 2
6577 && (*mb_off2cells
)(off
, max_off
) == 1
6578 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6579 clear_next_cell
= TRUE
;
6581 /* Make sure we never leave a second byte of a double-byte behind,
6582 * it confuses mb_off2cells(). */
6584 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6585 || (mbyte_cells
== 2
6586 && (*mb_off2cells
)(off
, max_off
) == 1
6587 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6588 ScreenLines
[off
+ mbyte_blen
] = 0;
6590 ScreenLines
[off
] = c
;
6591 ScreenAttrs
[off
] = attr
;
6595 if (c
< 0x80 && u8cc
[0] == 0)
6596 ScreenLinesUC
[off
] = 0;
6601 ScreenLinesUC
[off
] = u8c
;
6602 for (i
= 0; i
< Screen_mco
; ++i
)
6604 ScreenLinesC
[i
][off
] = u8cc
[i
];
6609 if (mbyte_cells
== 2)
6611 ScreenLines
[off
+ 1] = 0;
6612 ScreenAttrs
[off
+ 1] = attr
;
6614 screen_char(off
, row
, col
);
6616 else if (mbyte_cells
== 2)
6618 ScreenLines
[off
+ 1] = ptr
[1];
6619 ScreenAttrs
[off
+ 1] = attr
;
6620 screen_char_2(off
, row
, col
);
6622 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6624 ScreenLines2
[off
] = ptr
[1];
6625 screen_char(off
, row
, col
);
6629 screen_char(off
, row
, col
);
6637 if (clear_next_cell
)
6638 ptr
= (char_u
*)" ";
6649 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6650 /* If we detected the next character needs to be redrawn, but the text
6651 * doesn't extend up to there, update the character here. */
6652 if (force_redraw_next
&& col
< screen_Columns
)
6655 if (enc_dbcs
!= 0 && dbcs_off2cells(off
, max_off
) > 1)
6656 screen_char_2(off
, row
, col
);
6659 screen_char(off
, row
, col
);
6664 #ifdef FEAT_SEARCH_EXTRA
6666 * Prepare for 'hlsearch' highlighting.
6671 if (p_hls
&& !no_hlsearch
)
6673 last_pat_prog(&search_hl
.rm
);
6674 search_hl
.attr
= hl_attr(HLF_L
);
6675 # ifdef FEAT_RELTIME
6676 /* Set the time limit to 'redrawtime'. */
6677 profile_setlimit(p_rdt
, &search_hl
.tm
);
6683 * Clean up for 'hlsearch' highlighting.
6688 if (search_hl
.rm
.regprog
!= NULL
)
6690 vim_free(search_hl
.rm
.regprog
);
6691 search_hl
.rm
.regprog
= NULL
;
6696 * Advance to the match in window "wp" line "lnum" or past it.
6699 prepare_search_hl(wp
, lnum
)
6703 matchitem_T
*cur
; /* points to the match list */
6704 match_T
*shl
; /* points to search_hl or a match */
6705 int shl_flag
; /* flag to indicate whether search_hl
6706 has been processed or not */
6710 * When using a multi-line pattern, start searching at the top
6711 * of the window or just after a closed fold.
6712 * Do this both for search_hl and the match list.
6714 cur
= wp
->w_match_head
;
6716 while (cur
!= NULL
|| shl_flag
== FALSE
)
6718 if (shl_flag
== FALSE
)
6725 if (shl
->rm
.regprog
!= NULL
6727 && re_multiline(shl
->rm
.regprog
))
6729 if (shl
->first_lnum
== 0)
6731 # ifdef FEAT_FOLDING
6732 for (shl
->first_lnum
= lnum
;
6733 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6734 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6735 NULL
, NULL
, TRUE
, NULL
))
6738 shl
->first_lnum
= wp
->w_topline
;
6742 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6744 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6747 shl
->first_lnum
= shl
->lnum
6748 + shl
->rm
.endpos
[0].lnum
6749 - shl
->rm
.startpos
[0].lnum
;
6750 n
= shl
->rm
.endpos
[0].col
;
6759 if (shl
!= &search_hl
&& cur
!= NULL
)
6765 * Search for a next 'hlsearch' or match.
6767 * Sets shl->lnum and shl->rm contents.
6768 * Note: Assumes a previous match is always before "lnum", unless
6769 * shl->lnum is zero.
6770 * Careful: Any pointers for buffer lines will become invalid.
6773 next_search_hl(win
, shl
, lnum
, mincol
)
6775 match_T
*shl
; /* points to search_hl or a match */
6777 colnr_T mincol
; /* minimal column for a match */
6785 /* Check for three situations:
6786 * 1. If the "lnum" is below a previous match, start a new search.
6787 * 2. If the previous match includes "mincol", use it.
6788 * 3. Continue after the previous match.
6790 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6793 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6798 * Repeat searching for a match until one is found that includes "mincol"
6799 * or none is found in this line.
6801 called_emsg
= FALSE
;
6805 /* Stop searching after passing the time limit. */
6806 if (profile_passed_limit(&(shl
->tm
)))
6808 shl
->lnum
= 0; /* no match found in time */
6812 /* Three situations:
6813 * 1. No useful previous match: search from start of line.
6814 * 2. Not Vi compatible or empty match: continue at next character.
6815 * Break the loop if this is beyond the end of the line.
6816 * 3. Vi compatible searching: continue at end of previous match.
6820 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6821 || (shl
->rm
.endpos
[0].lnum
== 0
6822 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6826 matchcol
= shl
->rm
.startpos
[0].col
;
6827 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6836 matchcol
+= mb_ptr2len(ml
);
6842 matchcol
= shl
->rm
.endpos
[0].col
;
6845 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
,
6854 /* Error while handling regexp: stop using this regexp. */
6855 if (shl
== &search_hl
)
6857 /* don't free regprog in the match list, it's a copy */
6858 vim_free(shl
->rm
.regprog
);
6861 shl
->rm
.regprog
= NULL
;
6863 got_int
= FALSE
; /* avoid the "Type :quit to exit Vim" message */
6868 shl
->lnum
= 0; /* no match found */
6871 if (shl
->rm
.startpos
[0].lnum
> 0
6872 || shl
->rm
.startpos
[0].col
>= mincol
6874 || shl
->rm
.endpos
[0].col
> mincol
)
6876 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6877 break; /* useful match found */
6884 screen_start_highlight(attr
)
6887 attrentry_T
*aep
= NULL
;
6901 /* The GUI handles this internally. */
6902 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6908 if (attr
> HL_ALL
) /* special HL attr. */
6911 aep
= syn_cterm_attr2entry(attr
);
6913 aep
= syn_term_attr2entry(attr
);
6914 if (aep
== NULL
) /* did ":syntax clear" */
6917 attr
= aep
->ae_attr
;
6919 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6921 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6922 && cterm_normal_fg_bold
)
6923 /* If the Normal FG color has BOLD attribute and the new HL
6924 * has a FG color defined, clear BOLD. */
6926 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6928 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6929 /* underline or undercurl */
6931 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6933 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6937 * Output the color or start string after bold etc., in case the
6938 * bold etc. override the color setting.
6944 if (aep
->ae_u
.cterm
.fg_color
)
6945 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6946 if (aep
->ae_u
.cterm
.bg_color
)
6947 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6951 if (aep
->ae_u
.term
.start
!= NULL
)
6952 out_str(aep
->ae_u
.term
.start
);
6960 screen_stop_highlight()
6962 int do_ME
= FALSE
; /* output T_ME code */
6964 if (screen_attr
!= 0
6975 /* use internal GUI code */
6976 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6982 if (screen_attr
> HL_ALL
) /* special HL attr. */
6989 * Assume that t_me restores the original colors!
6991 aep
= syn_cterm_attr2entry(screen_attr
);
6992 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6993 || aep
->ae_u
.cterm
.bg_color
))
6998 aep
= syn_term_attr2entry(screen_attr
);
6999 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
7001 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
7004 out_str(aep
->ae_u
.term
.stop
);
7007 if (aep
== NULL
) /* did ":syntax clear" */
7010 screen_attr
= aep
->ae_attr
;
7014 * Often all ending-codes are equal to T_ME. Avoid outputting the
7015 * same sequence several times.
7017 if (screen_attr
& HL_STANDOUT
)
7019 if (STRCMP(T_SE
, T_ME
) == 0)
7024 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
7026 if (STRCMP(T_UE
, T_ME
) == 0)
7031 if (screen_attr
& HL_ITALIC
)
7033 if (STRCMP(T_CZR
, T_ME
) == 0)
7038 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
7043 /* set Normal cterm colors */
7044 if (cterm_normal_fg_color
!= 0)
7045 term_fg_color(cterm_normal_fg_color
- 1);
7046 if (cterm_normal_bg_color
!= 0)
7047 term_bg_color(cterm_normal_bg_color
- 1);
7048 if (cterm_normal_fg_bold
)
7057 * Reset the colors for a cterm. Used when leaving Vim.
7058 * The machine specific code may override this again.
7061 reset_cterm_colors()
7065 /* set Normal cterm colors */
7066 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
7071 if (cterm_normal_fg_bold
)
7080 * Put character ScreenLines["off"] on the screen at position "row" and "col",
7081 * using the attributes from ScreenAttrs["off"].
7084 screen_char(off
, row
, col
)
7091 /* Check for illegal values, just in case (could happen just after
7093 if (row
>= screen_Rows
|| col
>= screen_Columns
)
7096 /* Outputting the last character on the screen may scrollup the screen.
7097 * Don't to it! Mark the character invalid (update it when scrolled up) */
7098 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
7099 #ifdef FEAT_RIGHTLEFT
7100 /* account for first command-line character in rightleft mode */
7105 ScreenAttrs
[off
] = (sattr_T
)-1;
7110 * Stop highlighting first, so it's easier to move the cursor.
7112 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
7113 if (screen_char_attr
!= 0)
7114 attr
= screen_char_attr
;
7117 attr
= ScreenAttrs
[off
];
7118 if (screen_attr
!= attr
)
7119 screen_stop_highlight();
7123 if (screen_attr
!= attr
)
7124 screen_start_highlight(attr
);
7127 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
7129 char_u buf
[MB_MAXBYTES
+ 1];
7131 /* Convert UTF-8 character to bytes and write it. */
7133 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
7136 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
7145 out_char(ScreenLines
[off
]);
7147 /* double-byte character in single-width cell */
7148 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
7149 out_char(ScreenLines2
[off
]);
7159 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
7160 * on the screen at position 'row' and 'col'.
7161 * The attributes of the first byte is used for all. This is required to
7162 * output the two bytes of a double-byte character with nothing in between.
7165 screen_char_2(off
, row
, col
)
7170 /* Check for illegal values (could be wrong when screen was resized). */
7171 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
7174 /* Outputting the last character on the screen may scrollup the screen.
7175 * Don't to it! Mark the character invalid (update it when scrolled up) */
7176 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
7178 ScreenAttrs
[off
] = (sattr_T
)-1;
7182 /* Output the first byte normally (positions the cursor), then write the
7183 * second byte directly. */
7184 screen_char(off
, row
, col
);
7185 out_char(ScreenLines
[off
+ 1]);
7190 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
7192 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
7193 * This uses the contents of ScreenLines[] and doesn't change it.
7196 screen_draw_rectangle(row
, col
, height
, width
, invert
)
7209 /* Can't use ScreenLines unless initialized */
7210 if (ScreenLines
== NULL
)
7214 screen_char_attr
= HL_INVERSE
;
7215 for (r
= row
; r
< row
+ height
; ++r
)
7217 off
= LineOffset
[r
];
7219 max_off
= off
+ screen_Columns
;
7221 for (c
= col
; c
< col
+ width
; ++c
)
7224 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
, max_off
) > 1)
7226 screen_char_2(off
+ c
, r
, c
);
7232 screen_char(off
+ c
, r
, c
);
7234 if (utf_off2cells(off
+ c
, max_off
) > 1)
7240 screen_char_attr
= 0;
7244 #ifdef FEAT_VERTSPLIT
7246 * Redraw the characters for a vertically split window.
7249 redraw_block(row
, end
, wp
)
7257 # ifdef FEAT_CLIPBOARD
7258 clip_may_clear_selection(row
, end
- 1);
7269 width
= wp
->w_width
;
7271 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
7276 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7277 * with character 'c1' in first column followed by 'c2' in the other columns.
7278 * Use attributes 'attr'.
7281 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
7282 int start_row
, end_row
;
7283 int start_col
, end_col
;
7294 #if defined(FEAT_GUI) || defined(UNIX)
7295 int force_next
= FALSE
;
7298 if (end_row
> screen_Rows
) /* safety check */
7299 end_row
= screen_Rows
;
7300 if (end_col
> screen_Columns
) /* safety check */
7301 end_col
= screen_Columns
;
7302 if (ScreenLines
== NULL
7303 || start_row
>= end_row
7304 || start_col
>= end_col
) /* nothing to do */
7307 /* it's a "normal" terminal when not in a GUI or cterm */
7313 for (row
= start_row
; row
< end_row
; ++row
)
7322 /* When drawing over the right halve of a double-wide char clear
7323 * out the left halve. When drawing over the left halve of a
7324 * double wide-char clear out the right halve. Only needed in a
7326 if (start_col
> 0 && mb_fix_col(start_col
, row
) != start_col
)
7327 screen_puts_len((char_u
*)" ", 1, row
, start_col
- 1, 0);
7328 if (end_col
< screen_Columns
&& mb_fix_col(end_col
, row
) != end_col
)
7329 screen_puts_len((char_u
*)" ", 1, row
, end_col
, 0);
7333 * Try to use delete-line termcap code, when no attributes or in a
7334 * "normal" terminal, where a bold/italic space is just a
7339 && end_col
== Columns
7344 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
7347 * check if we really need to clear something
7350 if (c1
!= ' ') /* don't clear first char */
7353 off
= LineOffset
[row
] + col
;
7354 end_off
= LineOffset
[row
] + end_col
;
7356 /* skip blanks (used often, keep it fast!) */
7359 while (off
< end_off
&& ScreenLines
[off
] == ' '
7360 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
7364 while (off
< end_off
&& ScreenLines
[off
] == ' '
7365 && ScreenAttrs
[off
] == 0)
7367 if (off
< end_off
) /* something to be cleared */
7369 col
= off
- LineOffset
[row
];
7370 screen_stop_highlight();
7371 term_windgoto(row
, col
);/* clear rest of this screen line */
7373 screen_start(); /* don't know where cursor is now */
7374 col
= end_col
- col
;
7375 while (col
--) /* clear chars in ScreenLines */
7377 ScreenLines
[off
] = ' ';
7380 ScreenLinesUC
[off
] = 0;
7382 ScreenAttrs
[off
] = 0;
7386 did_delete
= TRUE
; /* the chars are cleared now */
7389 off
= LineOffset
[row
] + start_col
;
7391 for (col
= start_col
; col
< end_col
; ++col
)
7393 if (ScreenLines
[off
] != c
7395 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
7396 != (c
>= 0x80 ? c
: 0))
7398 || ScreenAttrs
[off
] != attr
7399 #if defined(FEAT_GUI) || defined(UNIX)
7404 #if defined(FEAT_GUI) || defined(UNIX)
7405 /* The bold trick may make a single row of pixels appear in
7406 * the next character. When a bold character is removed, the
7407 * next character should be redrawn too. This happens for our
7408 * own GUI and for some xterms. */
7413 # if defined(FEAT_GUI) && defined(UNIX)
7421 if (ScreenLines
[off
] != ' '
7422 && (ScreenAttrs
[off
] > HL_ALL
7423 || ScreenAttrs
[off
] & HL_BOLD
))
7429 ScreenLines
[off
] = c
;
7435 ScreenLinesUC
[off
] = c
;
7436 ScreenLinesC
[0][off
] = 0;
7439 ScreenLinesUC
[off
] = 0;
7442 ScreenAttrs
[off
] = attr
;
7443 if (!did_delete
|| c
!= ' ')
7444 screen_char(off
, row
, col
);
7447 if (col
== start_col
)
7454 if (end_col
== Columns
)
7455 LineWraps
[row
] = FALSE
;
7456 if (row
== Rows
- 1) /* overwritten the command line */
7458 redraw_cmdline
= TRUE
;
7459 if (c1
== ' ' && c2
== ' ')
7460 clear_cmdline
= FALSE
; /* command line has been cleared */
7462 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7468 * Check if there should be a delay. Used before clearing or redrawing the
7469 * screen or the command line.
7472 check_for_delay(check_msg_scroll
)
7473 int check_msg_scroll
;
7475 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7477 && emsg_silent
== 0)
7480 ui_delay(1000L, TRUE
);
7481 emsg_on_display
= FALSE
;
7482 if (check_msg_scroll
)
7488 * screen_valid - allocate screen buffers if size changed
7489 * If "clear" is TRUE: clear screen if it has been resized.
7490 * Returns TRUE if there is a valid screen to write to.
7491 * Returns FALSE when starting up and screen not initialized yet.
7497 screenalloc(clear
); /* allocate screen buffers if size changed */
7498 return (ScreenLines
!= NULL
);
7502 * Resize the shell to Rows and Columns.
7503 * Allocate ScreenLines[] and associated items.
7505 * There may be some time between setting Rows and Columns and (re)allocating
7506 * ScreenLines[]. This happens when starting up and when (manually) changing
7507 * the shell size. Always use screen_Rows and screen_Columns to access items
7508 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7509 * final size of the shell is needed.
7515 int new_row
, old_row
;
7520 int outofmem
= FALSE
;
7522 schar_T
*new_ScreenLines
;
7524 u8char_T
*new_ScreenLinesUC
= NULL
;
7525 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7526 schar_T
*new_ScreenLines2
= NULL
;
7529 sattr_T
*new_ScreenAttrs
;
7530 unsigned *new_LineOffset
;
7531 char_u
*new_LineWraps
;
7533 short *new_TabPageIdxs
;
7536 static int entered
= FALSE
; /* avoid recursiveness */
7537 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7539 int retry_count
= 0;
7544 * Allocation of the screen buffers is done only when the size changes and
7545 * when Rows and Columns have been set and we have started doing full
7548 if ((ScreenLines
!= NULL
7549 && Rows
== screen_Rows
7550 && Columns
== screen_Columns
7552 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7553 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7554 && p_mco
== Screen_mco
7559 || (!full_screen
&& ScreenLines
== NULL
))
7563 * It's possible that we produce an out-of-memory message below, which
7564 * will cause this function to be called again. To break the loop, just
7572 * Note that the window sizes are updated before reallocating the arrays,
7573 * thus we must not redraw here!
7575 ++RedrawingDisabled
;
7577 win_new_shellsize(); /* fit the windows in the new sized shell */
7579 comp_col(); /* recompute columns for shown command and ruler */
7582 * We're changing the size of the screen.
7583 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7584 * - Move lines from the old arrays into the new arrays, clear extra
7585 * lines (unless the screen is going to be cleared).
7586 * - Free the old arrays.
7588 * If anything fails, make ScreenLines NULL, so we don't do anything!
7589 * Continuing with the old ScreenLines may result in a crash, because the
7592 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7595 if (aucmd_win
!= NULL
)
7596 win_free_lsize(aucmd_win
);
7599 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7600 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7602 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
*) * MAX_MCO
);
7605 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7606 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7607 for (i
= 0; i
< p_mco
; ++i
)
7608 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc_clear((long_u
)(
7609 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7611 if (enc_dbcs
== DBCS_JPNU
)
7612 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7613 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7615 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7616 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7617 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7618 Rows
* sizeof(unsigned)), FALSE
);
7619 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7621 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7624 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7626 if (win_alloc_lines(wp
) == FAIL
)
7635 if (aucmd_win
!= NULL
&& aucmd_win
->w_lines
== NULL
7636 && win_alloc_lines(aucmd_win
) == FAIL
)
7644 for (i
= 0; i
< p_mco
; ++i
)
7645 if (new_ScreenLinesC
[i
] == NULL
)
7648 if (new_ScreenLines
== NULL
7650 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7651 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7653 || new_ScreenAttrs
== NULL
7654 || new_LineOffset
== NULL
7655 || new_LineWraps
== NULL
7657 || new_TabPageIdxs
== NULL
7661 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7663 /* guess the size */
7664 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7666 /* Remember we did this to avoid getting outofmem messages over
7667 * and over again. */
7668 done_outofmem_msg
= TRUE
;
7670 vim_free(new_ScreenLines
);
7671 new_ScreenLines
= NULL
;
7673 vim_free(new_ScreenLinesUC
);
7674 new_ScreenLinesUC
= NULL
;
7675 for (i
= 0; i
< p_mco
; ++i
)
7677 vim_free(new_ScreenLinesC
[i
]);
7678 new_ScreenLinesC
[i
] = NULL
;
7680 vim_free(new_ScreenLines2
);
7681 new_ScreenLines2
= NULL
;
7683 vim_free(new_ScreenAttrs
);
7684 new_ScreenAttrs
= NULL
;
7685 vim_free(new_LineOffset
);
7686 new_LineOffset
= NULL
;
7687 vim_free(new_LineWraps
);
7688 new_LineWraps
= NULL
;
7690 vim_free(new_TabPageIdxs
);
7691 new_TabPageIdxs
= NULL
;
7696 done_outofmem_msg
= FALSE
;
7698 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7700 new_LineOffset
[new_row
] = new_row
* Columns
;
7701 new_LineWraps
[new_row
] = FALSE
;
7704 * If the screen is not going to be cleared, copy as much as
7705 * possible from the old screen to the new one and clear the rest
7706 * (used when resizing the window at the "--more--" prompt or when
7707 * executing an external command, for the GUI).
7711 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7712 ' ', (size_t)Columns
* sizeof(schar_T
));
7716 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7717 0, (size_t)Columns
* sizeof(u8char_T
));
7718 for (i
= 0; i
< p_mco
; ++i
)
7719 (void)vim_memset(new_ScreenLinesC
[i
]
7720 + new_row
* Columns
,
7721 0, (size_t)Columns
* sizeof(u8char_T
));
7723 if (enc_dbcs
== DBCS_JPNU
)
7724 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7725 0, (size_t)Columns
* sizeof(schar_T
));
7727 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7728 0, (size_t)Columns
* sizeof(sattr_T
));
7729 old_row
= new_row
+ (screen_Rows
- Rows
);
7730 if (old_row
>= 0 && ScreenLines
!= NULL
)
7732 if (screen_Columns
< Columns
)
7733 len
= screen_Columns
;
7737 /* When switching to utf-8 don't copy characters, they
7738 * may be invalid now. Also when p_mco changes. */
7739 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7740 && p_mco
== Screen_mco
)
7742 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7743 ScreenLines
+ LineOffset
[old_row
],
7744 (size_t)len
* sizeof(schar_T
));
7746 if (enc_utf8
&& ScreenLinesUC
!= NULL
7747 && p_mco
== Screen_mco
)
7749 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7750 ScreenLinesUC
+ LineOffset
[old_row
],
7751 (size_t)len
* sizeof(u8char_T
));
7752 for (i
= 0; i
< p_mco
; ++i
)
7753 mch_memmove(new_ScreenLinesC
[i
]
7754 + new_LineOffset
[new_row
],
7755 ScreenLinesC
[i
] + LineOffset
[old_row
],
7756 (size_t)len
* sizeof(u8char_T
));
7758 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7759 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7760 ScreenLines2
+ LineOffset
[old_row
],
7761 (size_t)len
* sizeof(schar_T
));
7763 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7764 ScreenAttrs
+ LineOffset
[old_row
],
7765 (size_t)len
* sizeof(sattr_T
));
7769 /* Use the last line of the screen for the current line. */
7770 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7775 ScreenLines
= new_ScreenLines
;
7777 ScreenLinesUC
= new_ScreenLinesUC
;
7778 for (i
= 0; i
< p_mco
; ++i
)
7779 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7781 ScreenLines2
= new_ScreenLines2
;
7783 ScreenAttrs
= new_ScreenAttrs
;
7784 LineOffset
= new_LineOffset
;
7785 LineWraps
= new_LineWraps
;
7787 TabPageIdxs
= new_TabPageIdxs
;
7790 /* It's important that screen_Rows and screen_Columns reflect the actual
7791 * size of ScreenLines[]. Set them before calling anything. */
7793 old_Rows
= screen_Rows
;
7796 screen_Columns
= Columns
;
7798 must_redraw
= CLEAR
; /* need to clear the screen later */
7805 && ScreenLines
!= NULL
7806 && old_Rows
!= Rows
)
7808 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7810 * Adjust the position of the cursor, for when executing an external
7813 if (msg_row
>= Rows
) /* Rows got smaller */
7814 msg_row
= Rows
- 1; /* put cursor at last row */
7815 else if (Rows
> old_Rows
) /* Rows got bigger */
7816 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7817 if (msg_col
>= Columns
) /* Columns got smaller */
7818 msg_col
= Columns
- 1; /* put cursor at last column */
7823 --RedrawingDisabled
;
7827 * Do not apply autocommands more than 3 times to avoid an endless loop
7828 * in case applying autocommands always changes Rows or Columns.
7830 if (starting
== 0 && ++retry_count
<= 3)
7832 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7833 /* In rare cases, autocommands may have altered Rows or Columns,
7834 * jump back to check if we need to allocate the screen again. */
7846 vim_free(ScreenLinesUC
);
7847 for (i
= 0; i
< Screen_mco
; ++i
)
7848 vim_free(ScreenLinesC
[i
]);
7849 vim_free(ScreenLines2
);
7851 vim_free(ScreenLines
);
7852 vim_free(ScreenAttrs
);
7853 vim_free(LineOffset
);
7854 vim_free(LineWraps
);
7856 vim_free(TabPageIdxs
);
7863 check_for_delay(FALSE
);
7864 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7865 screenclear2(); /* clear the screen */
7873 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7875 || (gui
.in_use
&& gui
.starting
)
7883 screen_attr
= -1; /* force setting the Normal colors */
7884 screen_stop_highlight(); /* don't want highlighting here */
7886 #ifdef FEAT_CLIPBOARD
7887 /* disable selection without redrawing it */
7888 clip_scroll_selection(9999);
7891 /* blank out ScreenLines */
7892 for (i
= 0; i
< Rows
; ++i
)
7894 lineclear(LineOffset
[i
], (int)Columns
);
7895 LineWraps
[i
] = FALSE
;
7898 if (can_clear(T_CL
))
7900 out_str(T_CL
); /* clear the display */
7901 clear_cmdline
= FALSE
;
7902 mode_displayed
= FALSE
;
7906 /* can't clear the screen, mark all chars with invalid attributes */
7907 for (i
= 0; i
< Rows
; ++i
)
7908 lineinvalid(LineOffset
[i
], (int)Columns
);
7909 clear_cmdline
= TRUE
;
7912 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7914 win_rest_invalid(firstwin
);
7915 redraw_cmdline
= TRUE
;
7917 redraw_tabline
= TRUE
;
7919 if (must_redraw
== CLEAR
) /* no need to clear again */
7920 must_redraw
= NOT_VALID
;
7922 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7924 screen_start(); /* don't know where cursor is now */
7925 msg_scrolled
= 0; /* can't scroll back */
7931 * Clear one line in ScreenLines.
7934 lineclear(off
, width
)
7938 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7941 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7942 (size_t)width
* sizeof(u8char_T
));
7944 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7948 * Mark one line in ScreenLines invalid by setting the attributes to an
7952 lineinvalid(off
, width
)
7956 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7959 #ifdef FEAT_VERTSPLIT
7961 * Copy part of a Screenline for vertically split window "wp".
7964 linecopy(to
, from
, wp
)
7969 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7970 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7972 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7973 wp
->w_width
* sizeof(schar_T
));
7979 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7980 wp
->w_width
* sizeof(u8char_T
));
7981 for (i
= 0; i
< p_mco
; ++i
)
7982 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7983 wp
->w_width
* sizeof(u8char_T
));
7985 if (enc_dbcs
== DBCS_JPNU
)
7986 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7987 wp
->w_width
* sizeof(schar_T
));
7989 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7990 wp
->w_width
* sizeof(sattr_T
));
7995 * Return TRUE if clearing with term string "p" would work.
7996 * It can't work when the string is empty or it won't set the right background.
8002 return (*p
!= NUL
&& (t_colors
<= 1
8006 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
8010 * Reset cursor position. Use whenever cursor was moved because of outputting
8011 * something directly to the screen (shell commands) or a terminal control
8017 screen_cur_row
= screen_cur_col
= 9999;
8021 * Move the cursor to position "row","col" in the screen.
8022 * This tries to find the most efficient way to move, minimizing the number of
8023 * characters sent to the terminal.
8040 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
8041 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
8046 #define PLAN_WRITE 4
8047 /* Can't use ScreenLines unless initialized */
8048 if (ScreenLines
== NULL
)
8051 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
8053 /* Check for valid position. */
8054 if (row
< 0) /* window without text lines? */
8056 if (row
>= screen_Rows
)
8057 row
= screen_Rows
- 1;
8058 if (col
>= screen_Columns
)
8059 col
= screen_Columns
- 1;
8061 /* check if no cursor movement is allowed in highlight mode */
8062 if (screen_attr
&& *T_MS
== NUL
)
8063 noinvcurs
= HIGHL_COST
;
8066 goto_cost
= GOTO_COST
+ noinvcurs
;
8069 * Plan how to do the positioning:
8070 * 1. Use CR to move it to column 0, same row.
8071 * 2. Use T_LE to move it a few columns to the left.
8072 * 3. Use NL to move a few lines down, column 0.
8073 * 4. Move a few columns to the right with T_ND or by writing chars.
8075 * Don't do this if the cursor went beyond the last column, the cursor
8076 * position is unknown then (some terminals wrap, some don't )
8078 * First check if the highlighting attributes allow us to write
8079 * characters to move the cursor to the right.
8081 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
8084 * If the cursor is in the same row, bigger col, we can use CR
8087 bs
= NULL
; /* init for GCC */
8089 if (row
== screen_cur_row
&& col
< screen_cur_col
)
8091 /* "le" is preferred over "bc", because "bc" is obsolete */
8093 bs
= T_LE
; /* "cursor left" */
8095 bs
= T_BC
; /* "backspace character (old) */
8097 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
8100 if (col
+ 1 < cost
) /* using CR is less characters */
8104 cost
= 1; /* CR is just one character */
8111 if (noinvcurs
) /* will stop highlighting */
8119 * If the cursor is above where we want to be, we can use CR LF.
8121 else if (row
> screen_cur_row
)
8125 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
8126 if (noinvcurs
) /* will stop highlighting */
8134 * If the cursor is in the same row, smaller col, just use write.
8139 wouldbe_col
= screen_cur_col
;
8144 * Check if any characters that need to be written have the
8145 * correct attributes. Also avoid UTF-8 characters.
8147 i
= col
- wouldbe_col
;
8150 if (cost
< goto_cost
&& i
> 0)
8153 * Check if the attributes are correct without additionally
8154 * stopping highlighting.
8156 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
8157 while (i
&& *p
++ == attr
)
8162 * Try if it works when highlighting is stopped here.
8167 while (i
&& *p
++ == 0)
8171 cost
= 999; /* different attributes, don't do it */
8176 /* Don't use an UTF-8 char for positioning, it's slow. */
8177 for (i
= wouldbe_col
; i
< col
; ++i
)
8178 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
8188 * We can do it without term_windgoto()!
8190 if (cost
< goto_cost
)
8192 if (plan
== PLAN_LE
)
8195 screen_stop_highlight();
8196 while (screen_cur_col
> col
)
8202 else if (plan
== PLAN_CR
)
8205 screen_stop_highlight();
8209 else if (plan
== PLAN_NL
)
8212 screen_stop_highlight();
8213 while (screen_cur_row
< row
)
8221 i
= col
- screen_cur_col
;
8225 * Use cursor-right if it's one character only. Avoids
8226 * removing a line of pixels from the last bold char, when
8227 * using the bold trick in the GUI.
8229 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
8238 off
= LineOffset
[row
] + screen_cur_col
;
8241 if (ScreenAttrs
[off
] != screen_attr
)
8242 screen_stop_highlight();
8246 out_char(ScreenLines
[off
]);
8248 if (enc_dbcs
== DBCS_JPNU
8249 && ScreenLines
[off
] == 0x8e)
8250 out_char(ScreenLines2
[off
]);
8261 if (cost
>= goto_cost
)
8264 screen_stop_highlight();
8265 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
8267 term_cursor_right(col
- screen_cur_col
);
8269 term_windgoto(row
, col
);
8271 screen_cur_row
= row
;
8272 screen_cur_col
= col
;
8277 * Set cursor to its position in the current window.
8285 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
8286 W_WINCOL(curwin
) + (
8287 #ifdef FEAT_RIGHTLEFT
8288 /* With 'rightleft' set and the cursor on a double-wide
8289 * character, position it on the leftmost column. */
8290 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
8293 && (*mb_ptr2cells
)(ml_get_cursor()) == 2
8294 && vim_isprintc(gchar_cursor())) ? 2 :
8304 * insert 'line_count' lines at 'row' in window 'wp'
8305 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8306 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8308 * Returns FAIL if the lines are not inserted, OK for success.
8311 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
8324 wp
->w_lines_valid
= 0;
8326 if (wp
->w_height
< 5)
8329 if (line_count
> wp
->w_height
- row
)
8330 line_count
= wp
->w_height
- row
;
8332 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
8333 if (retval
!= MAYBE
)
8337 * If there is a next window or a status line, we first try to delete the
8338 * lines at the bottom to avoid messing what is after the window.
8339 * If this fails and there are following windows, don't do anything to avoid
8340 * messing up those windows, better just redraw.
8344 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
8346 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8347 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
8349 else if (wp
->w_next
)
8354 * if no lines deleted, blank the lines that will end up below the window
8359 wp
->w_redr_status
= TRUE
;
8361 redraw_cmdline
= TRUE
;
8362 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
8363 lastrow
= nextrow
+ line_count
;
8366 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
8367 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8371 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
8374 /* deletion will have messed up other windows */
8378 wp
->w_redr_status
= TRUE
;
8380 win_rest_invalid(W_NEXT(wp
));
8389 * delete "line_count" window lines at "row" in window "wp"
8390 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8391 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8393 * Return OK for success, FAIL if the lines are not deleted.
8396 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
8406 wp
->w_lines_valid
= 0;
8408 if (line_count
> wp
->w_height
- row
)
8409 line_count
= wp
->w_height
- row
;
8411 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
8412 if (retval
!= MAYBE
)
8415 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
8416 (int)Rows
, FALSE
, NULL
) == FAIL
)
8421 * If there are windows or status lines below, try to put them at the
8422 * correct place. If we can't do that, they have to be redrawn.
8424 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
8426 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8427 line_count
, (int)Rows
, NULL
) == FAIL
)
8429 wp
->w_redr_status
= TRUE
;
8430 win_rest_invalid(wp
->w_next
);
8434 * If this is the last window and there is no status line, redraw the
8435 * command line later.
8439 redraw_cmdline
= TRUE
;
8444 * Common code for win_ins_lines() and win_del_lines().
8445 * Returns OK or FAIL when the work has been done.
8446 * Returns MAYBE when not finished yet.
8449 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8458 if (!redrawing() || line_count
<= 0)
8461 /* only a few lines left: redraw is faster */
8462 if (mayclear
&& Rows
- line_count
< 5
8463 #ifdef FEAT_VERTSPLIT
8464 && wp
->w_width
== Columns
8468 screenclear(); /* will set wp->w_lines_valid to 0 */
8473 * Delete all remaining lines
8475 if (row
+ line_count
>= wp
->w_height
)
8477 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8478 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8484 * when scrolling, the message on the command line should be cleared,
8485 * otherwise it will stay there forever.
8487 clear_cmdline
= TRUE
;
8490 * If the terminal can set a scroll region, use that.
8491 * Always do this in a vertically split window. This will redraw from
8492 * ScreenLines[] when t_CV isn't defined. That's faster than using
8494 * Don't use a scroll region when we are going to redraw the text, writing
8495 * a character in the lower right corner of the scroll region causes a
8496 * scroll-up in the DJGPP version.
8499 #ifdef FEAT_VERTSPLIT
8500 || W_WIDTH(wp
) != Columns
8504 #ifdef FEAT_VERTSPLIT
8505 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8507 scroll_region_set(wp
, row
);
8509 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8510 wp
->w_height
- row
, FALSE
, wp
);
8512 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8513 wp
->w_height
- row
, wp
);
8514 #ifdef FEAT_VERTSPLIT
8515 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8517 scroll_region_reset();
8522 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8530 * window 'wp' and everything after it is messed up, mark it for redraw
8533 win_rest_invalid(wp
)
8542 redraw_win_later(wp
, NOT_VALID
);
8544 wp
->w_redr_status
= TRUE
;
8548 redraw_cmdline
= TRUE
;
8552 * The rest of the routines in this file perform screen manipulations. The
8553 * given operation is performed physically on the screen. The corresponding
8554 * change is also made to the internal screen image. In this way, the editor
8555 * anticipates the effect of editing changes on the appearance of the screen.
8556 * That way, when we call screenupdate a complete redraw isn't usually
8557 * necessary. Another advantage is that we can keep adding code to anticipate
8558 * screen changes, and in the meantime, everything still works.
8562 * types for inserting or deleting lines
8572 #define USE_REDRAW 9
8575 * insert lines on the screen and update ScreenLines[]
8576 * 'end' is the line after the scrolled part. Normally it is Rows.
8577 * When scrolling region used 'off' is the offset from the top for the region.
8578 * 'row' and 'end' are relative to the start of the region.
8580 * return FAIL for failure, OK for success.
8583 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8588 win_T
*wp
; /* NULL or window to use width from */
8596 int can_ce
= can_clear(T_CE
);
8600 * - there is no valid screen
8601 * - the screen has to be redrawn completely
8602 * - the line count is less than one
8603 * - the line count is more than 'ttyscroll'
8605 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8609 * There are seven ways to insert lines:
8610 * 0. When in a vertically split window and t_CV isn't set, redraw the
8611 * characters from ScreenLines[].
8612 * 1. Use T_CD (clear to end of display) if it exists and the result of
8613 * the insert is just empty lines
8614 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8615 * present or line_count > 1. It looks better if we do all the inserts
8617 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8618 * insert is just empty lines and T_CE is not present or line_count >
8620 * 4. Use T_AL (insert line) if it exists.
8621 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8623 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8625 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8626 * the 'da' flag is not set or we have clear line capability.
8627 * 8. redraw the characters from ScreenLines[].
8629 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8630 * the scrollbar for the window. It does have insert line, use that if it
8633 result_empty
= (row
+ line_count
>= end
);
8634 #ifdef FEAT_VERTSPLIT
8635 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8639 if (can_clear(T_CD
) && result_empty
)
8641 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8643 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8645 else if (*T_AL
!= NUL
)
8647 else if (can_ce
&& result_empty
)
8649 else if (*T_DL
!= NUL
&& result_empty
)
8651 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8657 * For clearing the lines screen_del_lines() is used. This will also take
8658 * care of t_db if necessary.
8660 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8661 type
== USE_T_CE
|| type
== USE_T_DL
)
8662 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8665 * If text is retained below the screen, first clear or delete as many
8666 * lines at the bottom of the window as are about to be inserted so that
8667 * the deleted lines won't later surface during a screen_del_lines.
8670 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8672 #ifdef FEAT_CLIPBOARD
8673 /* Remove a modeless selection when inserting lines halfway the screen
8674 * or not the full width of the screen. */
8676 # ifdef FEAT_VERTSPLIT
8677 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8680 clip_clear_selection();
8682 clip_scroll_selection(-line_count
);
8686 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8687 * scrolling is actually carried out. */
8688 gui_dont_update_cursor();
8691 if (*T_CCS
!= NUL
) /* cursor relative to region */
8694 cursor_row
= row
+ off
;
8697 * Shift LineOffset[] line_count down to reflect the inserted lines.
8698 * Clear the inserted lines in ScreenLines[].
8702 for (i
= 0; i
< line_count
; ++i
)
8704 #ifdef FEAT_VERTSPLIT
8705 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8707 /* need to copy part of a line */
8709 while ((j
-= line_count
) >= row
)
8710 linecopy(j
+ line_count
, j
, wp
);
8712 if (can_clear((char_u
*)" "))
8713 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8715 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8716 LineWraps
[j
] = FALSE
;
8722 temp
= LineOffset
[j
];
8723 while ((j
-= line_count
) >= row
)
8725 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8726 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8728 LineOffset
[j
+ line_count
] = temp
;
8729 LineWraps
[j
+ line_count
] = FALSE
;
8730 if (can_clear((char_u
*)" "))
8731 lineclear(temp
, (int)Columns
);
8733 lineinvalid(temp
, (int)Columns
);
8737 screen_stop_highlight();
8738 windgoto(cursor_row
, 0);
8740 #ifdef FEAT_VERTSPLIT
8741 /* redraw the characters */
8742 if (type
== USE_REDRAW
)
8743 redraw_block(row
, end
, wp
);
8746 if (type
== USE_T_CAL
)
8748 term_append_lines(line_count
);
8749 screen_start(); /* don't know where cursor is now */
8753 for (i
= 0; i
< line_count
; i
++)
8755 if (type
== USE_T_AL
)
8757 if (i
&& cursor_row
!= 0)
8758 windgoto(cursor_row
, 0);
8761 else /* type == USE_T_SR */
8763 screen_start(); /* don't know where cursor is now */
8768 * With scroll-reverse and 'da' flag set we need to clear the lines that
8769 * have been scrolled down into the region.
8771 if (type
== USE_T_SR
&& *T_DA
)
8773 for (i
= 0; i
< line_count
; ++i
)
8775 windgoto(off
+ i
, 0);
8777 screen_start(); /* don't know where cursor is now */
8782 gui_can_update_cursor();
8784 out_flush(); /* always flush after a scroll */
8790 * delete lines on the screen and update ScreenLines[]
8791 * 'end' is the line after the scrolled part. Normally it is Rows.
8792 * When scrolling region used 'off' is the offset from the top for the region.
8793 * 'row' and 'end' are relative to the start of the region.
8795 * Return OK for success, FAIL if the lines are not deleted.
8798 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8803 int force
; /* even when line_count > p_ttyscroll */
8804 win_T
*wp UNUSED
; /* NULL or window to use width from */
8811 int result_empty
; /* result is empty until end of region */
8812 int can_delete
; /* deleting line codes can be used */
8817 * - there is no valid screen
8818 * - the screen has to be redrawn completely
8819 * - the line count is less than one
8820 * - the line count is more than 'ttyscroll'
8822 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8823 (!force
&& line_count
> p_ttyscroll
))
8827 * Check if the rest of the current region will become empty.
8829 result_empty
= row
+ line_count
>= end
;
8832 * We can delete lines only when 'db' flag not set or when 'ce' option
8835 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8838 * There are six ways to delete lines:
8839 * 0. When in a vertically split window and t_CV isn't set, redraw the
8840 * characters from ScreenLines[].
8841 * 1. Use T_CD if it exists and the result is empty.
8842 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8843 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8844 * none of the other ways work.
8845 * 4. Use T_CE (erase line) if the result is empty.
8846 * 5. Use T_DL (delete line) if it exists.
8847 * 6. redraw the characters from ScreenLines[].
8849 #ifdef FEAT_VERTSPLIT
8850 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8854 if (can_clear(T_CD
) && result_empty
)
8856 #if defined(__BEOS__) && defined(BEOS_DR8)
8858 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8859 * its internal termcap... this works okay for tests which test *T_DB !=
8860 * NUL. It has the disadvantage that the user cannot use any :set t_*
8861 * command to get T_DB (back) to empty_option, only :set term=... will do
8863 * Anyway, this hack will hopefully go away with the next OS release.
8866 else if (row
== 0 && T_DB
== empty_option
8867 && (line_count
== 1 || *T_CDL
== NUL
))
8869 else if (row
== 0 && (
8871 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8872 * up, so use delete-line command */
8878 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8880 else if (can_clear(T_CE
) && result_empty
8881 #ifdef FEAT_VERTSPLIT
8882 && (wp
== NULL
|| wp
->w_width
== Columns
)
8886 else if (*T_DL
!= NUL
&& can_delete
)
8888 else if (*T_CDL
!= NUL
&& can_delete
)
8893 #ifdef FEAT_CLIPBOARD
8894 /* Remove a modeless selection when deleting lines halfway the screen or
8895 * not the full width of the screen. */
8897 # ifdef FEAT_VERTSPLIT
8898 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8901 clip_clear_selection();
8903 clip_scroll_selection(line_count
);
8907 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8908 * scrolling is actually carried out. */
8909 gui_dont_update_cursor();
8912 if (*T_CCS
!= NUL
) /* cursor relative to region */
8919 cursor_row
= row
+ off
;
8920 cursor_end
= end
+ off
;
8924 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8925 * Clear the inserted lines in ScreenLines[].
8929 for (i
= 0; i
< line_count
; ++i
)
8931 #ifdef FEAT_VERTSPLIT
8932 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8934 /* need to copy part of a line */
8936 while ((j
+= line_count
) <= end
- 1)
8937 linecopy(j
- line_count
, j
, wp
);
8939 if (can_clear((char_u
*)" "))
8940 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8942 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8943 LineWraps
[j
] = FALSE
;
8948 /* whole width, moving the line pointers is faster */
8950 temp
= LineOffset
[j
];
8951 while ((j
+= line_count
) <= end
- 1)
8953 LineOffset
[j
- line_count
] = LineOffset
[j
];
8954 LineWraps
[j
- line_count
] = LineWraps
[j
];
8956 LineOffset
[j
- line_count
] = temp
;
8957 LineWraps
[j
- line_count
] = FALSE
;
8958 if (can_clear((char_u
*)" "))
8959 lineclear(temp
, (int)Columns
);
8961 lineinvalid(temp
, (int)Columns
);
8965 screen_stop_highlight();
8967 #ifdef FEAT_VERTSPLIT
8968 /* redraw the characters */
8969 if (type
== USE_REDRAW
)
8970 redraw_block(row
, end
, wp
);
8973 if (type
== USE_T_CD
) /* delete the lines */
8975 windgoto(cursor_row
, 0);
8977 screen_start(); /* don't know where cursor is now */
8979 else if (type
== USE_T_CDL
)
8981 windgoto(cursor_row
, 0);
8982 term_delete_lines(line_count
);
8983 screen_start(); /* don't know where cursor is now */
8986 * Deleting lines at top of the screen or scroll region: Just scroll
8987 * the whole screen (scroll region) up by outputting newlines on the
8990 else if (type
== USE_NL
)
8992 windgoto(cursor_end
- 1, 0);
8993 for (i
= line_count
; --i
>= 0; )
8994 out_char('\n'); /* cursor will remain on same line */
8998 for (i
= line_count
; --i
>= 0; )
9000 if (type
== USE_T_DL
)
9002 windgoto(cursor_row
, 0);
9003 out_str(T_DL
); /* delete a line */
9005 else /* type == USE_T_CE */
9007 windgoto(cursor_row
+ i
, 0);
9008 out_str(T_CE
); /* erase a line */
9010 screen_start(); /* don't know where cursor is now */
9015 * If the 'db' flag is set, we need to clear the lines that have been
9016 * scrolled up at the bottom of the region.
9018 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
9020 for (i
= line_count
; i
> 0; --i
)
9022 windgoto(cursor_end
- i
, 0);
9023 out_str(T_CE
); /* erase a line */
9024 screen_start(); /* don't know where cursor is now */
9029 gui_can_update_cursor();
9031 out_flush(); /* always flush after a scroll */
9038 * show the current mode and ruler
9040 * If clear_cmdline is TRUE, clear the rest of the cmdline.
9041 * If clear_cmdline is FALSE there may be a message there that needs to be
9042 * cleared only if a mode is shown.
9043 * Return the length of the message (0 if no message).
9053 #ifdef FEAT_INS_EXPAND
9057 do_mode
= ((p_smd
&& msg_silent
== 0)
9058 && ((State
& INSERT
)
9064 if (do_mode
|| Recording
)
9067 * Don't show mode right now, when not redrawing or inside a mapping.
9068 * Call char_avail() only when we are going to show something, because
9069 * it takes a bit of time.
9071 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
9073 redraw_cmdline
= TRUE
; /* show mode later */
9077 nwr_save
= need_wait_return
;
9079 /* wait a bit before overwriting an important message */
9080 check_for_delay(FALSE
);
9082 /* if the cmdline is more than one line high, erase top lines */
9083 need_clear
= clear_cmdline
;
9084 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
9085 msg_clr_cmdline(); /* will reset clear_cmdline */
9087 /* Position on the last line in the window, column 0 */
9090 attr
= hl_attr(HLF_CM
); /* Highlight mode */
9093 MSG_PUTS_ATTR("--", attr
);
9094 #if defined(FEAT_XIM)
9095 # if 0 /* old version, changed by SungHyun Nam July 2008 */
9096 if (xic
!= NULL
&& im_get_status() && !p_imdisable
9097 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
9101 preedit_get_status()
9107 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
9108 MSG_PUTS_ATTR(" IM", attr
);
9110 MSG_PUTS_ATTR(" XIM", attr
);
9113 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
9116 if (hangul_input_state_get())
9117 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
9120 #ifdef FEAT_INS_EXPAND
9121 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
9123 /* These messages can get long, avoid a wrap in a narrow
9124 * window. Prefer showing edit_submode_extra. */
9125 length
= (Rows
- msg_row
) * Columns
- 3;
9126 if (edit_submode_extra
!= NULL
)
9127 length
-= vim_strsize(edit_submode_extra
);
9130 if (edit_submode_pre
!= NULL
)
9131 length
-= vim_strsize(edit_submode_pre
);
9132 if (length
- vim_strsize(edit_submode
) > 0)
9134 if (edit_submode_pre
!= NULL
)
9135 msg_puts_attr(edit_submode_pre
, attr
);
9136 msg_puts_attr(edit_submode
, attr
);
9138 if (edit_submode_extra
!= NULL
)
9140 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
9141 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
9142 sub_attr
= hl_attr(edit_submode_highl
);
9145 msg_puts_attr(edit_submode_extra
, sub_attr
);
9153 #ifdef FEAT_VREPLACE
9154 if (State
& VREPLACE_FLAG
)
9155 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
9158 if (State
& REPLACE_FLAG
)
9159 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
9160 else if (State
& INSERT
)
9162 #ifdef FEAT_RIGHTLEFT
9164 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
9166 MSG_PUTS_ATTR(_(" INSERT"), attr
);
9168 else if (restart_edit
== 'I')
9169 MSG_PUTS_ATTR(_(" (insert)"), attr
);
9170 else if (restart_edit
== 'R')
9171 MSG_PUTS_ATTR(_(" (replace)"), attr
);
9172 else if (restart_edit
== 'V')
9173 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
9174 #ifdef FEAT_RIGHTLEFT
9176 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
9179 MSG_PUTS_ATTR(farsi_text_5
, attr
);
9183 if (State
& LANGMAP
)
9186 if (curwin
->w_p_arab
)
9187 MSG_PUTS_ATTR(_(" Arabic"), attr
);
9190 MSG_PUTS_ATTR(_(" (lang)"), attr
);
9193 if ((State
& INSERT
) && p_paste
)
9194 MSG_PUTS_ATTR(_(" (paste)"), attr
);
9201 /* Don't concatenate separate words to avoid translation
9203 switch ((VIsual_select
? 4 : 0)
9204 + (VIsual_mode
== Ctrl_V
) * 2
9205 + (VIsual_mode
== 'V'))
9207 case 0: p
= N_(" VISUAL"); break;
9208 case 1: p
= N_(" VISUAL LINE"); break;
9209 case 2: p
= N_(" VISUAL BLOCK"); break;
9210 case 4: p
= N_(" SELECT"); break;
9211 case 5: p
= N_(" SELECT LINE"); break;
9212 default: p
= N_(" SELECT BLOCK"); break;
9214 MSG_PUTS_ATTR(_(p
), attr
);
9217 MSG_PUTS_ATTR(" --", attr
);
9223 #ifdef FEAT_INS_EXPAND
9224 && edit_submode
== NULL
/* otherwise it gets too long */
9228 MSG_PUTS_ATTR(_("recording"), attr
);
9232 mode_displayed
= TRUE
;
9233 if (need_clear
|| clear_cmdline
)
9235 msg_didout
= FALSE
; /* overwrite this message */
9238 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
9240 else if (clear_cmdline
&& msg_silent
== 0)
9241 /* Clear the whole command line. Will reset "clear_cmdline". */
9244 #ifdef FEAT_CMDL_INFO
9246 /* In Visual mode the size of the selected area must be redrawn. */
9251 /* If the last window has no status line, the ruler is after the mode
9252 * message and must be redrawn */
9254 # ifdef FEAT_WINDOWS
9255 && lastwin
->w_status_height
== 0
9258 win_redr_ruler(lastwin
, TRUE
);
9260 redraw_cmdline
= FALSE
;
9261 clear_cmdline
= FALSE
;
9267 * Position for a mode message.
9277 * Delete mode message. Used when ESC is typed which is expected to end
9278 * Insert mode (but Insert mode didn't end yet!).
9279 * Caller should check "mode_displayed".
9286 * Don't delete it right now, when not redrawing or inside a mapping.
9288 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
9289 redraw_cmdline
= TRUE
; /* delete mode later */
9294 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
9299 #if defined(FEAT_WINDOWS)
9301 * Draw the tab pages line at the top of the Vim window.
9318 int attr_sel
= hl_attr(HLF_TPS
);
9319 int attr_nosel
= hl_attr(HLF_TP
);
9320 int attr_fill
= hl_attr(HLF_TPF
);
9323 int use_sep_chars
= (t_colors
< 8
9329 redraw_tabline
= FALSE
;
9331 #ifdef FEAT_GUI_TABLINE
9332 /* Take care of a GUI tabline. */
9333 if (gui_use_tabline())
9335 gui_update_tabline();
9340 if (tabline_height() < 1)
9343 #if defined(FEAT_STL_OPT)
9345 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9346 for (scol
= 0; scol
< Columns
; ++scol
)
9347 TabPageIdxs
[scol
] = 0;
9349 /* Use the 'tabline' option if it's set. */
9352 int save_called_emsg
= called_emsg
;
9354 /* Check for an error. If there is one we would loop in redrawing the
9355 * screen. Avoid that by making 'tabline' empty. */
9356 called_emsg
= FALSE
;
9357 win_redr_custom(NULL
, FALSE
);
9359 set_string_option_direct((char_u
*)"tabline", -1,
9360 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9361 called_emsg
|= save_called_emsg
;
9366 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
9369 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
9376 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
9381 if (tp
->tp_topframe
== topframe
)
9383 if (use_sep_chars
&& col
> 0)
9384 screen_putchar('|', 0, col
++, attr
);
9386 if (tp
->tp_topframe
!= topframe
)
9389 screen_putchar(' ', 0, col
++, attr
);
9398 cwp
= tp
->tp_curwin
;
9399 wp
= tp
->tp_firstwin
;
9403 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
9404 if (bufIsChanged(wp
->w_buffer
))
9406 if (modified
|| wincount
> 1)
9410 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
9411 len
= (int)STRLEN(NameBuff
);
9412 if (col
+ len
>= Columns
- 3)
9414 screen_puts_len(NameBuff
, len
, 0, col
,
9415 #if defined(FEAT_SYN_HL)
9416 hl_combine_attr(attr
, hl_attr(HLF_T
))
9424 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
9425 screen_putchar(' ', 0, col
++, attr
);
9428 room
= scol
- col
+ tabwidth
- 1;
9431 /* Get buffer name in NameBuff[] */
9432 get_trans_bufname(cwp
->w_buffer
);
9433 shorten_dir(NameBuff
);
9434 len
= vim_strsize(NameBuff
);
9440 len
-= ptr2cells(p
);
9450 if (len
> Columns
- col
- 1)
9451 len
= Columns
- col
- 1;
9453 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9456 screen_putchar(' ', 0, col
++, attr
);
9458 /* Store the tab page number in TabPageIdxs[], so that
9459 * jump_to_mouse() knows where each one is. */
9462 TabPageIdxs
[scol
++] = tabcount
;
9469 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9471 /* Put an "X" for closing the current tab if there are several. */
9472 if (first_tabpage
->tp_next
!= NULL
)
9474 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9475 TabPageIdxs
[Columns
- 1] = -999;
9479 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9481 redraw_tabline
= FALSE
;
9485 * Get buffer name for "buf" into NameBuff[].
9486 * Takes care of special buffer names and translates special characters.
9489 get_trans_bufname(buf
)
9492 char_u
*bname
= (char_u
*)buf_spname(buf
);
9495 vim_strncpy(NameBuff
, bname
, MAXPATHL
- 1);
9499 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9500 trans_characters(NameBuff
, MAXPATHL
);
9504 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9506 * Get the character to use in a status line. Get its attributes in "*attr".
9509 fillchar_status(attr
, is_curwin
)
9516 *attr
= hl_attr(HLF_S
);
9521 *attr
= hl_attr(HLF_SNC
);
9524 /* Use fill when there is highlighting, and highlighting of current
9525 * window differs, or the fillchars differ, or this is not the
9527 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9528 || !is_curwin
|| firstwin
== lastwin
)
9529 || (fill_stl
!= fill_stlnc
)))
9537 #ifdef FEAT_VERTSPLIT
9539 * Get the character to use in a separator between vertically split windows.
9540 * Get its attributes in "*attr".
9546 *attr
= hl_attr(HLF_C
);
9547 if (*attr
== 0 && fill_vert
== ' ')
9555 * Return TRUE if redrawing should currently be done.
9560 return (!RedrawingDisabled
9561 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9565 * Return TRUE if printing messages should currently be done.
9570 return (!(p_lz
&& char_avail() && !KeyTyped
));
9574 * Show current status info in ruler and various other places
9575 * If always is FALSE, only show ruler if position has changed.
9581 if (!always
&& !redrawing())
9583 #ifdef FEAT_INS_EXPAND
9586 # ifdef FEAT_WINDOWS
9587 /* Don't redraw right now, do it later. */
9588 curwin
->w_redr_status
= TRUE
;
9593 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9594 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9596 redraw_custom_statusline(curwin
);
9600 #ifdef FEAT_CMDL_INFO
9601 win_redr_ruler(curwin
, always
);
9606 # ifdef FEAT_STL_OPT
9607 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9608 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9614 /* Redraw the tab pages line if needed. */
9620 #ifdef FEAT_CMDL_INFO
9622 win_redr_ruler(wp
, always
)
9626 #define RULER_BUF_LEN 70
9627 char_u buffer
[RULER_BUF_LEN
];
9631 int empty_line
= FALSE
;
9636 #ifdef FEAT_VERTSPLIT
9639 int width
= Columns
;
9640 # define WITH_OFF(x) x
9641 # define WITH_WIDTH(x) x
9643 # define WITH_OFF(x) 0
9644 # define WITH_WIDTH(x) Columns
9645 # define this_ru_col ru_col
9648 /* If 'ruler' off or redrawing disabled, don't do anything */
9653 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9654 * after deleting lines, before cursor.lnum is corrected.
9656 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9659 #ifdef FEAT_INS_EXPAND
9660 /* Don't draw the ruler while doing insert-completion, it might overwrite
9661 * the (long) mode message. */
9662 # ifdef FEAT_WINDOWS
9663 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9665 if (edit_submode
!= NULL
)
9667 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9675 int save_called_emsg
= called_emsg
;
9677 called_emsg
= FALSE
;
9678 win_redr_custom(wp
, TRUE
);
9680 set_string_option_direct((char_u
*)"rulerformat", -1,
9681 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9682 called_emsg
|= save_called_emsg
;
9688 * Check if not in Insert mode and the line is empty (will show "0-1").
9690 if (!(State
& INSERT
)
9691 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9695 * Only draw the ruler when something changed.
9697 validate_virtcol_win(wp
);
9700 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9701 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9702 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9703 #ifdef FEAT_VIRTUALEDIT
9704 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9706 || wp
->w_topline
!= wp
->w_ru_topline
9707 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9709 || wp
->w_topfill
!= wp
->w_ru_topfill
9711 || empty_line
!= wp
->w_ru_empty
)
9715 if (wp
->w_status_height
)
9717 row
= W_WINROW(wp
) + wp
->w_height
;
9718 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9719 # ifdef FEAT_VERTSPLIT
9721 width
= W_WIDTH(wp
);
9730 #ifdef FEAT_VERTSPLIT
9736 /* In list mode virtcol needs to be recomputed */
9737 virtcol
= wp
->w_virtcol
;
9738 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9740 wp
->w_p_list
= FALSE
;
9741 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9742 wp
->w_p_list
= TRUE
;
9746 * Some sprintfs return the length, some return a pointer.
9747 * To avoid portability problems we use strlen() here.
9749 vim_snprintf((char *)buffer
, RULER_BUF_LEN
, "%ld,",
9750 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9752 : (long)(wp
->w_cursor
.lnum
));
9753 len
= STRLEN(buffer
);
9754 col_print(buffer
+ len
, RULER_BUF_LEN
- len
,
9755 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9759 * Add a "50%" if there is room for it.
9760 * On the last line, don't print in the last column (scrolls the
9761 * screen up on some terminals).
9763 i
= (int)STRLEN(buffer
);
9764 get_rel_pos(wp
, buffer
+ i
+ 1, RULER_BUF_LEN
- i
- 1);
9765 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9767 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9770 #ifdef FEAT_VERTSPLIT
9771 this_ru_col
= ru_col
- (Columns
- width
);
9772 if (this_ru_col
< 0)
9775 /* Never use more than half the window/screen width, leave the other
9776 * half for the filename. */
9777 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9778 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9779 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9781 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9785 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9788 buffer
[i
++] = fillchar
;
9791 get_rel_pos(wp
, buffer
+ i
, RULER_BUF_LEN
- i
);
9793 /* Truncate at window boundary. */
9798 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9800 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9801 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9810 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9811 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9813 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9815 screen_fill(row
, row
+ 1,
9816 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9817 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9818 fillchar
, fillchar
, attr
);
9819 /* don't redraw the cmdline because of showing the ruler */
9821 wp
->w_ru_cursor
= wp
->w_cursor
;
9822 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9823 wp
->w_ru_empty
= empty_line
;
9824 wp
->w_ru_topline
= wp
->w_topline
;
9825 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9827 wp
->w_ru_topfill
= wp
->w_topfill
;
9833 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9835 * Return the width of the 'number' and 'relativenumber' column.
9836 * Caller may need to check if 'number' or 'relativenumber' is set.
9837 * Otherwise it depends on 'numberwidth' and the line count.
9848 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9850 /* 'relativenumber' */
9851 lnum
= wp
->w_height
;
9853 if (lnum
== wp
->w_nrwidth_line_count
)
9854 return wp
->w_nrwidth_width
;
9855 wp
->w_nrwidth_line_count
= lnum
;
9864 /* 'numberwidth' gives the minimal width plus one */
9865 if (n
< wp
->w_p_nuw
- 1)
9866 n
= wp
->w_p_nuw
- 1;
9868 wp
->w_nrwidth_width
= n
;