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' column changes. */
427 if (curwin
->w_redr_type
< NOT_VALID
428 && curwin
->w_nrwidth
!= (curwin
->w_p_nu
? number_width(curwin
) : 0))
429 curwin
->w_redr_type
= NOT_VALID
;
433 * Only start redrawing if there is really something to do.
435 if (type
== INVERTED
)
437 if (curwin
->w_redr_type
< type
439 && curwin
->w_lines
[0].wl_valid
441 && curwin
->w_topfill
== curwin
->w_old_topfill
442 && curwin
->w_botfill
== curwin
->w_old_botfill
444 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
448 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
449 && curwin
->w_old_visual_mode
== VIsual_mode
450 && (curwin
->w_valid
& VALID_VIRTCOL
)
451 && curwin
->w_old_curswant
== curwin
->w_curswant
)
454 curwin
->w_redr_type
= type
;
457 /* Redraw the tab pages line if needed. */
458 if (redraw_tabline
|| type
>= NOT_VALID
)
464 * Correct stored syntax highlighting info for changes in each displayed
465 * buffer. Each buffer must only be done once.
469 if (wp
->w_buffer
->b_mod_set
)
474 /* Check if we already did this buffer. */
475 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
476 if (wwp
->w_buffer
== wp
->w_buffer
)
483 syntax_present(wp
->w_buffer
))
484 syn_stack_apply_changes(wp
->w_buffer
);
490 * Go from top to bottom through the windows, redrawing the ones that need
493 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
496 #ifdef FEAT_SEARCH_EXTRA
497 search_hl
.rm
.regprog
= NULL
;
501 if (wp
->w_redr_type
!= 0)
504 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
508 # ifdef FEAT_SEARCH_EXTRA
511 # ifdef FEAT_CLIPBOARD
512 /* When Visual area changed, may have to update selection. */
513 if (clip_star
.available
&& clip_isautosel())
514 clip_update_selection();
517 /* Remove the cursor before starting to do anything, because
518 * scrolling may make it difficult to redraw the text under
529 /* redraw status line after the window to minimize cursor movement */
530 if (wp
->w_redr_status
)
537 #if defined(FEAT_SEARCH_EXTRA)
542 /* Reset b_mod_set flags. Going through all windows is probably faster
543 * than going through all buffers (there could be many buffers). */
544 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
545 wp
->w_buffer
->b_mod_set
= FALSE
;
547 curbuf
->b_mod_set
= FALSE
;
550 updating_screen
= FALSE
;
552 gui_may_resize_shell();
555 /* Clear or redraw the command line. Done last, because scrolling may
556 * mess up the command line. */
557 if (clear_cmdline
|| redraw_cmdline
)
560 /* May put up an introductory message when not editing a file */
561 if (!did_intro
&& bufempty()
562 && curbuf
->b_fname
== NULL
564 && firstwin
->w_next
== NULL
566 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
567 intro_message(FALSE
);
571 /* Redraw the cursor and update the scrollbars when all screen updating is
575 out_flush(); /* required before updating the cursor */
577 gui_update_cursor(FALSE
, FALSE
);
578 gui_update_scrollbars(FALSE
);
583 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
584 static void update_prepare
__ARGS((void));
585 static void update_finish
__ARGS((void));
588 * Prepare for updating one or more windows.
589 * Caller must check for "updating_screen" already set to avoid recursiveness.
595 updating_screen
= TRUE
;
597 /* Remove the cursor before starting to do anything, because scrolling may
598 * make it difficult to redraw the text under it. */
602 #ifdef FEAT_SEARCH_EXTRA
608 * Finish updating one or more windows.
616 # ifdef FEAT_SEARCH_EXTRA
620 updating_screen
= FALSE
;
623 gui_may_resize_shell();
625 /* Redraw the cursor and update the scrollbars when all screen updating is
629 out_flush(); /* required before updating the cursor */
630 gui_update_cursor(FALSE
, FALSE
);
631 gui_update_scrollbars(FALSE
);
637 #if defined(FEAT_SIGNS) || defined(PROTO)
639 update_debug_sign(buf
, lnum
)
647 win_foldinfo
.fi_level
= 0;
650 /* update/delete a specific mark */
653 if (buf
!= NULL
&& lnum
> 0)
655 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
656 && lnum
< wp
->w_botline
)
658 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
659 wp
->w_redraw_top
= lnum
;
660 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
661 wp
->w_redraw_bot
= lnum
;
662 redraw_win_later(wp
, VALID
);
666 redraw_win_later(wp
, VALID
);
667 if (wp
->w_redr_type
!= 0)
671 /* Return when there is nothing to do or screen updating already
673 if (!doit
|| updating_screen
)
676 /* update all windows that need updating */
680 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
682 if (wp
->w_redr_type
!= 0)
684 if (wp
->w_redr_status
)
688 if (curwin
->w_redr_type
!= 0)
697 #if defined(FEAT_GUI) || defined(PROTO)
699 * Update a single window, its status line and maybe the command line msg.
700 * Used for the GUI scrollbar.
706 /* return if already busy updating */
712 #ifdef FEAT_CLIPBOARD
713 /* When Visual area changed, may have to update selection. */
714 if (clip_star
.available
&& clip_isautosel())
715 clip_update_selection();
721 /* When the screen was cleared redraw the tab pages line. */
725 if (wp
->w_redr_status
726 # ifdef FEAT_CMDL_INFO
730 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
741 * Update a single window.
743 * This may cause the windows below it also to be redrawn (when clearing the
744 * screen or scrolling lines).
746 * How the window is redrawn depends on wp->w_redr_type. Each type also
747 * implies the one below it.
748 * NOT_VALID redraw the whole window
749 * SOME_VALID redraw the whole window but do scroll when possible
750 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
751 * INVERTED redraw the changed part of the Visual area
752 * INVERTED_ALL redraw the whole Visual area
753 * VALID 1. scroll up/down to adjust for a changed w_topline
754 * 2. update lines at the top when scrolled down
755 * 3. redraw changed text:
756 * - if wp->w_buffer->b_mod_set set, update lines between
757 * b_mod_top and b_mod_bot.
758 * - if wp->w_redraw_top non-zero, redraw lines between
759 * wp->w_redraw_top and wp->w_redr_bot.
760 * - continue redrawing when syntax status is invalid.
761 * 4. if scrolled up, update lines at the bottom.
762 * This results in three areas that may need updating:
763 * top: from first row to top_end (when scrolled down)
764 * mid: from mid_start to mid_end (update inversion or changed text)
765 * bot: from bot_start to last row (when scrolled up)
771 buf_T
*buf
= wp
->w_buffer
;
773 int top_end
= 0; /* Below last row of the top area that needs
774 updating. 0 when no top area updating. */
775 int mid_start
= 999;/* first row of the mid area that needs
776 updating. 999 when no mid area updating. */
777 int mid_end
= 0; /* Below last row of the mid area that needs
778 updating. 0 when no mid area updating. */
779 int bot_start
= 999;/* first row of the bot area that needs
780 updating. 999 when no bot area updating */
782 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
783 w_topline got smaller a bit */
785 #ifdef FEAT_SEARCH_EXTRA
786 matchitem_T
*cur
; /* points to the match list */
787 int top_to_mod
= FALSE
; /* redraw above mod_top */
790 int row
; /* current window row to display */
791 linenr_T lnum
; /* current buffer lnum to display */
792 int idx
; /* current index in w_lines[] */
793 int srow
; /* starting row of the current line */
795 int eof
= FALSE
; /* if TRUE, we hit the end of the file */
796 int didline
= FALSE
; /* if TRUE, we finished the last line */
799 static int recursive
= FALSE
; /* being called recursively */
800 int old_botline
= wp
->w_botline
;
805 /* remember what happened to the previous line, to know if
806 * check_visual_highlight() can be used */
807 #define DID_NONE 1 /* didn't update a line */
808 #define DID_LINE 2 /* updated a normal line */
809 #define DID_FOLD 3 /* updated a folded line */
810 int did_update
= DID_NONE
;
811 linenr_T syntax_last_parsed
= 0; /* last parsed text line */
813 linenr_T mod_top
= 0;
814 linenr_T mod_bot
= 0;
815 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
819 type
= wp
->w_redr_type
;
821 if (type
== NOT_VALID
)
824 wp
->w_redr_status
= TRUE
;
826 wp
->w_lines_valid
= 0;
829 /* Window is zero-height: nothing to draw. */
830 if (wp
->w_height
== 0)
836 #ifdef FEAT_VERTSPLIT
837 /* Window is zero-width: Only need to draw the separator. */
838 if (wp
->w_width
== 0)
840 /* draw the vertical separator right of this window */
841 draw_vsep_win(wp
, 0);
847 #ifdef FEAT_SEARCH_EXTRA
848 /* Setup for match and 'hlsearch' highlighting. Disable any previous
850 cur
= wp
->w_match_head
;
853 cur
->hl
.rm
= cur
->match
;
854 if (cur
->hlg_id
== 0)
857 cur
->hl
.attr
= syn_id2attr(cur
->hlg_id
);
860 cur
->hl
.first_lnum
= 0;
862 /* Set the time limit to 'redrawtime'. */
863 profile_setlimit(p_rdt
, &(cur
->hl
.tm
));
869 search_hl
.first_lnum
= 0;
870 /* time limit is set at the toplevel, for all windows */
873 #ifdef FEAT_LINEBREAK
874 /* Force redraw when width of 'number' column changes. */
875 i
= wp
->w_p_nu
? number_width(wp
) : 0;
876 if (wp
->w_nrwidth
!= i
)
884 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
887 * When there are both inserted/deleted lines and specific lines to be
888 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
889 * everything (only happens when redrawing is off for while).
896 * Set mod_top to the first line that needs displaying because of
897 * changes. Set mod_bot to the first line after the changes.
899 mod_top
= wp
->w_redraw_top
;
900 if (wp
->w_redraw_bot
!= 0)
901 mod_bot
= wp
->w_redraw_bot
+ 1;
904 wp
->w_redraw_top
= 0; /* reset for next time */
905 wp
->w_redraw_bot
= 0;
908 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
910 mod_top
= buf
->b_mod_top
;
912 /* Need to redraw lines above the change that may be included
913 * in a pattern match. */
914 if (syntax_present(buf
))
916 mod_top
-= buf
->b_syn_sync_linebreaks
;
922 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
923 mod_bot
= buf
->b_mod_bot
;
925 #ifdef FEAT_SEARCH_EXTRA
926 /* When 'hlsearch' is on and using a multi-line search pattern, a
927 * change in one line may make the Search highlighting in a
928 * previous line invalid. Simple solution: redraw all visible
929 * lines above the change.
930 * Same for a match pattern.
932 if (search_hl
.rm
.regprog
!= NULL
933 && re_multiline(search_hl
.rm
.regprog
))
937 cur
= wp
->w_match_head
;
940 if (cur
->match
.regprog
!= NULL
941 && re_multiline(cur
->match
.regprog
))
952 if (mod_top
!= 0 && hasAnyFolding(wp
))
954 linenr_T lnumt
, lnumb
;
957 * A change in a line can cause lines above it to become folded or
958 * unfolded. Find the top most buffer line that may be affected.
959 * If the line was previously folded and displayed, get the first
960 * line of that fold. If the line is folded now, get the first
961 * folded line. Use the minimum of these two.
964 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
965 * the line below it. If there is no valid entry, use w_topline.
966 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
967 * to this line. If there is no valid entry, use MAXLNUM. */
968 lnumt
= wp
->w_topline
;
970 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
971 if (wp
->w_lines
[i
].wl_valid
)
973 if (wp
->w_lines
[i
].wl_lastlnum
< mod_top
)
974 lnumt
= wp
->w_lines
[i
].wl_lastlnum
+ 1;
975 if (lnumb
== MAXLNUM
&& wp
->w_lines
[i
].wl_lnum
>= mod_bot
)
977 lnumb
= wp
->w_lines
[i
].wl_lnum
;
978 /* When there is a fold column it might need updating
979 * in the next line ("J" just above an open fold). */
985 (void)hasFoldingWin(wp
, mod_top
, &mod_top
, NULL
, TRUE
, NULL
);
989 /* Now do the same for the bottom line (one above mod_bot). */
991 (void)hasFoldingWin(wp
, mod_bot
, NULL
, &mod_bot
, TRUE
, NULL
);
998 /* When a change starts above w_topline and the end is below
999 * w_topline, start redrawing at w_topline.
1000 * If the end of the change is above w_topline: do like no change was
1001 * made, but redraw the first line to find changes in syntax. */
1002 if (mod_top
!= 0 && mod_top
< wp
->w_topline
)
1004 if (mod_bot
> wp
->w_topline
)
1005 mod_top
= wp
->w_topline
;
1007 else if (syntax_present(buf
))
1012 /* When line numbers are displayed need to redraw all lines below
1013 * inserted/deleted lines. */
1014 if (mod_top
!= 0 && buf
->b_mod_xlines
!= 0 && wp
->w_p_nu
)
1019 * When only displaying the lines at the top, set top_end. Used when
1020 * window has scrolled down for msg_scrolled.
1022 if (type
== REDRAW_TOP
)
1025 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
1027 j
+= wp
->w_lines
[i
].wl_size
;
1028 if (j
>= wp
->w_upd_rows
)
1035 /* not found (cannot happen?): redraw everything */
1038 /* top area defined, the rest is VALID */
1042 /* Trick: we want to avoid clearing the screen twice. screenclear() will
1043 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1044 * non-zero and thus not FALSE) will indicate that screenclear() was not
1047 screen_cleared
= MAYBE
;
1050 * If there are no changes on the screen that require a complete redraw,
1051 * handle three cases:
1052 * 1: we are off the top of the screen by a few lines: scroll down
1053 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1054 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1055 * w_lines[] that needs updating.
1057 if ((type
== VALID
|| type
== SOME_VALID
1058 || type
== INVERTED
|| type
== INVERTED_ALL
)
1060 && !wp
->w_botfill
&& !wp
->w_old_botfill
1064 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1067 * w_topline is the first changed line, the scrolling will be done
1071 else if (wp
->w_lines
[0].wl_valid
1072 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1074 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1075 && wp
->w_topfill
> wp
->w_old_topfill
)
1080 * New topline is above old topline: May scroll down.
1083 if (hasAnyFolding(wp
))
1087 /* count the number of lines we are off, counting a sequence
1088 * of folded lines as one */
1090 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1093 if (j
>= wp
->w_height
- 2)
1095 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1100 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1101 if (j
< wp
->w_height
- 2) /* not too far off */
1103 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1105 /* insert extra lines for previously invisible filler lines */
1106 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1107 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1108 - wp
->w_old_topfill
;
1110 if (i
< wp
->w_height
- 2) /* less than a screen off */
1113 * Try to insert the correct number of lines.
1114 * If not the last window, delete the lines at the bottom.
1115 * win_ins_lines may fail when the terminal can't do it.
1118 check_for_delay(FALSE
);
1119 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1121 if (wp
->w_lines_valid
!= 0)
1123 /* Need to update rows that are new, stop at the
1124 * first one that scrolled down. */
1127 scrolled_down
= TRUE
;
1130 /* Move the entries that were scrolled, disable
1131 * the entries for the lines to be redrawn. */
1132 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1133 wp
->w_lines_valid
= wp
->w_height
;
1134 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1135 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1137 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1141 mid_start
= 0; /* redraw all lines */
1144 mid_start
= 0; /* redraw all lines */
1147 mid_start
= 0; /* redraw all lines */
1152 * New topline is at or below old topline: May scroll up.
1153 * When topline didn't change, find first entry in w_lines[] that
1157 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1160 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1162 if (wp
->w_lines
[i
].wl_valid
1163 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1168 row
+= wp
->w_lines
[i
].wl_size
;
1172 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1179 * Try to delete the correct number of lines.
1180 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1183 /* If the topline didn't change, delete old filler lines,
1184 * otherwise delete filler lines of the new topline... */
1185 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1186 row
+= wp
->w_old_topfill
;
1188 row
+= diff_check_fill(wp
, wp
->w_topline
);
1189 /* ... but don't delete new filler lines. */
1190 row
-= wp
->w_topfill
;
1194 check_for_delay(FALSE
);
1195 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1196 bot_start
= wp
->w_height
- row
;
1198 mid_start
= 0; /* redraw all lines */
1200 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1203 * Skip the lines (below the deleted lines) that are still
1204 * valid and don't need redrawing. Copy their info
1205 * upwards, to compensate for the deleted lines. Set
1206 * bot_start to the first row that needs redrawing.
1212 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1213 /* stop at line that didn't fit, unless it is still
1214 * valid (no lines deleted) */
1215 if (row
> 0 && bot_start
+ row
1216 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1218 wp
->w_lines_valid
= idx
+ 1;
1221 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1223 /* stop at the last valid entry in w_lines[].wl_size */
1224 if (++j
>= wp
->w_lines_valid
)
1226 wp
->w_lines_valid
= idx
;
1231 /* Correct the first entry for filler lines at the top
1232 * when it won't get updated below. */
1233 if (wp
->w_p_diff
&& bot_start
> 0)
1234 wp
->w_lines
[0].wl_size
=
1235 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1242 /* When starting redraw in the first line, redraw all lines. When
1243 * there is only one window it's probably faster to clear the screen
1247 mid_end
= wp
->w_height
;
1248 if (lastwin
== firstwin
)
1250 /* Clear the screen when it was not done by win_del_lines() or
1251 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1253 if (screen_cleared
!= TRUE
)
1256 /* The screen was cleared, redraw the tab pages line. */
1263 /* When win_del_lines() or win_ins_lines() caused the screen to be
1264 * cleared (only happens for the first window) or when screenclear()
1265 * was called directly above, "must_redraw" will have been set to
1266 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1267 if (screen_cleared
== TRUE
)
1272 /* Not VALID or INVERTED: redraw all lines. */
1274 mid_end
= wp
->w_height
;
1277 if (type
== SOME_VALID
)
1279 /* SOME_VALID: redraw all lines. */
1281 mid_end
= wp
->w_height
;
1286 /* check if we are updating or removing the inverted part */
1287 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1288 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1295 && (VIsual_mode
!= wp
->w_old_visual_mode
1296 || type
== INVERTED_ALL
))
1299 * If the type of Visual selection changed, redraw the whole
1300 * selection. Also when the ownership of the X selection is
1303 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1305 from
= curwin
->w_cursor
.lnum
;
1311 to
= curwin
->w_cursor
.lnum
;
1313 /* redraw more when the cursor moved as well */
1314 if (wp
->w_old_cursor_lnum
< from
)
1315 from
= wp
->w_old_cursor_lnum
;
1316 if (wp
->w_old_cursor_lnum
> to
)
1317 to
= wp
->w_old_cursor_lnum
;
1318 if (wp
->w_old_visual_lnum
< from
)
1319 from
= wp
->w_old_visual_lnum
;
1320 if (wp
->w_old_visual_lnum
> to
)
1321 to
= wp
->w_old_visual_lnum
;
1326 * Find the line numbers that need to be updated: The lines
1327 * between the old cursor position and the current cursor
1328 * position. Also check if the Visual position changed.
1330 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1332 from
= curwin
->w_cursor
.lnum
;
1333 to
= wp
->w_old_cursor_lnum
;
1337 from
= wp
->w_old_cursor_lnum
;
1338 to
= curwin
->w_cursor
.lnum
;
1339 if (from
== 0) /* Visual mode just started */
1343 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1344 || VIsual
.col
!= wp
->w_old_visual_col
)
1346 if (wp
->w_old_visual_lnum
< from
1347 && wp
->w_old_visual_lnum
!= 0)
1348 from
= wp
->w_old_visual_lnum
;
1349 if (wp
->w_old_visual_lnum
> to
)
1350 to
= wp
->w_old_visual_lnum
;
1351 if (VIsual
.lnum
< from
)
1353 if (VIsual
.lnum
> to
)
1359 * If in block mode and changed column or curwin->w_curswant:
1361 * First compute the actual start and end column.
1363 if (VIsual_mode
== Ctrl_V
)
1367 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1369 if (curwin
->w_curswant
== MAXCOL
)
1372 if (fromc
!= wp
->w_old_cursor_fcol
1373 || toc
!= wp
->w_old_cursor_lcol
)
1375 if (from
> VIsual
.lnum
)
1377 if (to
< VIsual
.lnum
)
1380 wp
->w_old_cursor_fcol
= fromc
;
1381 wp
->w_old_cursor_lcol
= toc
;
1386 /* Use the line numbers of the old Visual area. */
1387 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1389 from
= wp
->w_old_cursor_lnum
;
1390 to
= wp
->w_old_visual_lnum
;
1394 from
= wp
->w_old_visual_lnum
;
1395 to
= wp
->w_old_cursor_lnum
;
1400 * There is no need to update lines above the top of the window.
1402 if (from
< wp
->w_topline
)
1403 from
= wp
->w_topline
;
1406 * If we know the value of w_botline, use it to restrict the update to
1407 * the lines that are visible in the window.
1409 if (wp
->w_valid
& VALID_BOTLINE
)
1411 if (from
>= wp
->w_botline
)
1412 from
= wp
->w_botline
- 1;
1413 if (to
>= wp
->w_botline
)
1414 to
= wp
->w_botline
- 1;
1418 * Find the minimal part to be updated.
1419 * Watch out for scrolling that made entries in w_lines[] invalid.
1420 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1421 * top_end; need to redraw from top_end to the "to" line.
1422 * A middle mouse click with a Visual selection may change the text
1423 * above the Visual area and reset wl_valid, do count these for
1424 * mid_end (in srow).
1428 lnum
= wp
->w_topline
;
1432 mid_start
= top_end
;
1435 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1437 if (wp
->w_lines
[idx
].wl_valid
)
1438 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1439 else if (!scrolled_down
)
1440 srow
+= wp
->w_lines
[idx
].wl_size
;
1442 # ifdef FEAT_FOLDING
1443 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1444 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1450 mid_end
= wp
->w_height
;
1451 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1453 if (wp
->w_lines
[idx
].wl_valid
1454 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1456 /* Only update until first row of this line */
1460 srow
+= wp
->w_lines
[idx
].wl_size
;
1465 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1467 wp
->w_old_visual_mode
= VIsual_mode
;
1468 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1469 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1470 wp
->w_old_visual_col
= VIsual
.col
;
1471 wp
->w_old_curswant
= curwin
->w_curswant
;
1475 wp
->w_old_visual_mode
= 0;
1476 wp
->w_old_cursor_lnum
= 0;
1477 wp
->w_old_visual_lnum
= 0;
1478 wp
->w_old_visual_col
= 0;
1480 #endif /* FEAT_VISUAL */
1482 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1483 /* reset got_int, otherwise regexp won't work */
1484 save_got_int
= got_int
;
1488 win_foldinfo
.fi_level
= 0;
1492 * Update all the window rows.
1494 idx
= 0; /* first entry in w_lines[].wl_size */
1497 lnum
= wp
->w_topline
; /* first line shown in window */
1500 /* stop updating when reached the end of the window (check for _past_
1501 * the end of the window is at the end of the loop) */
1502 if (row
== wp
->w_height
)
1508 /* stop updating when hit the end of the file */
1509 if (lnum
> buf
->b_ml
.ml_line_count
)
1515 /* Remember the starting row of the line that is going to be dealt
1516 * with. It is used further down when the line doesn't fit. */
1520 * Update a line when it is in an area that needs updating, when it
1521 * has changes or w_lines[idx] is invalid.
1522 * bot_start may be halfway a wrapped line after using
1523 * win_del_lines(), check if the current line includes it.
1524 * When syntax folding is being used, the saved syntax states will
1525 * already have been updated, we can't see where the syntax state is
1526 * the same again, just update until the end of the window.
1529 || (row
>= mid_start
&& row
< mid_end
)
1530 #ifdef FEAT_SEARCH_EXTRA
1533 || idx
>= wp
->w_lines_valid
1534 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1540 || did_update
== DID_FOLD
1541 || (did_update
== DID_LINE
1542 && syntax_present(buf
)
1544 # ifdef FEAT_FOLDING
1545 (foldmethodIsSyntax(wp
)
1546 && hasAnyFolding(wp
)) ||
1548 syntax_check_changed(lnum
)))
1552 #ifdef FEAT_SEARCH_EXTRA
1553 if (lnum
== mod_top
)
1558 * When at start of changed lines: May scroll following lines
1559 * up or down to minimize redrawing.
1560 * Don't do this when the change continues until the end.
1561 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1564 && mod_bot
!= MAXLNUM
1565 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1572 /* Count the old number of window rows, using w_lines[], which
1573 * should still contain the sizes for the lines as they are
1574 * currently displayed. */
1575 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1577 /* Only valid lines have a meaningful wl_lnum. Invalid
1578 * lines are part of the changed area. */
1579 if (wp
->w_lines
[i
].wl_valid
1580 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1582 old_rows
+= wp
->w_lines
[i
].wl_size
;
1584 if (wp
->w_lines
[i
].wl_valid
1585 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1587 /* Must have found the last valid entry above mod_bot.
1588 * Add following invalid entries. */
1590 while (i
< wp
->w_lines_valid
1591 && !wp
->w_lines
[i
].wl_valid
)
1592 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1598 if (i
>= wp
->w_lines_valid
)
1600 /* We can't find a valid line below the changed lines,
1601 * need to redraw until the end of the window.
1602 * Inserting/deleting lines has no use. */
1607 /* Able to count old number of rows: Count new window
1608 * rows, and may insert/delete lines */
1610 for (l
= lnum
; l
< mod_bot
; ++l
)
1613 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1618 if (l
== wp
->w_topline
)
1619 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1623 new_rows
+= plines_win(wp
, l
, TRUE
);
1625 if (new_rows
> wp
->w_height
- row
- 2)
1627 /* it's getting too much, must redraw the rest */
1632 xtra_rows
= new_rows
- old_rows
;
1635 /* May scroll text up. If there is not enough
1636 * remaining text or scrolling fails, must redraw the
1637 * rest. If scrolling works, must redraw the text
1638 * below the scrolled text. */
1639 if (row
- xtra_rows
>= wp
->w_height
- 2)
1643 check_for_delay(FALSE
);
1644 if (win_del_lines(wp
, row
,
1645 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1648 bot_start
= wp
->w_height
+ xtra_rows
;
1651 else if (xtra_rows
> 0)
1653 /* May scroll text down. If there is not enough
1654 * remaining text of scrolling fails, must redraw the
1656 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1660 check_for_delay(FALSE
);
1661 if (win_ins_lines(wp
, row
+ old_rows
,
1662 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1664 else if (top_end
> row
+ old_rows
)
1665 /* Scrolled the part at the top that requires
1667 top_end
+= xtra_rows
;
1671 /* When not updating the rest, may need to move w_lines[]
1673 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1677 int x
= row
+ new_rows
;
1679 /* move entries in w_lines[] upwards */
1682 /* stop at last valid entry in w_lines[] */
1683 if (i
>= wp
->w_lines_valid
)
1685 wp
->w_lines_valid
= j
;
1688 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1689 /* stop at a line that won't fit */
1690 if (x
+ (int)wp
->w_lines
[j
].wl_size
1693 wp
->w_lines_valid
= j
+ 1;
1696 x
+= wp
->w_lines
[j
++].wl_size
;
1704 /* move entries in w_lines[] downwards */
1706 wp
->w_lines_valid
+= j
;
1707 if (wp
->w_lines_valid
> wp
->w_height
)
1708 wp
->w_lines_valid
= wp
->w_height
;
1709 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1710 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1712 /* The w_lines[] entries for inserted lines are
1713 * now invalid, but wl_size may be used above.
1717 wp
->w_lines
[i
].wl_size
= 0;
1718 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1727 * When lines are folded, display one line for all of them.
1728 * Otherwise, display normally (can be several display lines when
1731 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1732 if (fold_count
!= 0)
1734 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1737 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1738 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1740 did_update
= DID_FOLD
;
1745 if (idx
< wp
->w_lines_valid
1746 && wp
->w_lines
[idx
].wl_valid
1747 && wp
->w_lines
[idx
].wl_lnum
== lnum
1748 && lnum
> wp
->w_topline
1749 && !(dy_flags
& DY_LASTLINE
)
1750 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1752 && diff_check_fill(wp
, lnum
) == 0
1756 /* This line is not going to fit. Don't draw anything here,
1757 * will draw "@ " lines below. */
1758 row
= wp
->w_height
+ 1;
1762 #ifdef FEAT_SEARCH_EXTRA
1763 prepare_search_hl(wp
, lnum
);
1766 /* Let the syntax stuff know we skipped a few lines. */
1767 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1768 && syntax_present(buf
))
1769 syntax_end_parsing(syntax_last_parsed
+ 1);
1775 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1778 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1779 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1782 did_update
= DID_LINE
;
1783 syntax_last_parsed
= lnum
;
1787 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1788 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1789 if (row
> wp
->w_height
) /* past end of screen */
1791 /* we may need the size of that too long line later on */
1792 if (dollar_vcol
== 0)
1793 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1797 if (dollar_vcol
== 0)
1798 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1801 lnum
+= fold_count
+ 1;
1808 /* This line does not need updating, advance to the next one */
1809 row
+= wp
->w_lines
[idx
++].wl_size
;
1810 if (row
> wp
->w_height
) /* past end of screen */
1813 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1818 did_update
= DID_NONE
;
1822 if (lnum
> buf
->b_ml
.ml_line_count
)
1829 * End of loop over all window lines.
1833 if (idx
> wp
->w_lines_valid
)
1834 wp
->w_lines_valid
= idx
;
1838 * Let the syntax stuff know we stop parsing here.
1840 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1841 syntax_end_parsing(syntax_last_parsed
+ 1);
1845 * If we didn't hit the end of the file, and we didn't finish the last
1846 * line we were working on, then the line didn't fit.
1848 wp
->w_empty_rows
= 0;
1850 wp
->w_filler_rows
= 0;
1852 if (!eof
&& !didline
)
1854 if (lnum
== wp
->w_topline
)
1857 * Single line that does not fit!
1858 * Don't overwrite it, it can be edited.
1860 wp
->w_botline
= lnum
+ 1;
1863 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1865 /* Window ends in filler lines. */
1866 wp
->w_botline
= lnum
;
1867 wp
->w_filler_rows
= wp
->w_height
- srow
;
1870 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1873 * Last line isn't finished: Display "@@@" at the end.
1875 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1876 W_WINROW(wp
) + wp
->w_height
,
1877 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1878 '@', '@', hl_attr(HLF_AT
));
1879 set_empty_rows(wp
, srow
);
1880 wp
->w_botline
= lnum
;
1884 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1885 wp
->w_botline
= lnum
;
1890 #ifdef FEAT_VERTSPLIT
1891 draw_vsep_win(wp
, row
);
1893 if (eof
) /* we hit the end of the file */
1895 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1897 j
= diff_check_fill(wp
, wp
->w_botline
);
1898 if (j
> 0 && !wp
->w_botfill
)
1901 * Display filler lines at the end of the file
1903 if (char2cells(fill_diff
) > 1)
1907 if (row
+ j
> wp
->w_height
)
1908 j
= wp
->w_height
- row
;
1909 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1914 else if (dollar_vcol
== 0)
1915 wp
->w_botline
= lnum
;
1917 /* make sure the rest of the screen is blank */
1918 /* put '~'s on rows that aren't part of the file. */
1919 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1922 /* Reset the type of redrawing required, the window has been updated. */
1923 wp
->w_redr_type
= 0;
1925 wp
->w_old_topfill
= wp
->w_topfill
;
1926 wp
->w_old_botfill
= wp
->w_botfill
;
1929 if (dollar_vcol
== 0)
1932 * There is a trick with w_botline. If we invalidate it on each
1933 * change that might modify it, this will cause a lot of expensive
1934 * calls to plines() in update_topline() each time. Therefore the
1935 * value of w_botline is often approximated, and this value is used to
1936 * compute the value of w_topline. If the value of w_botline was
1937 * wrong, check that the value of w_topline is correct (cursor is on
1938 * the visible part of the text). If it's not, we need to redraw
1939 * again. Mostly this just means scrolling up a few lines, so it
1940 * doesn't look too bad. Only do this for the current window (where
1941 * changes are relevant).
1943 wp
->w_valid
|= VALID_BOTLINE
;
1944 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1947 curwin
->w_valid
&= ~VALID_TOPLINE
;
1948 update_topline(); /* may invalidate w_botline again */
1949 if (must_redraw
!= 0)
1951 /* Don't update for changes in buffer again. */
1952 i
= curbuf
->b_mod_set
;
1953 curbuf
->b_mod_set
= FALSE
;
1956 curbuf
->b_mod_set
= i
;
1962 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1963 /* restore got_int, unless CTRL-C was hit while redrawing */
1965 got_int
= save_got_int
;
1970 static int draw_signcolumn
__ARGS((win_T
*wp
));
1973 * Return TRUE when window "wp" has a column to draw signs in.
1979 return (wp
->w_buffer
->b_signlist
!= NULL
1980 # ifdef FEAT_NETBEANS_INTG
1988 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1989 * as the filler character.
1992 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
2000 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
2007 #ifdef FEAT_RIGHTLEFT
2010 /* No check for cmdline window: should never be right-left. */
2011 # ifdef FEAT_FOLDING
2016 /* draw the fold column at the right */
2017 if (n
> W_WIDTH(wp
))
2019 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2020 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
2021 ' ', ' ', hl_attr(HLF_FC
));
2025 if (draw_signcolumn(wp
))
2029 /* draw the sign column left of the fold column */
2030 if (nn
> W_WIDTH(wp
))
2032 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2033 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2034 ' ', ' ', hl_attr(HLF_SC
));
2038 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2039 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2040 c2
, c2
, hl_attr(hl
));
2041 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2042 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2043 c1
, c2
, hl_attr(hl
));
2049 if (cmdwin_type
!= 0 && wp
== curwin
)
2051 /* draw the cmdline character in the leftmost column */
2053 if (n
> wp
->w_width
)
2055 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2056 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2057 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2061 if (wp
->w_p_fdc
> 0)
2063 int nn
= n
+ wp
->w_p_fdc
;
2065 /* draw the fold column at the left */
2066 if (nn
> W_WIDTH(wp
))
2068 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2069 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2070 ' ', ' ', hl_attr(HLF_FC
));
2075 if (draw_signcolumn(wp
))
2079 /* draw the sign column after the fold column */
2080 if (nn
> W_WIDTH(wp
))
2082 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2083 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2084 ' ', ' ', hl_attr(HLF_SC
));
2088 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2089 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2090 c1
, c2
, hl_attr(hl
));
2092 set_empty_rows(wp
, row
);
2097 * Display one folded line.
2100 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2103 foldinfo_T
*foldinfo
;
2109 linenr_T lnume
= lnum
+ fold_count
- 1;
2115 int off
= (int)(current_ScreenLine
- ScreenLines
);
2118 /* Build the fold line:
2119 * 1. Add the cmdwin_type for the command-line window
2120 * 2. Add the 'foldcolumn'
2121 * 3. Add the 'number' column
2122 * 4. Compose the text
2124 * 6. set highlighting for the Visual area an other text
2129 * 1. Add the cmdwin_type for the command-line window
2130 * Ignores 'rightleft', this window is never right-left.
2133 if (cmdwin_type
!= 0 && wp
== curwin
)
2135 ScreenLines
[off
] = cmdwin_type
;
2136 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2139 ScreenLinesUC
[off
] = 0;
2146 * 2. Add the 'foldcolumn'
2149 if (fdc
> W_WIDTH(wp
) - col
)
2150 fdc
= W_WIDTH(wp
) - col
;
2153 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2154 #ifdef FEAT_RIGHTLEFT
2159 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2161 /* reverse the fold column */
2162 for (i
= 0; i
< fdc
; ++i
)
2163 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2167 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2171 #ifdef FEAT_RIGHTLEFT
2172 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2173 for (ri = 0; ri < l; ++ri) \
2174 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2176 for (ri = 0; ri < l; ++ri) \
2177 ScreenAttrs[off + (p) + ri] = v
2179 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2180 ScreenAttrs[off + (p) + ri] = v
2183 /* Set all attributes of the 'number' column and the text */
2184 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2187 /* If signs are being displayed, add two spaces. */
2188 if (draw_signcolumn(wp
))
2190 len
= W_WIDTH(wp
) - col
;
2195 # ifdef FEAT_RIGHTLEFT
2197 /* the line number isn't reversed */
2198 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2199 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2202 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2209 * 3. Add the 'number' column
2213 len
= W_WIDTH(wp
) - col
;
2216 int w
= number_width(wp
);
2220 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2221 #ifdef FEAT_RIGHTLEFT
2223 /* the line number isn't reversed */
2224 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2228 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2234 * 4. Compose the folded-line string with 'foldtext', if set.
2236 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2238 txtcol
= col
; /* remember where text starts */
2241 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2242 * Right-left text is put in columns 0 - number-col, normal text is put
2243 * in columns number-col - window-width.
2249 int u8c
, u8cc
[MAX_MCO
];
2255 int prev_c
= 0; /* previous Arabic character */
2256 int prev_c1
= 0; /* first composing char for prev_c */
2259 # ifdef FEAT_RIGHTLEFT
2266 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2267 for (p
= text
; *p
!= NUL
; )
2269 cells
= (*mb_ptr2cells
)(p
);
2270 c_len
= (*mb_ptr2len
)(p
);
2271 if (col
+ cells
> W_WIDTH(wp
)
2272 # ifdef FEAT_RIGHTLEFT
2273 - (wp
->w_p_rl
? col
: 0)
2277 ScreenLines
[idx
] = *p
;
2280 u8c
= utfc_ptr2char(p
, u8cc
);
2281 if (*p
< 0x80 && u8cc
[0] == 0)
2283 ScreenLinesUC
[idx
] = 0;
2291 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2293 /* Do Arabic shaping. */
2298 /* The idea of what is the previous and next
2299 * character depends on 'rightleft'. */
2304 nc
= utf_ptr2char(p
+ c_len
);
2309 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2315 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2317 ScreenLines
[idx
] = firstbyte
;
2322 /* Non-BMP character: display as ? or fullwidth ?. */
2325 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2328 ScreenLinesUC
[idx
] = u8c
;
2329 for (i
= 0; i
< Screen_mco
; ++i
)
2331 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2337 ScreenLines
[idx
+ 1] = 0;
2339 else if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2340 /* double-byte single width character */
2341 ScreenLines2
[idx
] = p
[1];
2343 /* double-width character */
2344 ScreenLines
[idx
+ 1] = p
[1];
2353 len
= (int)STRLEN(text
);
2354 if (len
> W_WIDTH(wp
) - col
)
2355 len
= W_WIDTH(wp
) - col
;
2358 #ifdef FEAT_RIGHTLEFT
2360 STRNCPY(current_ScreenLine
, text
, len
);
2363 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2368 /* Fill the rest of the line with the fold filler */
2369 #ifdef FEAT_RIGHTLEFT
2373 while (col
< W_WIDTH(wp
)
2374 #ifdef FEAT_RIGHTLEFT
2375 - (wp
->w_p_rl
? txtcol
: 0)
2382 if (fill_fold
>= 0x80)
2384 ScreenLinesUC
[off
+ col
] = fill_fold
;
2385 ScreenLinesC
[0][off
+ col
] = 0;
2388 ScreenLinesUC
[off
+ col
] = 0;
2391 ScreenLines
[off
+ col
++] = fill_fold
;
2398 * 6. set highlighting for the Visual area an other text.
2399 * If all folded lines are in the Visual area, highlight the line.
2402 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2404 if (ltoreq(curwin
->w_cursor
, VIsual
))
2406 /* Visual is after curwin->w_cursor */
2407 top
= &curwin
->w_cursor
;
2412 /* Visual is before curwin->w_cursor */
2414 bot
= &curwin
->w_cursor
;
2416 if (lnum
>= top
->lnum
2417 && lnume
<= bot
->lnum
2418 && (VIsual_mode
!= 'v'
2419 || ((lnum
> top
->lnum
2420 || (lnum
== top
->lnum
2422 && (lnume
< bot
->lnum
2423 || (lnume
== bot
->lnum
2424 && (bot
->col
- (*p_sel
== 'e'))
2425 >= (colnr_T
)STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2427 if (VIsual_mode
== Ctrl_V
)
2429 /* Visual block mode: highlight the chars part of the block */
2430 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2432 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2433 len
= wp
->w_old_cursor_lcol
;
2435 len
= W_WIDTH(wp
) - txtcol
;
2436 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2437 len
- (int)wp
->w_old_cursor_fcol
);
2442 /* Set all attributes of the text */
2443 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2450 /* Show 'cursorcolumn' in the fold line. */
2453 txtcol
+= wp
->w_virtcol
;
2455 txtcol
-= wp
->w_skipcol
;
2457 txtcol
-= wp
->w_leftcol
;
2458 if (txtcol
>= 0 && txtcol
< W_WIDTH(wp
))
2459 ScreenAttrs
[off
+ txtcol
] = hl_combine_attr(
2460 ScreenAttrs
[off
+ txtcol
], hl_attr(HLF_CUC
));
2464 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2465 (int)W_WIDTH(wp
), FALSE
);
2468 * Update w_cline_height and w_cline_folded if the cursor line was
2469 * updated (saves a call to plines() later).
2472 && lnum
<= curwin
->w_cursor
.lnum
2473 && lnume
>= curwin
->w_cursor
.lnum
)
2475 curwin
->w_cline_row
= row
;
2476 curwin
->w_cline_height
= 1;
2477 curwin
->w_cline_folded
= TRUE
;
2478 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2483 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2486 copy_text_attr(off
, buf
, len
, attr
)
2494 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2497 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2499 for (i
= 0; i
< len
; ++i
)
2500 ScreenAttrs
[off
+ i
] = attr
;
2504 * Fill the foldcolumn at "p" for window "wp".
2505 * Only to be called when 'foldcolumn' > 0.
2508 fill_foldcolumn(p
, wp
, closed
, lnum
)
2511 int closed
; /* TRUE of FALSE */
2512 linenr_T lnum
; /* current line number */
2519 /* Init to all spaces. */
2520 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2522 level
= win_foldinfo
.fi_level
;
2525 /* If there is only one column put more info in it. */
2526 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2528 /* If the column is too narrow, we start at the lowest level that
2529 * fits and use numbers to indicated the depth. */
2530 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2531 if (first_level
< 1)
2534 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2536 if (win_foldinfo
.fi_lnum
== lnum
2537 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2539 else if (first_level
== 1)
2541 else if (first_level
+ i
<= 9)
2542 p
[i
] = '0' + first_level
+ i
;
2545 if (first_level
+ i
== level
)
2550 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2552 #endif /* FEAT_FOLDING */
2555 * Display line "lnum" of window 'wp' on the screen.
2556 * Start at row "startrow", stop when "endrow" is reached.
2557 * wp->w_virtcol needs to be valid.
2559 * Return the number of last row the line occupies.
2562 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2567 int nochange UNUSED
; /* not updating for changed text */
2569 int col
; /* visual column on screen */
2570 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2571 int c
= 0; /* init for GCC */
2572 long vcol
= 0; /* virtual column (for tabs) */
2573 long vcol_prev
= -1; /* "vcol" of previous character */
2574 char_u
*line
; /* current line */
2575 char_u
*ptr
; /* current position in "line" */
2576 int row
; /* row in the window, excl w_winrow */
2577 int screen_row
; /* row on the screen, incl w_winrow */
2579 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2580 int n_extra
= 0; /* number of extra chars */
2581 char_u
*p_extra
= NULL
; /* string of extra chars, plus NUL */
2582 int c_extra
= NUL
; /* extra chars, all the same */
2583 int extra_attr
= 0; /* attributes when n_extra != 0 */
2584 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2585 displaying lcs_eol at end-of-line */
2586 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2587 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2589 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2590 int saved_n_extra
= 0;
2591 char_u
*saved_p_extra
= NULL
;
2592 int saved_c_extra
= 0;
2593 int saved_char_attr
= 0;
2595 int n_attr
= 0; /* chars with special attr */
2596 int saved_attr2
= 0; /* char_attr saved for n_attr */
2597 int n_attr3
= 0; /* chars with overruling special attr */
2598 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2600 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2602 int fromcol
, tocol
; /* start/end of inverting */
2603 int fromcol_prev
= -2; /* start of inverting after cursor */
2604 int noinvcur
= FALSE
; /* don't invert the cursor */
2607 int lnum_in_visual_area
= FALSE
;
2612 int char_attr
= 0; /* attributes for next character */
2613 int attr_pri
= FALSE
; /* char_attr has priority */
2614 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2616 int attr
= 0; /* attributes for area highlighting */
2617 int area_attr
= 0; /* attributes desired by highlighting */
2618 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2620 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2621 int syntax_attr
= 0; /* attributes desired by syntax */
2622 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2624 int eol_hl_off
= 0; /* 1 if highlighted char after EOL */
2627 int has_spell
= FALSE
; /* this buffer has spell checking */
2628 # define SPWORDLEN 150
2629 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2630 int nextlinecol
= 0; /* column where nextline[] starts */
2631 int nextline_idx
= 0; /* index in nextline[] where next line
2633 int spell_attr
= 0; /* attributes desired by spelling */
2634 int word_end
= 0; /* last byte with same spell_attr */
2635 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2636 static int checked_col
= 0; /* column in "checked_lnum" up to which
2637 * there are no spell errors */
2638 static int cap_col
= -1; /* column to check for Cap word */
2639 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2640 int cur_checked_col
= 0; /* checked column for current line */
2642 int extra_check
; /* has syntax or linebreak */
2644 int multi_attr
= 0; /* attributes desired by multibyte */
2645 int mb_l
= 1; /* multi-byte byte length */
2646 int mb_c
= 0; /* decoded multi-byte character */
2647 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2648 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2651 int filler_lines
; /* nr of filler lines to be drawn */
2652 int filler_todo
; /* nr of filler lines still to do + 1 */
2653 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2654 int change_start
= MAXCOL
; /* first col of changed area */
2655 int change_end
= -1; /* last col of changed area */
2657 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2658 #ifdef FEAT_LINEBREAK
2659 int need_showbreak
= FALSE
;
2661 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2662 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2664 int line_attr
= 0; /* attribute for the whole line */
2666 #ifdef FEAT_SEARCH_EXTRA
2667 matchitem_T
*cur
; /* points to the match list */
2668 match_T
*shl
; /* points to search_hl or a match */
2669 int shl_flag
; /* flag to indicate whether search_hl
2670 has been processed or not */
2671 int prevcol_hl_flag
; /* flag to indicate whether prevcol
2672 equals startcol of search_hl or one
2676 int prev_c
= 0; /* previous Arabic character */
2677 int prev_c1
= 0; /* first composing char for prev_c */
2679 #if defined(LINE_ATTR)
2680 int did_line_attr
= 0;
2683 /* draw_state: items that are drawn in sequence: */
2684 #define WL_START 0 /* nothing done yet */
2686 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2688 # define WL_CMDLINE WL_START
2691 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2693 # define WL_FOLD WL_CMDLINE
2696 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2698 # define WL_SIGN WL_FOLD /* column for signs */
2700 #define WL_NR WL_SIGN + 1 /* line number */
2701 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2702 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2704 # define WL_SBR WL_NR
2706 #define WL_LINE WL_SBR + 1 /* text in the line */
2707 int draw_state
= WL_START
; /* what to draw next */
2708 #if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
2709 int feedback_col
= 0;
2710 int feedback_old_attr
= -1;
2714 if (startrow
> endrow
) /* past the end already! */
2718 screen_row
= row
+ W_WINROW(wp
);
2721 * To speed up the loop below, set extra_check when there is linebreak,
2722 * trailing white space and/or syntax processing to be done.
2724 #ifdef FEAT_LINEBREAK
2725 extra_check
= wp
->w_p_lbr
;
2730 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2732 /* Prepare for syntax highlighting in this line. When there is an
2733 * error, stop syntax highlighting. */
2734 save_did_emsg
= did_emsg
;
2736 syntax_start(wp
, lnum
);
2738 wp
->w_buffer
->b_syn_error
= TRUE
;
2741 did_emsg
= save_did_emsg
;
2750 && *wp
->w_buffer
->b_p_spl
!= NUL
2751 && wp
->w_buffer
->b_langp
.ga_len
> 0
2752 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2754 /* Prepare for spell checking. */
2758 /* Get the start of the next line, so that words that wrap to the next
2759 * line are found too: "et<line-break>al.".
2760 * Trick: skip a few chars for C/shell/Vim comments */
2761 nextline
[SPWORDLEN
] = NUL
;
2762 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2764 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2765 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2768 /* When a word wrapped from the previous line the start of the current
2770 if (lnum
== checked_lnum
)
2771 cur_checked_col
= checked_col
;
2774 /* When there was a sentence end in the previous line may require a
2775 * word starting with capital in this line. In line 1 always check
2776 * the first word. */
2777 if (lnum
!= capcol_lnum
)
2786 * handle visual active in this window
2791 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2793 /* Visual is after curwin->w_cursor */
2794 if (ltoreq(curwin
->w_cursor
, VIsual
))
2796 top
= &curwin
->w_cursor
;
2799 else /* Visual is before curwin->w_cursor */
2802 bot
= &curwin
->w_cursor
;
2804 lnum_in_visual_area
= (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
);
2805 if (VIsual_mode
== Ctrl_V
) /* block mode */
2807 if (lnum_in_visual_area
)
2809 fromcol
= wp
->w_old_cursor_fcol
;
2810 tocol
= wp
->w_old_cursor_lcol
;
2813 else /* non-block mode */
2815 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2817 else if (lnum
== top
->lnum
)
2819 if (VIsual_mode
== 'V') /* linewise */
2823 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2824 if (gchar_pos(top
) == NUL
)
2825 tocol
= fromcol
+ 1;
2828 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2830 if (*p_sel
== 'e' && bot
->col
== 0
2831 #ifdef FEAT_VIRTUALEDIT
2839 else if (bot
->col
== MAXCOL
)
2845 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2848 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2856 /* Check if the character under the cursor should not be inverted */
2857 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2865 /* if inverting in this line set area_highlighting */
2868 area_highlighting
= TRUE
;
2869 attr
= hl_attr(HLF_V
);
2870 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2871 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2872 attr
= hl_attr(HLF_VNC
);
2878 * handle 'incsearch' and ":s///c" highlighting
2881 #endif /* FEAT_VISUAL */
2884 && lnum
>= curwin
->w_cursor
.lnum
2885 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2887 if (lnum
== curwin
->w_cursor
.lnum
)
2888 getvcol(curwin
, &(curwin
->w_cursor
),
2889 (colnr_T
*)&fromcol
, NULL
, NULL
);
2892 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2895 pos
.col
= search_match_endcol
;
2896 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2900 /* do at least one character; happens when past end of line */
2901 if (fromcol
== tocol
)
2902 tocol
= fromcol
+ 1;
2903 area_highlighting
= TRUE
;
2904 attr
= hl_attr(HLF_I
);
2908 filler_lines
= diff_check(wp
, lnum
);
2909 if (filler_lines
< 0)
2911 if (filler_lines
== -1)
2913 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2914 diff_hlf
= HLF_ADD
; /* added line */
2915 else if (change_start
== 0)
2916 diff_hlf
= HLF_TXD
; /* changed text */
2918 diff_hlf
= HLF_CHD
; /* changed line */
2921 diff_hlf
= HLF_ADD
; /* added line */
2923 area_highlighting
= TRUE
;
2925 if (lnum
== wp
->w_topline
)
2926 filler_lines
= wp
->w_topfill
;
2927 filler_todo
= filler_lines
;
2932 /* If this line has a sign with line highlighting set line_attr. */
2933 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2935 line_attr
= sign_get_attr((int)v
, TRUE
);
2937 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2938 /* Highlight the current line in the quickfix window. */
2939 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2940 line_attr
= hl_attr(HLF_L
);
2943 area_highlighting
= TRUE
;
2946 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2952 /* For checking first word with a capital skip white space. */
2954 cap_col
= (int)(skipwhite(line
) - line
);
2956 /* To be able to spell-check over line boundaries copy the end of the
2957 * current line into nextline[]. Above the start of the next line was
2958 * copied to nextline[SPWORDLEN]. */
2959 if (nextline
[SPWORDLEN
] == NUL
)
2961 /* No next line or it is empty. */
2962 nextlinecol
= MAXCOL
;
2967 v
= (long)STRLEN(line
);
2970 /* Short line, use it completely and append the start of the
2973 mch_memmove(nextline
, line
, (size_t)v
);
2974 STRMOVE(nextline
+ v
, nextline
+ SPWORDLEN
);
2975 nextline_idx
= v
+ 1;
2979 /* Long line, use only the last SPWORDLEN bytes. */
2980 nextlinecol
= v
- SPWORDLEN
;
2981 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2982 nextline_idx
= SPWORDLEN
+ 1;
2988 /* find start of trailing whitespace */
2989 if (wp
->w_p_list
&& lcs_trail
)
2991 trailcol
= (colnr_T
)STRLEN(ptr
);
2992 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
2994 trailcol
+= (colnr_T
) (ptr
- line
);
2999 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
3000 * first character to be displayed.
3009 char_u
*prev_ptr
= ptr
;
3011 while (vcol
< v
&& *ptr
!= NUL
)
3013 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
3021 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3023 * - 'cuc' is set, or
3024 * - 'virtualedit' is set, or
3025 * - the visual mode is active,
3026 * the end of the line may be before the start of the displayed part.
3031 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL)
3035 # ifdef FEAT_VIRTUALEDIT
3042 (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
3050 /* Handle a character that's not completely on the screen: Put ptr at
3051 * that character but skip the first few screen characters. */
3064 * Adjust for when the inverted text is before the screen,
3065 * and when the start of the inverted text is before the screen.
3069 else if (fromcol
>= 0 && fromcol
< vcol
)
3072 #ifdef FEAT_LINEBREAK
3073 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3075 need_showbreak
= TRUE
;
3078 /* When spell checking a word we need to figure out the start of the
3079 * word and if it's badly spelled or not. */
3083 colnr_T linecol
= (colnr_T
)(ptr
- line
);
3084 hlf_T spell_hlf
= HLF_COUNT
;
3087 wp
->w_cursor
.lnum
= lnum
;
3088 wp
->w_cursor
.col
= linecol
;
3089 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3091 /* spell_move_to() may call ml_get() and make "line" invalid */
3092 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3093 ptr
= line
+ linecol
;
3095 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3097 /* no bad word found at line start, don't check until end of a
3099 spell_hlf
= HLF_COUNT
;
3100 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
)
3105 /* bad word found, use attributes until end of word */
3106 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3108 /* Turn index into actual attributes. */
3109 if (spell_hlf
!= HLF_COUNT
)
3110 spell_attr
= highlight_attr
[spell_hlf
];
3115 /* Need to restart syntax highlighting for this line. */
3117 syntax_start(wp
, lnum
);
3124 * Correct highlighting for cursor that can't be disabled.
3125 * Avoids having to check this for each character.
3131 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3133 /* highlighting starts at cursor, let it start just after the
3135 fromcol_prev
= fromcol
;
3138 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3139 /* restart highlighting after the cursor */
3140 fromcol_prev
= wp
->w_virtcol
;
3142 if (fromcol
>= tocol
)
3146 #ifdef FEAT_SEARCH_EXTRA
3148 * Handle highlighting the last used search pattern and matches.
3149 * Do this for both search_hl and the match list.
3151 cur
= wp
->w_match_head
;
3153 while (cur
!= NULL
|| shl_flag
== FALSE
)
3155 if (shl_flag
== FALSE
)
3162 shl
->startcol
= MAXCOL
;
3163 shl
->endcol
= MAXCOL
;
3165 if (shl
->rm
.regprog
!= NULL
)
3167 v
= (long)(ptr
- line
);
3168 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3170 /* Need to get the line again, a multi-line regexp may have made it
3172 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3175 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3177 if (shl
->lnum
== lnum
)
3178 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3181 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3182 - shl
->rm
.startpos
[0].lnum
)
3183 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3185 shl
->endcol
= MAXCOL
;
3186 /* Highlight one character for an empty match. */
3187 if (shl
->startcol
== shl
->endcol
)
3190 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3191 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3196 if ((long)shl
->startcol
< v
) /* match at leftcol */
3198 shl
->attr_cur
= shl
->attr
;
3199 search_attr
= shl
->attr
;
3201 area_highlighting
= TRUE
;
3204 if (shl
!= &search_hl
&& cur
!= NULL
)
3210 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3211 * active, because it's not clear what is selected then. */
3212 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3214 line_attr
= hl_attr(HLF_CUL
);
3215 area_highlighting
= TRUE
;
3219 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3221 #ifdef FEAT_RIGHTLEFT
3224 /* Rightleft window: process the text in the normal direction, but put
3225 * it in current_ScreenLine[] from right to left. Start at the
3226 * rightmost column of the window. */
3227 col
= W_WIDTH(wp
) - 1;
3233 * Repeat for the whole displayed line.
3237 /* Skip this quickly when working on the text. */
3238 if (draw_state
!= WL_LINE
)
3241 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3243 draw_state
= WL_CMDLINE
;
3244 if (cmdwin_type
!= 0 && wp
== curwin
)
3246 /* Draw the cmdline character. */
3248 c_extra
= cmdwin_type
;
3249 char_attr
= hl_attr(HLF_AT
);
3255 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3257 draw_state
= WL_FOLD
;
3258 if (wp
->w_p_fdc
> 0)
3260 /* Draw the 'foldcolumn'. */
3261 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3262 n_extra
= wp
->w_p_fdc
;
3264 p_extra
[n_extra
] = NUL
;
3266 char_attr
= hl_attr(HLF_FC
);
3272 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3274 draw_state
= WL_SIGN
;
3275 /* Show the sign column when there are any signs in this
3276 * buffer or when using Netbeans. */
3277 if (draw_signcolumn(wp
)
3284 # ifdef FEAT_SIGN_ICONS
3288 /* Draw two cells with the sign value or blank. */
3290 char_attr
= hl_attr(HLF_SC
);
3293 if (row
== startrow
)
3295 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3297 # ifdef FEAT_SIGN_ICONS
3298 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3300 if (gui
.in_use
&& icon_sign
!= 0)
3302 /* Use the image in this position. */
3303 c_extra
= SIGN_BYTE
;
3304 # ifdef FEAT_NETBEANS_INTG
3305 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3306 c_extra
= MULTISIGN_BYTE
;
3308 char_attr
= icon_sign
;
3314 p_extra
= sign_get_text(text_sign
);
3315 if (p_extra
!= NULL
)
3318 n_extra
= (int)STRLEN(p_extra
);
3320 char_attr
= sign_get_attr(text_sign
, FALSE
);
3327 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3330 /* Display the line number. After the first fill with blanks
3331 * when the 'n' flag isn't in 'cpo' */
3337 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3339 /* Draw the line number (empty space after wrapping). */
3346 sprintf((char *)extra
, "%*ld ",
3347 number_width(wp
), (long)lnum
);
3348 if (wp
->w_skipcol
> 0)
3349 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3351 #ifdef FEAT_RIGHTLEFT
3352 if (wp
->w_p_rl
) /* reverse line numbers */
3360 n_extra
= number_width(wp
) + 1;
3361 char_attr
= hl_attr(HLF_N
);
3363 /* When 'cursorline' is set highlight the line number of
3364 * the current line differently. */
3365 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3366 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3371 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3372 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3374 draw_state
= WL_SBR
;
3376 if (filler_todo
> 0)
3378 /* Draw "deleted" diff line(s). */
3379 if (char2cells(fill_diff
) > 1)
3382 c_extra
= fill_diff
;
3383 # ifdef FEAT_RIGHTLEFT
3388 n_extra
= W_WIDTH(wp
) - col
;
3389 char_attr
= hl_attr(HLF_DED
);
3392 # ifdef FEAT_LINEBREAK
3393 if (*p_sbr
!= NUL
&& need_showbreak
)
3395 /* Draw 'showbreak' at the start of each broken line. */
3398 n_extra
= (int)STRLEN(p_sbr
);
3399 char_attr
= hl_attr(HLF_AT
);
3400 need_showbreak
= FALSE
;
3401 /* Correct end of highlighted area for 'showbreak',
3402 * required when 'linebreak' is also set. */
3410 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3412 draw_state
= WL_LINE
;
3415 /* Continue item from end of wrapped line. */
3416 n_extra
= saved_n_extra
;
3417 c_extra
= saved_c_extra
;
3418 p_extra
= saved_p_extra
;
3419 char_attr
= saved_char_attr
;
3426 /* When still displaying '$' of change command, stop at cursor */
3427 if (dollar_vcol
!= 0 && wp
== curwin
3428 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3434 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3436 /* Pretend we have finished updating the window. Except when
3437 * 'cursorcolumn' is set. */
3440 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3447 if (draw_state
== WL_LINE
&& area_highlighting
)
3449 /* handle Visual or match highlighting in this line */
3452 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3453 && (*mb_ptr2cells
)(ptr
) > 1)
3455 || ((int)vcol_prev
== fromcol_prev
3456 && vcol_prev
< vcol
/* not at margin */
3458 area_attr
= attr
; /* start highlighting */
3459 else if (area_attr
!= 0
3461 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3462 area_attr
= 0; /* stop highlighting */
3464 #ifdef FEAT_SEARCH_EXTRA
3468 * Check for start/end of search pattern match.
3469 * After end, check for start/end of next match.
3470 * When another match, have to check for start again.
3471 * Watch out for matching an empty string!
3472 * Do this for 'search_hl' and the match list (ordered by
3475 v
= (long)(ptr
- line
);
3476 cur
= wp
->w_match_head
;
3478 while (cur
!= NULL
|| shl_flag
== FALSE
)
3480 if (shl_flag
== FALSE
3482 && cur
->priority
> SEARCH_HL_PRIORITY
)
3490 while (shl
->rm
.regprog
!= NULL
)
3492 if (shl
->startcol
!= MAXCOL
3493 && v
>= (long)shl
->startcol
3494 && v
< (long)shl
->endcol
)
3496 shl
->attr_cur
= shl
->attr
;
3498 else if (v
== (long)shl
->endcol
)
3502 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3504 /* Need to get the line again, a multi-line regexp
3505 * may have made it invalid. */
3506 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3509 if (shl
->lnum
== lnum
)
3511 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3512 if (shl
->rm
.endpos
[0].lnum
== 0)
3513 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3515 shl
->endcol
= MAXCOL
;
3517 if (shl
->startcol
== shl
->endcol
)
3519 /* highlight empty match, try again after
3523 shl
->endcol
+= (*mb_ptr2len
)(line
3530 /* Loop to check if the match starts at the
3531 * current position */
3537 if (shl
!= &search_hl
&& cur
!= NULL
)
3541 /* Use attributes from match with highest priority among
3542 * 'search_hl' and the match list. */
3543 search_attr
= search_hl
.attr_cur
;
3544 cur
= wp
->w_match_head
;
3546 while (cur
!= NULL
|| shl_flag
== FALSE
)
3548 if (shl_flag
== FALSE
3550 && cur
->priority
> SEARCH_HL_PRIORITY
)
3558 if (shl
->attr_cur
!= 0)
3559 search_attr
= shl
->attr_cur
;
3560 if (shl
!= &search_hl
&& cur
!= NULL
)
3567 if (diff_hlf
!= (hlf_T
)0)
3569 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
3571 diff_hlf
= HLF_TXD
; /* changed text */
3572 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
3574 diff_hlf
= HLF_CHD
; /* changed line */
3575 line_attr
= hl_attr(diff_hlf
);
3579 /* Decide which of the highlight attributes to use. */
3582 char_attr
= area_attr
;
3583 else if (search_attr
!= 0)
3584 char_attr
= search_attr
;
3586 /* Use line_attr when not in the Visual or 'incsearch' area
3587 * (area_attr may be 0 when "noinvcur" is set). */
3588 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3589 || vcol
< fromcol
|| vcol_prev
< fromcol_prev
3591 char_attr
= line_attr
;
3598 char_attr
= syntax_attr
;
3606 * Get the next character to put on the screen.
3609 * The "p_extra" points to the extra stuff that is inserted to
3610 * represent special characters (non-printable stuff) and other
3611 * things. When all characters are the same, c_extra is used.
3612 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3613 * "p_extra[n_extra]".
3614 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3622 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3623 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3642 /* If the UTF-8 character is more than one byte:
3643 * Decode it into "mb_c". */
3644 mb_l
= (*mb_ptr2len
)(p_extra
);
3650 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3657 /* if this is a DBCS character, put it in "mb_c" */
3658 mb_l
= MB_BYTE2LEN(c
);
3659 if (mb_l
>= n_extra
)
3662 mb_c
= (c
<< 8) + p_extra
[1];
3664 if (mb_l
== 0) /* at the NUL at end-of-line */
3667 /* If a double-width char doesn't fit display a '>' in the
3670 # ifdef FEAT_RIGHTLEFT
3671 wp
->w_p_rl
? (col
<= 0) :
3673 (col
>= W_WIDTH(wp
) - 1))
3674 && (*mb_char2cells
)(mb_c
) == 2)
3680 multi_attr
= hl_attr(HLF_AT
);
3681 /* put the pointer back to output the double-width
3682 * character at the start of the next line. */
3688 n_extra
-= mb_l
- 1;
3689 p_extra
+= mb_l
- 1;
3700 * Get a character from the line itself.
3709 /* If the UTF-8 character is more than one byte: Decode it
3711 mb_l
= (*mb_ptr2len
)(ptr
);
3715 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3716 /* Overlong encoded ASCII or ASCII with composing char
3717 * is displayed normally, except a NUL. */
3722 /* At start of the line we can have a composing char.
3723 * Draw it as a space with a composing char. */
3724 if (utf_iscomposing(mb_c
))
3728 for (i
= Screen_mco
- 1; i
> 0; --i
)
3729 u8cc
[i
] = u8cc
[i
- 1];
3735 if ((mb_l
== 1 && c
>= 0x80)
3736 || (mb_l
>= 1 && mb_c
== 0)
3737 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3744 * Illegal UTF-8 byte: display as <xx>.
3745 * Non-BMP character : display as ? or fullwidth ?.
3751 transchar_hex(extra
, mb_c
);
3752 # ifdef FEAT_RIGHTLEFT
3753 if (wp
->w_p_rl
) /* reverse */
3758 else if (utf_char2cells(mb_c
) != 2)
3761 /* 0xff1f in UTF-8: full-width '?' */
3762 STRCPY(extra
, "\357\274\237");
3767 mb_c
= mb_ptr2char_adv(&p_extra
);
3768 mb_utf8
= (c
>= 0x80);
3769 n_extra
= (int)STRLEN(p_extra
);
3771 if (area_attr
== 0 && search_attr
== 0)
3773 n_attr
= n_extra
+ 1;
3774 extra_attr
= hl_attr(HLF_8
);
3775 saved_attr2
= char_attr
; /* save current attr */
3778 else if (mb_l
== 0) /* at the NUL at end-of-line */
3781 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3783 /* Do Arabic shaping. */
3787 /* The idea of what is the previous and next
3788 * character depends on 'rightleft'. */
3793 nc
= utf_ptr2char(ptr
+ mb_l
);
3798 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3804 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3812 mb_l
= MB_BYTE2LEN(c
);
3813 if (mb_l
== 0) /* at the NUL at end-of-line */
3817 /* We assume a second byte below 32 is illegal.
3818 * Hopefully this is OK for all double-byte encodings!
3821 mb_c
= (c
<< 8) + ptr
[1];
3826 /* head byte at end of line */
3828 transchar_nonprint(extra
, c
);
3832 /* illegal tail byte */
3834 STRCPY(extra
, "XX");
3837 n_extra
= (int)STRLEN(extra
) - 1;
3840 if (area_attr
== 0 && search_attr
== 0)
3842 n_attr
= n_extra
+ 1;
3843 extra_attr
= hl_attr(HLF_8
);
3844 saved_attr2
= char_attr
; /* save current attr */
3850 /* If a double-width char doesn't fit display a '>' in the
3851 * last column; the character is displayed at the start of the
3854 # ifdef FEAT_RIGHTLEFT
3855 wp
->w_p_rl
? (col
<= 0) :
3857 (col
>= W_WIDTH(wp
) - 1))
3858 && (*mb_char2cells
)(mb_c
) == 2)
3864 multi_attr
= hl_attr(HLF_AT
);
3865 /* Put pointer back so that the character will be
3866 * displayed at the start of the next line. */
3869 else if (*ptr
!= NUL
)
3872 /* If a double-width char doesn't fit at the left side display
3873 * a '<' in the first column. */
3874 if (n_skip
> 0 && mb_l
> 1)
3879 if (area_attr
== 0 && search_attr
== 0)
3881 n_attr
= n_extra
+ 1;
3882 extra_attr
= hl_attr(HLF_AT
);
3883 saved_attr2
= char_attr
; /* save current attr */
3894 /* 'list' : change char 160 to lcs_nbsp. */
3895 if (wp
->w_p_list
&& (c
== 160
3897 || (mb_utf8
&& mb_c
== 160)
3902 if (area_attr
== 0 && search_attr
== 0)
3905 extra_attr
= hl_attr(HLF_8
);
3906 saved_attr2
= char_attr
; /* save current attr */
3910 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3924 int can_spell
= TRUE
;
3928 /* Get syntax attribute, unless still at the start of the line
3929 * (double-wide char that doesn't fit). */
3930 v
= (long)(ptr
- line
);
3931 if (has_syntax
&& v
> 0)
3933 /* Get the syntax attribute for the character. If there
3934 * is an error, disable syntax highlighting. */
3935 save_did_emsg
= did_emsg
;
3938 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3940 has_spell
? &can_spell
:
3946 wp
->w_buffer
->b_syn_error
= TRUE
;
3950 did_emsg
= save_did_emsg
;
3952 /* Need to get the line again, a multi-line regexp may
3953 * have made it invalid. */
3954 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3958 char_attr
= syntax_attr
;
3960 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3965 /* Check spelling (unless at the end of the line).
3966 * Only do this when there is no syntax highlighting, the
3967 * @Spell cluster is not used or the current syntax item
3968 * contains the @Spell cluster. */
3969 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3974 char_attr
= syntax_attr
;
3982 char_u
*prev_ptr
, *p
;
3984 hlf_T spell_hlf
= HLF_COUNT
;
3988 prev_ptr
= ptr
- mb_l
;
3995 /* Use nextline[] if possible, it has the start of the
3996 * next line concatenated. */
3997 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3998 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
4001 cap_col
-= (int)(prev_ptr
- line
);
4002 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
4006 /* In Insert mode only highlight a word that
4007 * doesn't touch the cursor. */
4008 if (spell_hlf
!= HLF_COUNT
4009 && (State
& INSERT
) != 0
4010 && wp
->w_cursor
.lnum
== lnum
4011 && wp
->w_cursor
.col
>=
4012 (colnr_T
)(prev_ptr
- line
)
4013 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
4015 spell_hlf
= HLF_COUNT
;
4016 spell_redraw_lnum
= lnum
;
4019 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
4020 && (p
- nextline
) + len
> nextline_idx
)
4022 /* Remember that the good word continues at the
4023 * start of the next line. */
4024 checked_lnum
= lnum
+ 1;
4025 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
4028 /* Turn index into actual attributes. */
4029 if (spell_hlf
!= HLF_COUNT
)
4030 spell_attr
= highlight_attr
[spell_hlf
];
4035 && (p
- nextline
) + cap_col
>= nextline_idx
)
4037 /* Remember that the word in the next line
4038 * must start with a capital. */
4039 capcol_lnum
= lnum
+ 1;
4040 cap_col
= (int)((p
- nextline
) + cap_col
4044 /* Compute the actual column. */
4045 cap_col
+= (int)(prev_ptr
- line
);
4049 if (spell_attr
!= 0)
4052 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
4054 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
4057 #ifdef FEAT_LINEBREAK
4059 * Found last space before word: check for line break.
4061 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
4064 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
4068 1), (colnr_T
)vcol
, NULL
) - 1;
4075 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
4081 extra_attr
= hl_attr(HLF_8
);
4082 saved_attr2
= char_attr
; /* save current attr */
4086 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4099 * Handling of non-printable characters.
4101 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
4104 * when getting a character from the file, we may have to
4105 * turn it into something else on the way to putting it
4106 * into "ScreenLines".
4108 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
4110 /* tab amount depends on current column */
4111 n_extra
= (int)wp
->w_buffer
->b_p_ts
4112 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
4114 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4120 n_attr
= n_extra
+ 1;
4121 extra_attr
= hl_attr(HLF_8
);
4122 saved_attr2
= char_attr
; /* save current attr */
4125 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4140 && ((wp
->w_p_list
&& lcs_eol
> 0)
4141 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4144 && VIsual_mode
!= Ctrl_V
4147 # ifdef FEAT_RIGHTLEFT
4148 wp
->w_p_rl
? (col
>= 0) :
4150 (col
< W_WIDTH(wp
)))
4152 && lnum
== wp
->w_cursor
.lnum
4153 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4154 && lcs_eol_one
>= 0)
4156 /* Display a '$' after the line or highlight an extra
4157 * character if the line break is included. */
4158 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4159 /* For a diff line the highlighting continues after the
4163 diff_hlf
== (hlf_T
)0
4174 #ifdef FEAT_VIRTUALEDIT
4175 /* In virtualedit, visual selections may extend
4176 * beyond end of line. */
4177 if (area_highlighting
&& virtual_active()
4178 && tocol
!= MAXCOL
&& vcol
< tocol
)
4183 p_extra
= at_end_str
;
4193 --ptr
; /* put it back at the NUL */
4196 extra_attr
= hl_attr(HLF_AT
);
4201 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4208 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4213 p_extra
= transchar(c
);
4214 #ifdef FEAT_RIGHTLEFT
4215 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4216 rl_mirror(p_extra
); /* reverse "<12>" */
4218 n_extra
= byte2cells(c
) - 1;
4223 n_attr
= n_extra
+ 1;
4224 extra_attr
= hl_attr(HLF_8
);
4225 saved_attr2
= char_attr
; /* save current attr */
4228 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4231 #ifdef FEAT_VIRTUALEDIT
4232 else if (VIsual_active
4233 && (VIsual_mode
== Ctrl_V
4234 || VIsual_mode
== 'v')
4239 # ifdef FEAT_RIGHTLEFT
4240 wp
->w_p_rl
? (col
>= 0) :
4242 (col
< W_WIDTH(wp
))))
4245 --ptr
; /* put it back at the NUL */
4248 #if defined(LINE_ATTR)
4251 diff_hlf
!= (hlf_T
)0 ||
4255 # ifdef FEAT_RIGHTLEFT
4256 wp
->w_p_rl
? (col
>= 0) :
4258 (col
< W_WIDTH(wp
))))
4260 /* Highlight until the right side of the window */
4262 --ptr
; /* put it back at the NUL */
4264 /* Remember we do the char for line highlighting. */
4267 /* don't do search HL for the rest of the line */
4268 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4269 char_attr
= line_attr
;
4271 if (diff_hlf
== HLF_TXD
)
4274 if (attr
== 0 || char_attr
!= attr
)
4275 char_attr
= hl_attr(diff_hlf
);
4283 /* Don't override visual selection highlighting. */
4285 && draw_state
== WL_LINE
4287 char_attr
= extra_attr
;
4289 #if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
4290 /* XIM don't send preedit_start and preedit_end, but they send
4291 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4292 * im_is_preediting() here. */
4294 # ifndef FEAT_GUI_MACVIM
4297 lnum
== wp
->w_cursor
.lnum
4300 && im_is_preediting()
4301 && draw_state
== WL_LINE
)
4305 if (preedit_end_col
== MAXCOL
)
4306 getvcol(curwin
, &(wp
->w_cursor
), &tcol
, NULL
, NULL
);
4308 tcol
= preedit_end_col
;
4309 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4311 if (feedback_old_attr
< 0)
4314 feedback_old_attr
= char_attr
;
4316 char_attr
= im_get_feedback_attr(feedback_col
);
4318 char_attr
= feedback_old_attr
;
4321 else if (feedback_old_attr
>= 0)
4323 char_attr
= feedback_old_attr
;
4324 feedback_old_attr
= -1;
4330 * Handle the case where we are in column 0 but not on the first
4331 * character of the line and the user wants us to show us a
4332 * special character (via 'listchars' option "precedes:<char>".
4334 if (lcs_prec_todo
!= NUL
4335 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4339 && draw_state
> WL_NR
4343 lcs_prec_todo
= NUL
;
4346 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4353 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4357 saved_attr3
= char_attr
; /* save current attr */
4358 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4364 * At end of the text line or just after the last character.
4367 #if defined(LINE_ATTR)
4368 || did_line_attr
== 1
4372 #ifdef FEAT_SEARCH_EXTRA
4373 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4375 /* we're not really at that column when skipping some text */
4376 if ((long)(wp
->w_p_wrap
? wp
->w_skipcol
: wp
->w_leftcol
) > prevcol
)
4380 /* invert at least one char, used for Visual and empty line or
4381 * highlight match at end of line. If it's beyond the last
4382 * char on the screen, just overwrite that one (tricky!) Not
4383 * needed when a '$' was displayed for 'list'. */
4384 #ifdef FEAT_SEARCH_EXTRA
4385 prevcol_hl_flag
= FALSE
;
4386 if (prevcol
== (long)search_hl
.startcol
)
4387 prevcol_hl_flag
= TRUE
;
4390 cur
= wp
->w_match_head
;
4393 if (prevcol
== (long)cur
->hl
.startcol
)
4395 prevcol_hl_flag
= TRUE
;
4402 if (lcs_eol
== lcs_eol_one
4403 && ((area_attr
!= 0 && vcol
== fromcol
4405 && (VIsual_mode
!= Ctrl_V
4406 || lnum
== VIsual
.lnum
4407 || lnum
== curwin
->w_cursor
.lnum
)
4410 #ifdef FEAT_SEARCH_EXTRA
4411 /* highlight 'hlsearch' match at end of line */
4412 || (prevcol_hl_flag
== TRUE
4413 # if defined(LINE_ATTR)
4414 && did_line_attr
<= 1
4422 #ifdef FEAT_RIGHTLEFT
4431 if (col
>= W_WIDTH(wp
))
4436 /* At the window boundary, highlight the last character
4437 * instead (better than nothing). */
4443 /* Add a blank character to highlight. */
4444 ScreenLines
[off
] = ' ';
4447 ScreenLinesUC
[off
] = 0;
4450 #ifdef FEAT_SEARCH_EXTRA
4453 /* Use attributes from match with highest priority among
4454 * 'search_hl' and the match list. */
4455 char_attr
= search_hl
.attr
;
4456 cur
= wp
->w_match_head
;
4458 while (cur
!= NULL
|| shl_flag
== FALSE
)
4460 if (shl_flag
== FALSE
4462 && cur
->priority
> SEARCH_HL_PRIORITY
)
4470 if ((ptr
- line
) - 1 == (long)shl
->startcol
)
4471 char_attr
= shl
->attr
;
4472 if (shl
!= &search_hl
&& cur
!= NULL
)
4477 ScreenAttrs
[off
] = char_attr
;
4478 #ifdef FEAT_RIGHTLEFT
4498 * At end of the text line.
4503 if (eol_hl_off
> 0 && vcol
- eol_hl_off
== (long)wp
->w_virtcol
4504 && lnum
== wp
->w_cursor
.lnum
)
4506 /* highlight last char after line */
4512 /* Highlight 'cursorcolumn' past end of the line. */
4517 /* check if line ends before left margin */
4518 if (vcol
< v
+ col
- win_col_off(wp
))
4520 vcol
= v
+ col
- win_col_off(wp
);
4522 && (int)wp
->w_virtcol
>= vcol
- eol_hl_off
4523 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4525 && lnum
!= wp
->w_cursor
.lnum
4526 # ifdef FEAT_RIGHTLEFT
4531 while (col
< W_WIDTH(wp
))
4533 ScreenLines
[off
] = ' ';
4536 ScreenLinesUC
[off
] = 0;
4539 if (vcol
== (long)wp
->w_virtcol
)
4541 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4544 ScreenAttrs
[off
++] = 0;
4550 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4555 * Update w_cline_height and w_cline_folded if the cursor line was
4556 * updated (saves a call to plines() later).
4558 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4560 curwin
->w_cline_row
= startrow
;
4561 curwin
->w_cline_height
= row
- startrow
;
4563 curwin
->w_cline_folded
= FALSE
;
4565 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4571 /* line continues beyond line end */
4578 #ifdef FEAT_RIGHTLEFT
4579 wp
->w_p_rl
? col
== 0 :
4581 col
== W_WIDTH(wp
) - 1)
4583 || (wp
->w_p_list
&& lcs_eol_one
> 0)
4584 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4587 char_attr
= hl_attr(HLF_AT
);
4590 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4602 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4603 * highlight the cursor position itself. */
4604 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4605 && lnum
!= wp
->w_cursor
.lnum
4606 && draw_state
== WL_LINE
4607 && !lnum_in_visual_area
)
4609 vcol_save_attr
= char_attr
;
4610 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4613 vcol_save_attr
= -1;
4617 * Store character to be displayed.
4618 * Skip characters that are left of the screen for 'nowrap'.
4621 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4624 * Store the character.
4626 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4627 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4629 /* A double-wide character is: put first halve in left cell. */
4634 ScreenLines
[off
] = c
;
4636 if (enc_dbcs
== DBCS_JPNU
)
4638 if ((mb_c
& 0xff00) == 0x8e00)
4639 ScreenLines
[off
] = 0x8e;
4640 ScreenLines2
[off
] = mb_c
& 0xff;
4648 ScreenLinesUC
[off
] = mb_c
;
4649 if ((c
& 0xff) == 0)
4650 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4651 for (i
= 0; i
< Screen_mco
; ++i
)
4653 ScreenLinesC
[i
][off
] = u8cc
[i
];
4659 ScreenLinesUC
[off
] = 0;
4663 ScreenAttrs
[off
] = multi_attr
;
4668 ScreenAttrs
[off
] = char_attr
;
4671 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4673 /* Need to fill two screen columns. */
4677 /* UTF-8: Put a 0 in the second screen char. */
4678 ScreenLines
[off
] = 0;
4680 /* DBCS: Put second byte in the second screen char. */
4681 ScreenLines
[off
] = mb_c
& 0xff;
4683 /* When "tocol" is halfway a character, set it to the end of
4684 * the character, otherwise highlighting won't stop. */
4687 #ifdef FEAT_RIGHTLEFT
4690 /* now it's time to backup one cell */
4697 #ifdef FEAT_RIGHTLEFT
4713 /* Only advance the "vcol" when after the 'number' column. */
4714 if (draw_state
> WL_NR
4722 if (vcol_save_attr
>= 0)
4723 char_attr
= vcol_save_attr
;
4726 /* restore attributes after "predeces" in 'listchars' */
4727 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4728 char_attr
= saved_attr3
;
4730 /* restore attributes after last 'listchars' or 'number' char */
4731 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4732 char_attr
= saved_attr2
;
4735 * At end of screen line and there is more to come: Display the line
4736 * so far. If there is no more to display it is caught above.
4739 #ifdef FEAT_RIGHTLEFT
4740 wp
->w_p_rl
? (col
< 0) :
4742 (col
>= W_WIDTH(wp
)))
4747 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4748 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4751 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4756 /* When not wrapping and finished diff lines, or when displayed
4757 * '$' and highlighting until last column, break here. */
4762 ) || lcs_eol_one
== -1)
4765 /* When the window is too narrow draw all "@" lines. */
4766 if (draw_state
!= WL_LINE
4772 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4773 #ifdef FEAT_VERTSPLIT
4774 draw_vsep_win(wp
, row
);
4779 /* When line got too long for screen break here. */
4786 if (screen_cur_row
== screen_row
- 1
4790 && W_WIDTH(wp
) == Columns
)
4792 /* Remember that the line wraps, used for modeless copy. */
4793 LineWraps
[screen_row
- 1] = TRUE
;
4796 * Special trick to make copy/paste of wrapped lines work with
4797 * xterm/screen: write an extra character beyond the end of
4798 * the line. This will work with all terminal types
4799 * (regardless of the xn,am settings).
4800 * Only do this on a fast tty.
4801 * Only do this if the cursor is on the current line
4802 * (something has been written in it).
4803 * Don't do this for the GUI.
4804 * Don't do this for double-width characters.
4805 * Don't do this for a window not at the right screen border.
4813 && ((*mb_off2cells
)(LineOffset
[screen_row
],
4814 LineOffset
[screen_row
] + screen_Columns
)
4816 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4818 LineOffset
[screen_row
] + screen_Columns
)
4823 /* First make sure we are at the end of the screen line,
4824 * then output the same character again to let the
4825 * terminal know about the wrap. If the terminal doesn't
4826 * auto-wrap, we overwrite the character. */
4827 if (screen_cur_col
!= W_WIDTH(wp
))
4828 screen_char(LineOffset
[screen_row
- 1]
4829 + (unsigned)Columns
- 1,
4830 screen_row
- 1, (int)(Columns
- 1));
4833 /* When there is a multi-byte character, just output a
4834 * space to keep it simple. */
4835 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4836 screen_row
- 1] + (Columns
- 1)]) > 1)
4840 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4842 /* force a redraw of the first char on the next line */
4843 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4844 screen_start(); /* don't know where cursor is now */
4849 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4850 #ifdef FEAT_RIGHTLEFT
4853 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4858 /* reset the drawing state for the start of a wrapped line */
4859 draw_state
= WL_START
;
4860 saved_n_extra
= n_extra
;
4861 saved_p_extra
= p_extra
;
4862 saved_c_extra
= c_extra
;
4863 saved_char_attr
= char_attr
;
4865 lcs_prec_todo
= lcs_prec
;
4866 #ifdef FEAT_LINEBREAK
4868 if (filler_todo
<= 0)
4870 need_showbreak
= TRUE
;
4874 /* When the filler lines are actually below the last line of the
4875 * file, don't draw the line itself, break here. */
4876 if (filler_todo
== 0 && wp
->w_botfill
)
4881 } /* for every character in the line */
4884 /* After an empty line check first word for capital. */
4885 if (*skipwhite(line
) == NUL
)
4887 capcol_lnum
= lnum
+ 1;
4896 static int comp_char_differs
__ARGS((int, int));
4899 * Return if the composing characters at "off_from" and "off_to" differ.
4900 * Only to be used when ScreenLinesUC[off_from] != 0.
4903 comp_char_differs(off_from
, off_to
)
4909 for (i
= 0; i
< Screen_mco
; ++i
)
4911 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4913 if (ScreenLinesC
[i
][off_from
] == 0)
4921 * Check whether the given character needs redrawing:
4922 * - the (first byte of the) character is different
4923 * - the attributes are different
4924 * - the character is multi-byte and the next byte is different
4925 * - the character is two cells wide and the second cell differs.
4928 char_needs_redraw(off_from
, off_to
, cols
)
4934 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4935 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4939 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4940 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4941 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4942 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4943 != ScreenLines
[off_to
+ 1])))
4945 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4946 || (ScreenLinesUC
[off_from
] != 0
4947 && comp_char_differs(off_from
, off_to
))
4948 || (cols
> 1 && ScreenLines
[off_from
+ 1]
4949 != ScreenLines
[off_to
+ 1])))
4957 * Move one "cooked" screen line to the screen, but only the characters that
4958 * have actually changed. Handle insert/delete character.
4959 * "coloff" gives the first column on the screen for this line.
4960 * "endcol" gives the columns where valid characters are.
4961 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4962 * needs to be cleared, negative otherwise.
4963 * "rlflag" is TRUE in a rightleft window:
4964 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4965 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4968 screen_line(row
, coloff
, endcol
, clear_width
4969 #ifdef FEAT_RIGHTLEFT
4977 #ifdef FEAT_RIGHTLEFT
4984 unsigned max_off_from
;
4985 unsigned max_off_to
;
4988 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4991 int force
= FALSE
; /* force update rest of the line */
4992 int redraw_this
/* bool: does character need redraw? */
4994 = TRUE
/* For GUI when while-loop empty */
4997 int redraw_next
; /* redraw_this for next character */
4999 int clear_next
= FALSE
;
5000 int char_cells
; /* 1: normal char */
5001 /* 2: occupies two display cells */
5002 # define CHAR_CELLS char_cells
5004 # define CHAR_CELLS 1
5007 # ifdef FEAT_CLIPBOARD
5008 clip_may_clear_selection(row
, row
);
5011 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
5012 off_to
= LineOffset
[row
] + coloff
;
5014 max_off_from
= off_from
+ screen_Columns
;
5015 max_off_to
= LineOffset
[row
] + screen_Columns
;
5018 #ifdef FEAT_RIGHTLEFT
5021 /* Clear rest first, because it's left of the text. */
5022 if (clear_width
> 0)
5024 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
5025 && ScreenAttrs
[off_to
] == 0
5027 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5035 screen_fill(row
, row
+ 1, col
+ coloff
,
5036 endcol
+ coloff
+ 1, ' ', ' ', 0);
5039 off_to
= LineOffset
[row
] + col
+ coloff
;
5041 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
5043 #endif /* FEAT_RIGHTLEFT */
5045 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
5047 while (col
< endcol
)
5050 if (has_mbyte
&& (col
+ 1 < endcol
))
5051 char_cells
= (*mb_off2cells
)(off_from
, max_off_from
);
5056 redraw_this
= redraw_next
;
5057 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
5058 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
5061 /* If the next character was bold, then redraw the current character to
5062 * remove any pixels that might have spilt over into us. This only
5063 * happens in the GUI.
5065 if (redraw_next
&& gui
.in_use
)
5067 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
5069 hl
= syn_attr2attr(hl
);
5078 * Special handling when 'xs' termcap flag set (hpterm):
5079 * Attributes for characters are stored at the position where the
5080 * cursor is when writing the highlighting code. The
5081 * start-highlighting code must be written with the cursor on the
5082 * first highlighted character. The stop-highlighting code must
5083 * be written with the cursor just after the last highlighted
5085 * Overwriting a character doesn't remove it's highlighting. Need
5086 * to clear the rest of the line, and force redrawing it
5094 && ScreenAttrs
[off_to
] != 0
5095 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
5098 * Need to remove highlighting attributes here.
5100 windgoto(row
, col
+ coloff
);
5101 out_str(T_CE
); /* clear rest of this screen line */
5102 screen_start(); /* don't know where cursor is now */
5103 force
= TRUE
; /* force redraw of rest of the line */
5104 redraw_next
= TRUE
; /* or else next char would miss out */
5107 * If the previous character was highlighted, need to stop
5108 * highlighting at this character.
5110 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
5112 screen_attr
= ScreenAttrs
[off_to
- 1];
5113 term_windgoto(row
, col
+ coloff
);
5114 screen_stop_highlight();
5117 screen_attr
= 0; /* highlighting has stopped */
5122 /* Check if overwriting a double-byte with a single-byte or
5123 * the other way around requires another character to be
5124 * redrawn. For UTF-8 this isn't needed, because comparing
5125 * ScreenLinesUC[] is sufficient. */
5128 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5130 /* Writing a single-cell character over a double-cell
5131 * character: need to redraw the next cell. */
5132 ScreenLines
[off_to
+ 1] = 0;
5135 else if (char_cells
== 2
5137 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5138 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)
5140 /* Writing the second half of a double-cell character over
5141 * a double-cell character: need to redraw the second
5143 ScreenLines
[off_to
+ 2] = 0;
5147 if (enc_dbcs
== DBCS_JPNU
)
5148 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
5150 /* When writing a single-width character over a double-width
5151 * character and at the end of the redrawn text, need to clear out
5152 * the right halve of the old character.
5153 * Also required when writing the right halve of a double-width
5154 * char over the left halve of an existing one. */
5155 if (has_mbyte
&& col
+ char_cells
== endcol
5156 && ((char_cells
== 1
5157 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5159 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5160 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)))
5164 ScreenLines
[off_to
] = ScreenLines
[off_from
];
5168 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
5169 if (ScreenLinesUC
[off_from
] != 0)
5173 for (i
= 0; i
< Screen_mco
; ++i
)
5174 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
5177 if (char_cells
== 2)
5178 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
5181 #if defined(FEAT_GUI) || defined(UNIX)
5182 /* The bold trick makes a single column of pixels appear in the
5183 * next character. When a bold character is removed, the next
5184 * character should be redrawn too. This happens for our own GUI
5185 * and for some xterms. */
5190 # if defined(FEAT_GUI) && defined(UNIX)
5198 hl
= ScreenAttrs
[off_to
];
5200 hl
= syn_attr2attr(hl
);
5205 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5207 /* For simplicity set the attributes of second half of a
5208 * double-wide character equal to the first half. */
5209 if (char_cells
== 2)
5210 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5212 if (enc_dbcs
!= 0 && char_cells
== 2)
5213 screen_char_2(off_to
, row
, col
+ coloff
);
5216 screen_char(off_to
, row
, col
+ coloff
);
5222 && col
+ coloff
> 0)
5224 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5227 * Don't output stop-highlight when moving the cursor, it will
5228 * stop the highlighting when it should continue.
5232 else if (screen_attr
!= 0)
5233 screen_stop_highlight();
5236 off_to
+= CHAR_CELLS
;
5237 off_from
+= CHAR_CELLS
;
5244 /* Clear the second half of a double-wide character of which the left
5245 * half was overwritten with a single-wide character. */
5246 ScreenLines
[off_to
] = ' ';
5248 ScreenLinesUC
[off_to
] = 0;
5249 screen_char(off_to
, row
, col
+ coloff
);
5254 #ifdef FEAT_RIGHTLEFT
5263 /* blank out the rest of the line */
5264 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5265 && ScreenAttrs
[off_to
] == 0
5267 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5274 if (col
< clear_width
)
5278 * In the GUI, clearing the rest of the line may leave pixels
5279 * behind if the first character cleared was bold. Some bold
5280 * fonts spill over the left. In this case we redraw the previous
5281 * character too. If we didn't skip any blanks above, then we
5282 * only redraw if the character wasn't already redrawn anyway.
5284 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5286 hl
= ScreenAttrs
[off_to
];
5287 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5292 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5293 * that its width is 2. */
5294 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5295 else if (enc_dbcs
!= 0)
5297 /* find previous character by counting from first
5298 * column and get its width. */
5299 unsigned off
= LineOffset
[row
];
5300 unsigned max_off
= LineOffset
[row
] + screen_Columns
;
5302 while (off
< off_to
)
5304 prev_cells
= (*mb_off2cells
)(off
, max_off
);
5309 if (enc_dbcs
!= 0 && prev_cells
> 1)
5310 screen_char_2(off_to
- prev_cells
, row
,
5311 col
+ coloff
- prev_cells
);
5314 screen_char(off_to
- prev_cells
, row
,
5315 col
+ coloff
- prev_cells
);
5319 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5321 #ifdef FEAT_VERTSPLIT
5322 off_to
+= clear_width
- col
;
5328 if (clear_width
> 0)
5330 #ifdef FEAT_VERTSPLIT
5331 /* For a window that's left of another, draw the separator char. */
5332 if (col
+ coloff
< Columns
)
5336 c
= fillchar_vsep(&hl
);
5337 if (ScreenLines
[off_to
] != c
5339 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5340 != (c
>= 0x80 ? c
: 0))
5342 || ScreenAttrs
[off_to
] != hl
)
5344 ScreenLines
[off_to
] = c
;
5345 ScreenAttrs
[off_to
] = hl
;
5351 ScreenLinesUC
[off_to
] = c
;
5352 ScreenLinesC
[0][off_to
] = 0;
5355 ScreenLinesUC
[off_to
] = 0;
5358 screen_char(off_to
, row
, col
+ coloff
);
5363 LineWraps
[row
] = FALSE
;
5367 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5369 * Mirror text "str" for right-left displaying.
5370 * Only works for single-byte characters (e.g., numbers).
5379 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5388 #if defined(FEAT_WINDOWS) || defined(PROTO)
5390 * mark all status lines for redraw; used after first :cd
5397 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5398 if (wp
->w_status_height
)
5400 wp
->w_redr_status
= TRUE
;
5401 redraw_later(VALID
);
5406 * mark all status lines of the current buffer for redraw
5409 status_redraw_curbuf()
5413 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5414 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5416 wp
->w_redr_status
= TRUE
;
5417 redraw_later(VALID
);
5422 * Redraw all status lines that need to be redrawn.
5425 redraw_statuslines()
5429 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5430 if (wp
->w_redr_status
)
5431 win_redr_status(wp
);
5437 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5439 * Redraw all status lines at the bottom of frame "frp".
5442 win_redraw_last_status(frp
)
5445 if (frp
->fr_layout
== FR_LEAF
)
5446 frp
->fr_win
->w_redr_status
= TRUE
;
5447 else if (frp
->fr_layout
== FR_ROW
)
5449 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5450 win_redraw_last_status(frp
);
5452 else /* frp->fr_layout == FR_COL */
5454 frp
= frp
->fr_child
;
5455 while (frp
->fr_next
!= NULL
)
5457 win_redraw_last_status(frp
);
5462 #ifdef FEAT_VERTSPLIT
5464 * Draw the verticap separator right of window "wp" starting with line "row".
5467 draw_vsep_win(wp
, row
)
5474 if (wp
->w_vsep_width
)
5476 /* draw the vertical separator right of this window */
5477 c
= fillchar_vsep(&hl
);
5478 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5479 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5485 #ifdef FEAT_WILDMENU
5486 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5487 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5490 * Get the length of an item as it will be shown in the status line.
5493 status_match_len(xp
, s
)
5500 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5501 || xp
->xp_context
== EXPAND_MENUNAMES
);
5503 /* Check for menu separators - replace with '|'. */
5504 if (emenu
&& menu_is_separator(s
))
5510 s
+= skip_status_match_char(xp
, s
);
5511 len
+= ptr2cells(s
);
5519 * Return the number of characters that should be skipped in a status match.
5520 * These are backslashes used for escaping. Do show backslashes in help tags.
5523 skip_status_match_char(xp
, s
)
5527 if ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5529 || ((xp
->xp_context
== EXPAND_MENUS
5530 || xp
->xp_context
== EXPAND_MENUNAMES
)
5531 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5535 #ifndef BACKSLASH_IN_FILENAME
5536 if (xp
->xp_shell
&& csh_like_shell() && s
[1] == '\\' && s
[2] == '!')
5545 * Show wildchar matches in the status line.
5546 * Show at least the "match" item.
5547 * We start at item 'first_match' in the list and show all matches that fit.
5549 * If inversion is possible we use it. Else '=' characters are used.
5552 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5555 char_u
**matches
; /* list of matches */
5559 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5563 int clen
; /* length in screen cells */
5567 int highlight
= TRUE
;
5568 char_u
*selstart
= NULL
;
5569 int selstart_col
= 0;
5570 char_u
*selend
= NULL
;
5571 static int first_match
= 0;
5572 int add_left
= FALSE
;
5577 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5581 if (matches
== NULL
) /* interrupted completion? */
5586 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5589 buf
= alloc((unsigned)Columns
+ 1);
5593 if (match
== -1) /* don't show match but original text */
5598 /* count 1 for the ending ">" */
5599 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5602 else if (match
< first_match
)
5604 /* jumping left, as far as we can go */
5605 first_match
= match
;
5610 /* check if match fits on the screen */
5611 for (i
= first_match
; i
< match
; ++i
)
5612 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5613 if (first_match
> 0)
5615 /* jumping right, put match at the left */
5616 if ((long)clen
> Columns
)
5618 first_match
= match
;
5619 /* if showing the last match, we can add some on the left */
5621 for (i
= match
; i
< num_matches
; ++i
)
5623 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5624 if ((long)clen
>= Columns
)
5627 if (i
== num_matches
)
5632 while (first_match
> 0)
5634 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5635 if ((long)clen
>= Columns
)
5640 fillchar
= fillchar_status(&attr
, TRUE
);
5642 if (first_match
== 0)
5655 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5659 selstart
= buf
+ len
;
5660 selstart_col
= clen
;
5664 /* Check for menu separators - replace with '|' */
5666 emenu
= (xp
->xp_context
== EXPAND_MENUS
5667 || xp
->xp_context
== EXPAND_MENUNAMES
);
5668 if (emenu
&& menu_is_separator(s
))
5670 STRCPY(buf
+ len
, transchar('|'));
5671 l
= (int)STRLEN(buf
+ len
);
5677 for ( ; *s
!= NUL
; ++s
)
5679 s
+= skip_status_match_char(xp
, s
);
5680 clen
+= ptr2cells(s
);
5682 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5684 STRNCPY(buf
+ len
, s
, l
);
5691 STRCPY(buf
+ len
, transchar_byte(*s
));
5692 len
+= (int)STRLEN(buf
+ len
);
5698 *(buf
+ len
++) = ' ';
5699 *(buf
+ len
++) = ' ';
5701 if (++i
== num_matches
)
5705 if (i
!= num_matches
)
5707 *(buf
+ len
++) = '>';
5713 row
= cmdline_row
- 1;
5716 if (wild_menu_showing
== 0)
5718 if (msg_scrolled
> 0)
5720 /* Put the wildmenu just above the command line. If there is
5721 * no room, scroll the screen one line up. */
5722 if (cmdline_row
== Rows
- 1)
5724 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5732 wild_menu_showing
= WM_SCROLLED
;
5736 /* Create status line if needed by setting 'laststatus' to 2.
5737 * Set 'winminheight' to zero to avoid that the window is
5739 if (lastwin
->w_status_height
== 0)
5747 wild_menu_showing
= WM_SHOWN
;
5751 screen_puts(buf
, row
, 0, attr
);
5752 if (selstart
!= NULL
&& highlight
)
5755 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5758 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5761 #ifdef FEAT_VERTSPLIT
5762 win_redraw_last_status(topframe
);
5764 lastwin
->w_redr_status
= TRUE
;
5770 #if defined(FEAT_WINDOWS) || defined(PROTO)
5772 * Redraw the status line of window wp.
5774 * If inversion is possible we use it. Else '=' characters are used.
5786 static int busy
= FALSE
;
5788 /* It's possible to get here recursively when 'statusline' (indirectly)
5789 * invokes ":redrawstatus". Simply ignore the call then. */
5794 wp
->w_redr_status
= FALSE
;
5795 if (wp
->w_status_height
== 0)
5797 /* no status line, can only be last window */
5798 redraw_cmdline
= TRUE
;
5800 else if (!redrawing()
5801 #ifdef FEAT_INS_EXPAND
5802 /* don't update status line when popup menu is visible and may be
5808 /* Don't redraw right now, do it later. */
5809 wp
->w_redr_status
= TRUE
;
5812 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5814 /* redraw custom status line */
5815 redraw_custom_statusline(wp
);
5820 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5822 get_trans_bufname(wp
->w_buffer
);
5824 len
= (int)STRLEN(p
);
5826 if (wp
->w_buffer
->b_help
5827 #ifdef FEAT_QUICKFIX
5830 || bufIsChanged(wp
->w_buffer
)
5831 || wp
->w_buffer
->b_p_ro
)
5833 if (wp
->w_buffer
->b_help
)
5835 STRCPY(p
+ len
, _("[Help]"));
5836 len
+= (int)STRLEN(p
+ len
);
5838 #ifdef FEAT_QUICKFIX
5841 STRCPY(p
+ len
, _("[Preview]"));
5842 len
+= (int)STRLEN(p
+ len
);
5845 if (bufIsChanged(wp
->w_buffer
))
5847 STRCPY(p
+ len
, "[+]");
5850 if (wp
->w_buffer
->b_p_ro
)
5852 STRCPY(p
+ len
, "[RO]");
5856 #ifndef FEAT_VERTSPLIT
5857 this_ru_col
= ru_col
;
5858 if (this_ru_col
< (Columns
+ 1) / 2)
5859 this_ru_col
= (Columns
+ 1) / 2;
5861 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5862 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5863 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5864 if (this_ru_col
<= 1)
5866 p
= (char_u
*)"<"; /* No room for file name! */
5876 /* Count total number of display cells. */
5877 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5878 clen
+= (*mb_ptr2cells
)(p
+ i
);
5879 /* Find first character that will fit.
5880 * Going from start to end is much faster for DBCS. */
5881 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5882 i
+= (*mb_ptr2len
)(p
+ i
))
5883 clen
-= (*mb_ptr2cells
)(p
+ i
);
5895 if (len
> this_ru_col
- 1)
5897 p
+= len
- (this_ru_col
- 1);
5899 len
= this_ru_col
- 1;
5902 row
= W_WINROW(wp
) + wp
->w_height
;
5903 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5904 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5905 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5907 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5908 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5909 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5910 - 1 + W_WINCOL(wp
)), attr
);
5912 #ifdef FEAT_CMDL_INFO
5913 win_redr_ruler(wp
, TRUE
);
5917 #ifdef FEAT_VERTSPLIT
5919 * May need to draw the character below the vertical separator.
5921 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5923 if (stl_connected(wp
))
5924 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5926 fillchar
= fillchar_vsep(&attr
);
5927 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5936 * Redraw the status line according to 'statusline' and take care of any
5937 * errors encountered.
5940 redraw_custom_statusline(wp
)
5943 static int entered
= FALSE
;
5944 int save_called_emsg
= called_emsg
;
5946 /* When called recursively return. This can happen when the statusline
5947 * contains an expression that triggers a redraw. */
5952 called_emsg
= FALSE
;
5953 win_redr_custom(wp
, FALSE
);
5956 /* When there is an error disable the statusline, otherwise the
5957 * display is messed up with errors and a redraw triggers the problem
5958 * again and again. */
5959 set_string_option_direct((char_u
*)"statusline", -1,
5960 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5961 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5963 called_emsg
|= save_called_emsg
;
5968 # ifdef FEAT_VERTSPLIT
5970 * Return TRUE if the status line of window "wp" is connected to the status
5971 * line of the window right of it. If not, then it's a vertical separator.
5972 * Only call if (wp->w_vsep_width != 0).
5981 while (fr
->fr_parent
!= NULL
)
5983 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5985 if (fr
->fr_next
!= NULL
)
5990 if (fr
->fr_next
!= NULL
)
5999 #endif /* FEAT_WINDOWS */
6001 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
6003 * Get the value to show for the language mappings, active 'keymap'.
6006 get_keymap_str(wp
, buf
, len
)
6008 char_u
*buf
; /* buffer for the result */
6009 int len
; /* length of buffer */
6013 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
6018 buf_T
*old_curbuf
= curbuf
;
6019 win_T
*old_curwin
= curwin
;
6022 curbuf
= wp
->w_buffer
;
6024 STRCPY(buf
, "b:keymap_name"); /* must be writable */
6026 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
6028 curbuf
= old_curbuf
;
6029 curwin
= old_curwin
;
6030 if (p
== NULL
|| *p
== NUL
)
6034 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
6035 p
= wp
->w_buffer
->b_p_keymap
;
6038 p
= (char_u
*)"lang";
6040 if ((int)(STRLEN(p
) + 3) < len
)
6041 sprintf((char *)buf
, "<%s>", p
);
6048 return buf
[0] != NUL
;
6052 #if defined(FEAT_STL_OPT) || defined(PROTO)
6054 * Redraw the status line or ruler of window "wp".
6055 * When "wp" is NULL redraw the tab pages line from 'tabline'.
6058 win_redr_custom(wp
, draw_ruler
)
6060 int draw_ruler
; /* TRUE or FALSE */
6071 char_u buf
[MAXPATHL
];
6074 struct stl_hlrec hltab
[STL_MAX_ITEM
];
6075 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
6076 int use_sandbox
= FALSE
;
6078 /* setup environment for the task at hand */
6081 /* Use 'tabline'. Always at the first line of the screen. */
6085 attr
= hl_attr(HLF_TPF
);
6088 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
6093 row
= W_WINROW(wp
) + wp
->w_height
;
6094 fillchar
= fillchar_status(&attr
, wp
== curwin
);
6095 maxwidth
= W_WIDTH(wp
);
6100 /* advance past any leading group spec - implicit in ru_col */
6105 if (atoi((char *)stl
))
6106 while (VIM_ISDIGIT(*stl
))
6111 #ifdef FEAT_VERTSPLIT
6112 col
= ru_col
- (Columns
- W_WIDTH(wp
));
6113 if (col
< (W_WIDTH(wp
) + 1) / 2)
6114 col
= (W_WIDTH(wp
) + 1) / 2;
6117 if (col
> (Columns
+ 1) / 2)
6118 col
= (Columns
+ 1) / 2;
6120 maxwidth
= W_WIDTH(wp
) - col
;
6122 if (!wp
->w_status_height
)
6126 --maxwidth
; /* writing in last column may cause scrolling */
6132 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
6137 if (*wp
->w_p_stl
!= NUL
)
6142 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
6143 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
6147 #ifdef FEAT_VERTSPLIT
6148 col
+= W_WINCOL(wp
);
6155 /* Make a copy, because the statusline may include a function call that
6156 * might change the option value and free the memory. */
6157 stl
= vim_strsave(stl
);
6158 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
6161 fillchar
, maxwidth
, hltab
, tabtab
);
6163 len
= (int)STRLEN(buf
);
6165 while (width
< maxwidth
&& len
< (int)sizeof(buf
) - 1)
6168 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
6170 buf
[len
++] = fillchar
;
6177 * Draw each snippet with the specified highlighting.
6181 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
6183 len
= (int)(hltab
[n
].start
- p
);
6184 screen_puts_len(p
, len
, row
, col
, curattr
);
6185 col
+= vim_strnsize(p
, len
);
6188 if (hltab
[n
].userhl
== 0)
6190 else if (hltab
[n
].userhl
< 0)
6191 curattr
= syn_id2attr(-hltab
[n
].userhl
);
6193 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
6194 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
6197 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
6199 screen_puts(p
, row
, col
, curattr
);
6203 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6208 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
6210 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
6212 TabPageIdxs
[col
++] = fillchar
;
6213 p
= tabtab
[n
].start
;
6214 fillchar
= tabtab
[n
].userhl
;
6216 while (col
< Columns
)
6217 TabPageIdxs
[col
++] = fillchar
;
6221 #endif /* FEAT_STL_OPT */
6224 * Output a single character directly to the screen and update ScreenLines.
6227 screen_putchar(c
, row
, col
, attr
)
6233 char_u buf
[MB_MAXBYTES
+ 1];
6235 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6242 screen_puts(buf
, row
, col
, attr
);
6246 * Get a single character directly from ScreenLines into "bytes[]".
6247 * Also return its attribute in *attrp;
6250 screen_getbytes(row
, col
, bytes
, attrp
)
6258 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6260 off
= LineOffset
[row
] + col
;
6261 *attrp
= ScreenAttrs
[off
];
6262 bytes
[0] = ScreenLines
[off
];
6266 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6267 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6268 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6270 bytes
[0] = ScreenLines
[off
];
6271 bytes
[1] = ScreenLines2
[off
];
6274 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6276 bytes
[1] = ScreenLines
[off
+ 1];
6284 static int screen_comp_differs
__ARGS((int, int*));
6287 * Return TRUE if composing characters for screen posn "off" differs from
6288 * composing characters in "u8cc".
6289 * Only to be used when ScreenLinesUC[off] != 0.
6292 screen_comp_differs(off
, u8cc
)
6298 for (i
= 0; i
< Screen_mco
; ++i
)
6300 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6310 * Put string '*text' on the screen at position 'row' and 'col', with
6311 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6312 * Note: only outputs within one row, message is truncated at screen boundary!
6313 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6316 screen_puts(text
, row
, col
, attr
)
6322 screen_puts_len(text
, -1, row
, col
, attr
);
6326 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6330 screen_puts_len(text
, len
, row
, col
, attr
)
6343 int mbyte_cells
= 1;
6346 int clear_next_cell
= FALSE
;
6348 int prev_c
= 0; /* previous Arabic character */
6353 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6354 int force_redraw_this
;
6355 int force_redraw_next
= FALSE
;
6359 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6361 off
= LineOffset
[row
] + col
;
6364 /* When drawing over the right halve of a double-wide char clear out the
6365 * left halve. Only needed in a terminal. */
6366 if (has_mbyte
&& col
> 0 && col
< screen_Columns
6370 && mb_fix_col(col
, row
) != col
)
6372 ScreenLines
[off
- 1] = ' ';
6373 ScreenAttrs
[off
- 1] = 0;
6376 ScreenLinesUC
[off
- 1] = 0;
6377 ScreenLinesC
[0][off
- 1] = 0;
6379 /* redraw the previous cell, make it empty */
6380 screen_char(off
- 1, row
, col
- 1);
6381 /* force the cell at "col" to be redrawn */
6382 force_redraw_next
= TRUE
;
6387 max_off
= LineOffset
[row
] + screen_Columns
;
6389 while (col
< screen_Columns
6390 && (len
< 0 || (int)(ptr
- text
) < len
)
6395 /* check if this is the first byte of a multibyte */
6398 if (enc_utf8
&& len
> 0)
6399 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6401 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6402 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6404 else if (enc_dbcs
!= 0)
6405 mbyte_cells
= mbyte_blen
;
6409 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6410 (int)((text
+ len
) - ptr
));
6412 u8c
= utfc_ptr2char(ptr
, u8cc
);
6413 mbyte_cells
= utf_char2cells(u8c
);
6415 /* Non-BMP character: display as ? or fullwidth ?. */
6418 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6420 attr
= hl_attr(HLF_8
);
6424 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6426 /* Do Arabic shaping. */
6427 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6429 /* Past end of string to be displayed. */
6435 nc
= utfc_ptr2char_len(ptr
+ mbyte_blen
, pcc
,
6436 (int)((text
+ len
) - ptr
- mbyte_blen
));
6441 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6446 if (col
+ mbyte_cells
> screen_Columns
)
6448 /* Only 1 cell left, but character requires 2 cells:
6449 * display a '>' in the last column to avoid wrapping. */
6457 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6458 force_redraw_this
= force_redraw_next
;
6459 force_redraw_next
= FALSE
;
6462 need_redraw
= ScreenLines
[off
] != c
6464 || (mbyte_cells
== 2
6465 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6466 || (enc_dbcs
== DBCS_JPNU
6468 && ScreenLines2
[off
] != ptr
[1])
6470 && (ScreenLinesUC
[off
] !=
6471 (u8char_T
)(c
< 0x80 && u8cc
[0] == 0 ? 0 : u8c
)
6472 || (ScreenLinesUC
[off
] != 0
6473 && screen_comp_differs(off
, u8cc
))))
6475 || ScreenAttrs
[off
] != attr
6479 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6480 || force_redraw_this
6484 #if defined(FEAT_GUI) || defined(UNIX)
6485 /* The bold trick makes a single row of pixels appear in the next
6486 * character. When a bold character is removed, the next
6487 * character should be redrawn too. This happens for our own GUI
6488 * and for some xterms. */
6489 if (need_redraw
&& ScreenLines
[off
] != ' ' && (
6493 # if defined(FEAT_GUI) && defined(UNIX)
6501 int n
= ScreenAttrs
[off
];
6504 n
= syn_attr2attr(n
);
6506 force_redraw_next
= TRUE
;
6510 /* When at the end of the text and overwriting a two-cell
6511 * character with a one-cell character, need to clear the next
6512 * cell. Also when overwriting the left halve of a two-cell char
6513 * with the right halve of a two-cell char. Do this only once
6514 * (mb_off2cells() may return 2 on the right halve). */
6515 if (clear_next_cell
)
6516 clear_next_cell
= FALSE
;
6518 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6519 : ptr
+ mbyte_blen
>= text
+ len
)
6520 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6521 || (mbyte_cells
== 2
6522 && (*mb_off2cells
)(off
, max_off
) == 1
6523 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6524 clear_next_cell
= TRUE
;
6526 /* Make sure we never leave a second byte of a double-byte behind,
6527 * it confuses mb_off2cells(). */
6529 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6530 || (mbyte_cells
== 2
6531 && (*mb_off2cells
)(off
, max_off
) == 1
6532 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6533 ScreenLines
[off
+ mbyte_blen
] = 0;
6535 ScreenLines
[off
] = c
;
6536 ScreenAttrs
[off
] = attr
;
6540 if (c
< 0x80 && u8cc
[0] == 0)
6541 ScreenLinesUC
[off
] = 0;
6546 ScreenLinesUC
[off
] = u8c
;
6547 for (i
= 0; i
< Screen_mco
; ++i
)
6549 ScreenLinesC
[i
][off
] = u8cc
[i
];
6554 if (mbyte_cells
== 2)
6556 ScreenLines
[off
+ 1] = 0;
6557 ScreenAttrs
[off
+ 1] = attr
;
6559 screen_char(off
, row
, col
);
6561 else if (mbyte_cells
== 2)
6563 ScreenLines
[off
+ 1] = ptr
[1];
6564 ScreenAttrs
[off
+ 1] = attr
;
6565 screen_char_2(off
, row
, col
);
6567 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6569 ScreenLines2
[off
] = ptr
[1];
6570 screen_char(off
, row
, col
);
6574 screen_char(off
, row
, col
);
6582 if (clear_next_cell
)
6583 ptr
= (char_u
*)" ";
6594 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
6595 /* If we detected the next character needs to be redrawn, but the text
6596 * doesn't extend up to there, update the character here. */
6597 if (force_redraw_next
&& col
< screen_Columns
)
6600 if (enc_dbcs
!= 0 && dbcs_off2cells(off
, max_off
) > 1)
6601 screen_char_2(off
, row
, col
);
6604 screen_char(off
, row
, col
);
6609 #ifdef FEAT_SEARCH_EXTRA
6611 * Prepare for 'hlsearch' highlighting.
6616 if (p_hls
&& !no_hlsearch
)
6618 last_pat_prog(&search_hl
.rm
);
6619 search_hl
.attr
= hl_attr(HLF_L
);
6620 # ifdef FEAT_RELTIME
6621 /* Set the time limit to 'redrawtime'. */
6622 profile_setlimit(p_rdt
, &search_hl
.tm
);
6628 * Clean up for 'hlsearch' highlighting.
6633 if (search_hl
.rm
.regprog
!= NULL
)
6635 vim_free(search_hl
.rm
.regprog
);
6636 search_hl
.rm
.regprog
= NULL
;
6641 * Advance to the match in window "wp" line "lnum" or past it.
6644 prepare_search_hl(wp
, lnum
)
6648 matchitem_T
*cur
; /* points to the match list */
6649 match_T
*shl
; /* points to search_hl or a match */
6650 int shl_flag
; /* flag to indicate whether search_hl
6651 has been processed or not */
6655 * When using a multi-line pattern, start searching at the top
6656 * of the window or just after a closed fold.
6657 * Do this both for search_hl and the match list.
6659 cur
= wp
->w_match_head
;
6661 while (cur
!= NULL
|| shl_flag
== FALSE
)
6663 if (shl_flag
== FALSE
)
6670 if (shl
->rm
.regprog
!= NULL
6672 && re_multiline(shl
->rm
.regprog
))
6674 if (shl
->first_lnum
== 0)
6676 # ifdef FEAT_FOLDING
6677 for (shl
->first_lnum
= lnum
;
6678 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6679 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6680 NULL
, NULL
, TRUE
, NULL
))
6683 shl
->first_lnum
= wp
->w_topline
;
6687 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6689 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6692 shl
->first_lnum
= shl
->lnum
6693 + shl
->rm
.endpos
[0].lnum
6694 - shl
->rm
.startpos
[0].lnum
;
6695 n
= shl
->rm
.endpos
[0].col
;
6704 if (shl
!= &search_hl
&& cur
!= NULL
)
6710 * Search for a next 'hlsearch' or match.
6712 * Sets shl->lnum and shl->rm contents.
6713 * Note: Assumes a previous match is always before "lnum", unless
6714 * shl->lnum is zero.
6715 * Careful: Any pointers for buffer lines will become invalid.
6718 next_search_hl(win
, shl
, lnum
, mincol
)
6720 match_T
*shl
; /* points to search_hl or a match */
6722 colnr_T mincol
; /* minimal column for a match */
6730 /* Check for three situations:
6731 * 1. If the "lnum" is below a previous match, start a new search.
6732 * 2. If the previous match includes "mincol", use it.
6733 * 3. Continue after the previous match.
6735 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6738 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6743 * Repeat searching for a match until one is found that includes "mincol"
6744 * or none is found in this line.
6746 called_emsg
= FALSE
;
6750 /* Stop searching after passing the time limit. */
6751 if (profile_passed_limit(&(shl
->tm
)))
6753 shl
->lnum
= 0; /* no match found in time */
6757 /* Three situations:
6758 * 1. No useful previous match: search from start of line.
6759 * 2. Not Vi compatible or empty match: continue at next character.
6760 * Break the loop if this is beyond the end of the line.
6761 * 3. Vi compatible searching: continue at end of previous match.
6765 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6766 || (shl
->rm
.endpos
[0].lnum
== 0
6767 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6771 matchcol
= shl
->rm
.startpos
[0].col
;
6772 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6781 matchcol
+= mb_ptr2len(ml
);
6787 matchcol
= shl
->rm
.endpos
[0].col
;
6790 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
,
6799 /* Error while handling regexp: stop using this regexp. */
6800 if (shl
== &search_hl
)
6802 /* don't free regprog in the match list, it's a copy */
6803 vim_free(shl
->rm
.regprog
);
6806 shl
->rm
.regprog
= NULL
;
6808 got_int
= FALSE
; /* avoid the "Type :quit to exit Vim" message */
6813 shl
->lnum
= 0; /* no match found */
6816 if (shl
->rm
.startpos
[0].lnum
> 0
6817 || shl
->rm
.startpos
[0].col
>= mincol
6819 || shl
->rm
.endpos
[0].col
> mincol
)
6821 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6822 break; /* useful match found */
6829 screen_start_highlight(attr
)
6832 attrentry_T
*aep
= NULL
;
6846 /* The GUI handles this internally. */
6847 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6853 if (attr
> HL_ALL
) /* special HL attr. */
6856 aep
= syn_cterm_attr2entry(attr
);
6858 aep
= syn_term_attr2entry(attr
);
6859 if (aep
== NULL
) /* did ":syntax clear" */
6862 attr
= aep
->ae_attr
;
6864 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6866 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6867 && cterm_normal_fg_bold
)
6868 /* If the Normal FG color has BOLD attribute and the new HL
6869 * has a FG color defined, clear BOLD. */
6871 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6873 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6874 /* underline or undercurl */
6876 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6878 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6882 * Output the color or start string after bold etc., in case the
6883 * bold etc. override the color setting.
6889 if (aep
->ae_u
.cterm
.fg_color
)
6890 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6891 if (aep
->ae_u
.cterm
.bg_color
)
6892 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6896 if (aep
->ae_u
.term
.start
!= NULL
)
6897 out_str(aep
->ae_u
.term
.start
);
6905 screen_stop_highlight()
6907 int do_ME
= FALSE
; /* output T_ME code */
6909 if (screen_attr
!= 0
6920 /* use internal GUI code */
6921 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6927 if (screen_attr
> HL_ALL
) /* special HL attr. */
6934 * Assume that t_me restores the original colors!
6936 aep
= syn_cterm_attr2entry(screen_attr
);
6937 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6938 || aep
->ae_u
.cterm
.bg_color
))
6943 aep
= syn_term_attr2entry(screen_attr
);
6944 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6946 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6949 out_str(aep
->ae_u
.term
.stop
);
6952 if (aep
== NULL
) /* did ":syntax clear" */
6955 screen_attr
= aep
->ae_attr
;
6959 * Often all ending-codes are equal to T_ME. Avoid outputting the
6960 * same sequence several times.
6962 if (screen_attr
& HL_STANDOUT
)
6964 if (STRCMP(T_SE
, T_ME
) == 0)
6969 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6971 if (STRCMP(T_UE
, T_ME
) == 0)
6976 if (screen_attr
& HL_ITALIC
)
6978 if (STRCMP(T_CZR
, T_ME
) == 0)
6983 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6988 /* set Normal cterm colors */
6989 if (cterm_normal_fg_color
!= 0)
6990 term_fg_color(cterm_normal_fg_color
- 1);
6991 if (cterm_normal_bg_color
!= 0)
6992 term_bg_color(cterm_normal_bg_color
- 1);
6993 if (cterm_normal_fg_bold
)
7002 * Reset the colors for a cterm. Used when leaving Vim.
7003 * The machine specific code may override this again.
7006 reset_cterm_colors()
7010 /* set Normal cterm colors */
7011 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
7016 if (cterm_normal_fg_bold
)
7025 * Put character ScreenLines["off"] on the screen at position "row" and "col",
7026 * using the attributes from ScreenAttrs["off"].
7029 screen_char(off
, row
, col
)
7036 /* Check for illegal values, just in case (could happen just after
7038 if (row
>= screen_Rows
|| col
>= screen_Columns
)
7041 /* Outputting the last character on the screen may scrollup the screen.
7042 * Don't to it! Mark the character invalid (update it when scrolled up) */
7043 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
7044 #ifdef FEAT_RIGHTLEFT
7045 /* account for first command-line character in rightleft mode */
7050 ScreenAttrs
[off
] = (sattr_T
)-1;
7055 * Stop highlighting first, so it's easier to move the cursor.
7057 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
7058 if (screen_char_attr
!= 0)
7059 attr
= screen_char_attr
;
7062 attr
= ScreenAttrs
[off
];
7063 if (screen_attr
!= attr
)
7064 screen_stop_highlight();
7068 if (screen_attr
!= attr
)
7069 screen_start_highlight(attr
);
7072 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
7074 char_u buf
[MB_MAXBYTES
+ 1];
7076 /* Convert UTF-8 character to bytes and write it. */
7078 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
7081 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
7090 out_char(ScreenLines
[off
]);
7092 /* double-byte character in single-width cell */
7093 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
7094 out_char(ScreenLines2
[off
]);
7104 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
7105 * on the screen at position 'row' and 'col'.
7106 * The attributes of the first byte is used for all. This is required to
7107 * output the two bytes of a double-byte character with nothing in between.
7110 screen_char_2(off
, row
, col
)
7115 /* Check for illegal values (could be wrong when screen was resized). */
7116 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
7119 /* Outputting the last character on the screen may scrollup the screen.
7120 * Don't to it! Mark the character invalid (update it when scrolled up) */
7121 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
7123 ScreenAttrs
[off
] = (sattr_T
)-1;
7127 /* Output the first byte normally (positions the cursor), then write the
7128 * second byte directly. */
7129 screen_char(off
, row
, col
);
7130 out_char(ScreenLines
[off
+ 1]);
7135 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
7137 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
7138 * This uses the contents of ScreenLines[] and doesn't change it.
7141 screen_draw_rectangle(row
, col
, height
, width
, invert
)
7154 /* Can't use ScreenLines unless initialized */
7155 if (ScreenLines
== NULL
)
7159 screen_char_attr
= HL_INVERSE
;
7160 for (r
= row
; r
< row
+ height
; ++r
)
7162 off
= LineOffset
[r
];
7164 max_off
= off
+ screen_Columns
;
7166 for (c
= col
; c
< col
+ width
; ++c
)
7169 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
, max_off
) > 1)
7171 screen_char_2(off
+ c
, r
, c
);
7177 screen_char(off
+ c
, r
, c
);
7179 if (utf_off2cells(off
+ c
, max_off
) > 1)
7185 screen_char_attr
= 0;
7189 #ifdef FEAT_VERTSPLIT
7191 * Redraw the characters for a vertically split window.
7194 redraw_block(row
, end
, wp
)
7202 # ifdef FEAT_CLIPBOARD
7203 clip_may_clear_selection(row
, end
- 1);
7214 width
= wp
->w_width
;
7216 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
7221 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7222 * with character 'c1' in first column followed by 'c2' in the other columns.
7223 * Use attributes 'attr'.
7226 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
7227 int start_row
, end_row
;
7228 int start_col
, end_col
;
7239 #if defined(FEAT_GUI) || defined(UNIX)
7240 int force_next
= FALSE
;
7243 if (end_row
> screen_Rows
) /* safety check */
7244 end_row
= screen_Rows
;
7245 if (end_col
> screen_Columns
) /* safety check */
7246 end_col
= screen_Columns
;
7247 if (ScreenLines
== NULL
7248 || start_row
>= end_row
7249 || start_col
>= end_col
) /* nothing to do */
7252 /* it's a "normal" terminal when not in a GUI or cterm */
7258 for (row
= start_row
; row
< end_row
; ++row
)
7267 /* When drawing over the right halve of a double-wide char clear
7268 * out the left halve. When drawing over the left halve of a
7269 * double wide-char clear out the right halve. Only needed in a
7271 if (start_col
> 0 && mb_fix_col(start_col
, row
) != start_col
)
7272 screen_puts_len((char_u
*)" ", 1, row
, start_col
- 1, 0);
7273 if (end_col
< screen_Columns
&& mb_fix_col(end_col
, row
) != end_col
)
7274 screen_puts_len((char_u
*)" ", 1, row
, end_col
, 0);
7278 * Try to use delete-line termcap code, when no attributes or in a
7279 * "normal" terminal, where a bold/italic space is just a
7284 && end_col
== Columns
7289 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
7292 * check if we really need to clear something
7295 if (c1
!= ' ') /* don't clear first char */
7298 off
= LineOffset
[row
] + col
;
7299 end_off
= LineOffset
[row
] + end_col
;
7301 /* skip blanks (used often, keep it fast!) */
7304 while (off
< end_off
&& ScreenLines
[off
] == ' '
7305 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
7309 while (off
< end_off
&& ScreenLines
[off
] == ' '
7310 && ScreenAttrs
[off
] == 0)
7312 if (off
< end_off
) /* something to be cleared */
7314 col
= off
- LineOffset
[row
];
7315 screen_stop_highlight();
7316 term_windgoto(row
, col
);/* clear rest of this screen line */
7318 screen_start(); /* don't know where cursor is now */
7319 col
= end_col
- col
;
7320 while (col
--) /* clear chars in ScreenLines */
7322 ScreenLines
[off
] = ' ';
7325 ScreenLinesUC
[off
] = 0;
7327 ScreenAttrs
[off
] = 0;
7331 did_delete
= TRUE
; /* the chars are cleared now */
7334 off
= LineOffset
[row
] + start_col
;
7336 for (col
= start_col
; col
< end_col
; ++col
)
7338 if (ScreenLines
[off
] != c
7340 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
7341 != (c
>= 0x80 ? c
: 0))
7343 || ScreenAttrs
[off
] != attr
7344 #if defined(FEAT_GUI) || defined(UNIX)
7349 #if defined(FEAT_GUI) || defined(UNIX)
7350 /* The bold trick may make a single row of pixels appear in
7351 * the next character. When a bold character is removed, the
7352 * next character should be redrawn too. This happens for our
7353 * own GUI and for some xterms. */
7358 # if defined(FEAT_GUI) && defined(UNIX)
7366 if (ScreenLines
[off
] != ' '
7367 && (ScreenAttrs
[off
] > HL_ALL
7368 || ScreenAttrs
[off
] & HL_BOLD
))
7374 ScreenLines
[off
] = c
;
7380 ScreenLinesUC
[off
] = c
;
7381 ScreenLinesC
[0][off
] = 0;
7384 ScreenLinesUC
[off
] = 0;
7387 ScreenAttrs
[off
] = attr
;
7388 if (!did_delete
|| c
!= ' ')
7389 screen_char(off
, row
, col
);
7392 if (col
== start_col
)
7399 if (end_col
== Columns
)
7400 LineWraps
[row
] = FALSE
;
7401 if (row
== Rows
- 1) /* overwritten the command line */
7403 redraw_cmdline
= TRUE
;
7404 if (c1
== ' ' && c2
== ' ')
7405 clear_cmdline
= FALSE
; /* command line has been cleared */
7407 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7413 * Check if there should be a delay. Used before clearing or redrawing the
7414 * screen or the command line.
7417 check_for_delay(check_msg_scroll
)
7418 int check_msg_scroll
;
7420 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7422 && emsg_silent
== 0)
7425 ui_delay(1000L, TRUE
);
7426 emsg_on_display
= FALSE
;
7427 if (check_msg_scroll
)
7433 * screen_valid - allocate screen buffers if size changed
7434 * If "clear" is TRUE: clear screen if it has been resized.
7435 * Returns TRUE if there is a valid screen to write to.
7436 * Returns FALSE when starting up and screen not initialized yet.
7442 screenalloc(clear
); /* allocate screen buffers if size changed */
7443 return (ScreenLines
!= NULL
);
7447 * Resize the shell to Rows and Columns.
7448 * Allocate ScreenLines[] and associated items.
7450 * There may be some time between setting Rows and Columns and (re)allocating
7451 * ScreenLines[]. This happens when starting up and when (manually) changing
7452 * the shell size. Always use screen_Rows and screen_Columns to access items
7453 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7454 * final size of the shell is needed.
7460 int new_row
, old_row
;
7465 int outofmem
= FALSE
;
7467 schar_T
*new_ScreenLines
;
7469 u8char_T
*new_ScreenLinesUC
= NULL
;
7470 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7471 schar_T
*new_ScreenLines2
= NULL
;
7474 sattr_T
*new_ScreenAttrs
;
7475 unsigned *new_LineOffset
;
7476 char_u
*new_LineWraps
;
7478 short *new_TabPageIdxs
;
7481 static int entered
= FALSE
; /* avoid recursiveness */
7482 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7484 int retry_count
= 0;
7489 * Allocation of the screen buffers is done only when the size changes and
7490 * when Rows and Columns have been set and we have started doing full
7493 if ((ScreenLines
!= NULL
7494 && Rows
== screen_Rows
7495 && Columns
== screen_Columns
7497 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7498 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7499 && p_mco
== Screen_mco
7504 || (!full_screen
&& ScreenLines
== NULL
))
7508 * It's possible that we produce an out-of-memory message below, which
7509 * will cause this function to be called again. To break the loop, just
7517 * Note that the window sizes are updated before reallocating the arrays,
7518 * thus we must not redraw here!
7520 ++RedrawingDisabled
;
7522 win_new_shellsize(); /* fit the windows in the new sized shell */
7524 comp_col(); /* recompute columns for shown command and ruler */
7527 * We're changing the size of the screen.
7528 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7529 * - Move lines from the old arrays into the new arrays, clear extra
7530 * lines (unless the screen is going to be cleared).
7531 * - Free the old arrays.
7533 * If anything fails, make ScreenLines NULL, so we don't do anything!
7534 * Continuing with the old ScreenLines may result in a crash, because the
7537 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7540 if (aucmd_win
!= NULL
)
7541 win_free_lsize(aucmd_win
);
7544 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7545 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7547 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
*) * MAX_MCO
);
7550 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7551 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7552 for (i
= 0; i
< p_mco
; ++i
)
7553 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc_clear((long_u
)(
7554 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7556 if (enc_dbcs
== DBCS_JPNU
)
7557 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7558 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7560 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7561 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7562 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7563 Rows
* sizeof(unsigned)), FALSE
);
7564 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7566 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7569 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7571 if (win_alloc_lines(wp
) == FAIL
)
7580 if (aucmd_win
!= NULL
&& aucmd_win
->w_lines
== NULL
7581 && win_alloc_lines(aucmd_win
) == FAIL
)
7589 for (i
= 0; i
< p_mco
; ++i
)
7590 if (new_ScreenLinesC
[i
] == NULL
)
7593 if (new_ScreenLines
== NULL
7595 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7596 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7598 || new_ScreenAttrs
== NULL
7599 || new_LineOffset
== NULL
7600 || new_LineWraps
== NULL
7602 || new_TabPageIdxs
== NULL
7606 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7608 /* guess the size */
7609 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7611 /* Remember we did this to avoid getting outofmem messages over
7612 * and over again. */
7613 done_outofmem_msg
= TRUE
;
7615 vim_free(new_ScreenLines
);
7616 new_ScreenLines
= NULL
;
7618 vim_free(new_ScreenLinesUC
);
7619 new_ScreenLinesUC
= NULL
;
7620 for (i
= 0; i
< p_mco
; ++i
)
7622 vim_free(new_ScreenLinesC
[i
]);
7623 new_ScreenLinesC
[i
] = NULL
;
7625 vim_free(new_ScreenLines2
);
7626 new_ScreenLines2
= NULL
;
7628 vim_free(new_ScreenAttrs
);
7629 new_ScreenAttrs
= NULL
;
7630 vim_free(new_LineOffset
);
7631 new_LineOffset
= NULL
;
7632 vim_free(new_LineWraps
);
7633 new_LineWraps
= NULL
;
7635 vim_free(new_TabPageIdxs
);
7636 new_TabPageIdxs
= NULL
;
7641 done_outofmem_msg
= FALSE
;
7643 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7645 new_LineOffset
[new_row
] = new_row
* Columns
;
7646 new_LineWraps
[new_row
] = FALSE
;
7649 * If the screen is not going to be cleared, copy as much as
7650 * possible from the old screen to the new one and clear the rest
7651 * (used when resizing the window at the "--more--" prompt or when
7652 * executing an external command, for the GUI).
7656 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7657 ' ', (size_t)Columns
* sizeof(schar_T
));
7661 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7662 0, (size_t)Columns
* sizeof(u8char_T
));
7663 for (i
= 0; i
< p_mco
; ++i
)
7664 (void)vim_memset(new_ScreenLinesC
[i
]
7665 + new_row
* Columns
,
7666 0, (size_t)Columns
* sizeof(u8char_T
));
7668 if (enc_dbcs
== DBCS_JPNU
)
7669 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7670 0, (size_t)Columns
* sizeof(schar_T
));
7672 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7673 0, (size_t)Columns
* sizeof(sattr_T
));
7674 old_row
= new_row
+ (screen_Rows
- Rows
);
7675 if (old_row
>= 0 && ScreenLines
!= NULL
)
7677 if (screen_Columns
< Columns
)
7678 len
= screen_Columns
;
7682 /* When switching to utf-8 don't copy characters, they
7683 * may be invalid now. Also when p_mco changes. */
7684 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7685 && p_mco
== Screen_mco
)
7687 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7688 ScreenLines
+ LineOffset
[old_row
],
7689 (size_t)len
* sizeof(schar_T
));
7691 if (enc_utf8
&& ScreenLinesUC
!= NULL
7692 && p_mco
== Screen_mco
)
7694 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7695 ScreenLinesUC
+ LineOffset
[old_row
],
7696 (size_t)len
* sizeof(u8char_T
));
7697 for (i
= 0; i
< p_mco
; ++i
)
7698 mch_memmove(new_ScreenLinesC
[i
]
7699 + new_LineOffset
[new_row
],
7700 ScreenLinesC
[i
] + LineOffset
[old_row
],
7701 (size_t)len
* sizeof(u8char_T
));
7703 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7704 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7705 ScreenLines2
+ LineOffset
[old_row
],
7706 (size_t)len
* sizeof(schar_T
));
7708 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7709 ScreenAttrs
+ LineOffset
[old_row
],
7710 (size_t)len
* sizeof(sattr_T
));
7714 /* Use the last line of the screen for the current line. */
7715 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7720 ScreenLines
= new_ScreenLines
;
7722 ScreenLinesUC
= new_ScreenLinesUC
;
7723 for (i
= 0; i
< p_mco
; ++i
)
7724 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7726 ScreenLines2
= new_ScreenLines2
;
7728 ScreenAttrs
= new_ScreenAttrs
;
7729 LineOffset
= new_LineOffset
;
7730 LineWraps
= new_LineWraps
;
7732 TabPageIdxs
= new_TabPageIdxs
;
7735 /* It's important that screen_Rows and screen_Columns reflect the actual
7736 * size of ScreenLines[]. Set them before calling anything. */
7738 old_Rows
= screen_Rows
;
7741 screen_Columns
= Columns
;
7743 must_redraw
= CLEAR
; /* need to clear the screen later */
7750 && ScreenLines
!= NULL
7751 && old_Rows
!= Rows
)
7753 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7755 * Adjust the position of the cursor, for when executing an external
7758 if (msg_row
>= Rows
) /* Rows got smaller */
7759 msg_row
= Rows
- 1; /* put cursor at last row */
7760 else if (Rows
> old_Rows
) /* Rows got bigger */
7761 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7762 if (msg_col
>= Columns
) /* Columns got smaller */
7763 msg_col
= Columns
- 1; /* put cursor at last column */
7768 --RedrawingDisabled
;
7772 * Do not apply autocommands more than 3 times to avoid an endless loop
7773 * in case applying autocommands always changes Rows or Columns.
7775 if (starting
== 0 && ++retry_count
<= 3)
7777 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7778 /* In rare cases, autocommands may have altered Rows or Columns,
7779 * jump back to check if we need to allocate the screen again. */
7791 vim_free(ScreenLinesUC
);
7792 for (i
= 0; i
< Screen_mco
; ++i
)
7793 vim_free(ScreenLinesC
[i
]);
7794 vim_free(ScreenLines2
);
7796 vim_free(ScreenLines
);
7797 vim_free(ScreenAttrs
);
7798 vim_free(LineOffset
);
7799 vim_free(LineWraps
);
7801 vim_free(TabPageIdxs
);
7808 check_for_delay(FALSE
);
7809 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7810 screenclear2(); /* clear the screen */
7818 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7820 || (gui
.in_use
&& gui
.starting
)
7828 screen_attr
= -1; /* force setting the Normal colors */
7829 screen_stop_highlight(); /* don't want highlighting here */
7831 #ifdef FEAT_CLIPBOARD
7832 /* disable selection without redrawing it */
7833 clip_scroll_selection(9999);
7836 /* blank out ScreenLines */
7837 for (i
= 0; i
< Rows
; ++i
)
7839 lineclear(LineOffset
[i
], (int)Columns
);
7840 LineWraps
[i
] = FALSE
;
7843 if (can_clear(T_CL
))
7845 out_str(T_CL
); /* clear the display */
7846 clear_cmdline
= FALSE
;
7847 mode_displayed
= FALSE
;
7851 /* can't clear the screen, mark all chars with invalid attributes */
7852 for (i
= 0; i
< Rows
; ++i
)
7853 lineinvalid(LineOffset
[i
], (int)Columns
);
7854 clear_cmdline
= TRUE
;
7857 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7859 win_rest_invalid(firstwin
);
7860 redraw_cmdline
= TRUE
;
7862 redraw_tabline
= TRUE
;
7864 if (must_redraw
== CLEAR
) /* no need to clear again */
7865 must_redraw
= NOT_VALID
;
7867 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7869 screen_start(); /* don't know where cursor is now */
7870 msg_scrolled
= 0; /* can't scroll back */
7876 * Clear one line in ScreenLines.
7879 lineclear(off
, width
)
7883 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7886 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7887 (size_t)width
* sizeof(u8char_T
));
7889 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7893 * Mark one line in ScreenLines invalid by setting the attributes to an
7897 lineinvalid(off
, width
)
7901 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7904 #ifdef FEAT_VERTSPLIT
7906 * Copy part of a Screenline for vertically split window "wp".
7909 linecopy(to
, from
, wp
)
7914 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7915 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7917 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7918 wp
->w_width
* sizeof(schar_T
));
7924 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7925 wp
->w_width
* sizeof(u8char_T
));
7926 for (i
= 0; i
< p_mco
; ++i
)
7927 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7928 wp
->w_width
* sizeof(u8char_T
));
7930 if (enc_dbcs
== DBCS_JPNU
)
7931 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7932 wp
->w_width
* sizeof(schar_T
));
7934 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7935 wp
->w_width
* sizeof(sattr_T
));
7940 * Return TRUE if clearing with term string "p" would work.
7941 * It can't work when the string is empty or it won't set the right background.
7947 return (*p
!= NUL
&& (t_colors
<= 1
7951 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7955 * Reset cursor position. Use whenever cursor was moved because of outputting
7956 * something directly to the screen (shell commands) or a terminal control
7962 screen_cur_row
= screen_cur_col
= 9999;
7966 * Move the cursor to position "row","col" in the screen.
7967 * This tries to find the most efficient way to move, minimizing the number of
7968 * characters sent to the terminal.
7985 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
7986 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7991 #define PLAN_WRITE 4
7992 /* Can't use ScreenLines unless initialized */
7993 if (ScreenLines
== NULL
)
7996 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7998 /* Check for valid position. */
7999 if (row
< 0) /* window without text lines? */
8001 if (row
>= screen_Rows
)
8002 row
= screen_Rows
- 1;
8003 if (col
>= screen_Columns
)
8004 col
= screen_Columns
- 1;
8006 /* check if no cursor movement is allowed in highlight mode */
8007 if (screen_attr
&& *T_MS
== NUL
)
8008 noinvcurs
= HIGHL_COST
;
8011 goto_cost
= GOTO_COST
+ noinvcurs
;
8014 * Plan how to do the positioning:
8015 * 1. Use CR to move it to column 0, same row.
8016 * 2. Use T_LE to move it a few columns to the left.
8017 * 3. Use NL to move a few lines down, column 0.
8018 * 4. Move a few columns to the right with T_ND or by writing chars.
8020 * Don't do this if the cursor went beyond the last column, the cursor
8021 * position is unknown then (some terminals wrap, some don't )
8023 * First check if the highlighting attributes allow us to write
8024 * characters to move the cursor to the right.
8026 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
8029 * If the cursor is in the same row, bigger col, we can use CR
8032 bs
= NULL
; /* init for GCC */
8034 if (row
== screen_cur_row
&& col
< screen_cur_col
)
8036 /* "le" is preferred over "bc", because "bc" is obsolete */
8038 bs
= T_LE
; /* "cursor left" */
8040 bs
= T_BC
; /* "backspace character (old) */
8042 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
8045 if (col
+ 1 < cost
) /* using CR is less characters */
8049 cost
= 1; /* CR is just one character */
8056 if (noinvcurs
) /* will stop highlighting */
8064 * If the cursor is above where we want to be, we can use CR LF.
8066 else if (row
> screen_cur_row
)
8070 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
8071 if (noinvcurs
) /* will stop highlighting */
8079 * If the cursor is in the same row, smaller col, just use write.
8084 wouldbe_col
= screen_cur_col
;
8089 * Check if any characters that need to be written have the
8090 * correct attributes. Also avoid UTF-8 characters.
8092 i
= col
- wouldbe_col
;
8095 if (cost
< goto_cost
&& i
> 0)
8098 * Check if the attributes are correct without additionally
8099 * stopping highlighting.
8101 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
8102 while (i
&& *p
++ == attr
)
8107 * Try if it works when highlighting is stopped here.
8112 while (i
&& *p
++ == 0)
8116 cost
= 999; /* different attributes, don't do it */
8121 /* Don't use an UTF-8 char for positioning, it's slow. */
8122 for (i
= wouldbe_col
; i
< col
; ++i
)
8123 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
8133 * We can do it without term_windgoto()!
8135 if (cost
< goto_cost
)
8137 if (plan
== PLAN_LE
)
8140 screen_stop_highlight();
8141 while (screen_cur_col
> col
)
8147 else if (plan
== PLAN_CR
)
8150 screen_stop_highlight();
8154 else if (plan
== PLAN_NL
)
8157 screen_stop_highlight();
8158 while (screen_cur_row
< row
)
8166 i
= col
- screen_cur_col
;
8170 * Use cursor-right if it's one character only. Avoids
8171 * removing a line of pixels from the last bold char, when
8172 * using the bold trick in the GUI.
8174 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
8183 off
= LineOffset
[row
] + screen_cur_col
;
8186 if (ScreenAttrs
[off
] != screen_attr
)
8187 screen_stop_highlight();
8191 out_char(ScreenLines
[off
]);
8193 if (enc_dbcs
== DBCS_JPNU
8194 && ScreenLines
[off
] == 0x8e)
8195 out_char(ScreenLines2
[off
]);
8206 if (cost
>= goto_cost
)
8209 screen_stop_highlight();
8210 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
8212 term_cursor_right(col
- screen_cur_col
);
8214 term_windgoto(row
, col
);
8216 screen_cur_row
= row
;
8217 screen_cur_col
= col
;
8222 * Set cursor to its position in the current window.
8230 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
8231 W_WINCOL(curwin
) + (
8232 #ifdef FEAT_RIGHTLEFT
8233 /* With 'rightleft' set and the cursor on a double-wide
8234 * character, position it on the leftmost column. */
8235 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
8238 && (*mb_ptr2cells
)(ml_get_cursor()) == 2
8239 && vim_isprintc(gchar_cursor())) ? 2 :
8249 * insert 'line_count' lines at 'row' in window 'wp'
8250 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8251 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8253 * Returns FAIL if the lines are not inserted, OK for success.
8256 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
8269 wp
->w_lines_valid
= 0;
8271 if (wp
->w_height
< 5)
8274 if (line_count
> wp
->w_height
- row
)
8275 line_count
= wp
->w_height
- row
;
8277 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
8278 if (retval
!= MAYBE
)
8282 * If there is a next window or a status line, we first try to delete the
8283 * lines at the bottom to avoid messing what is after the window.
8284 * If this fails and there are following windows, don't do anything to avoid
8285 * messing up those windows, better just redraw.
8289 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
8291 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8292 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
8294 else if (wp
->w_next
)
8299 * if no lines deleted, blank the lines that will end up below the window
8304 wp
->w_redr_status
= TRUE
;
8306 redraw_cmdline
= TRUE
;
8307 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
8308 lastrow
= nextrow
+ line_count
;
8311 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
8312 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8316 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
8319 /* deletion will have messed up other windows */
8323 wp
->w_redr_status
= TRUE
;
8325 win_rest_invalid(W_NEXT(wp
));
8334 * delete "line_count" window lines at "row" in window "wp"
8335 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8336 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8338 * Return OK for success, FAIL if the lines are not deleted.
8341 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
8351 wp
->w_lines_valid
= 0;
8353 if (line_count
> wp
->w_height
- row
)
8354 line_count
= wp
->w_height
- row
;
8356 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
8357 if (retval
!= MAYBE
)
8360 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
8361 (int)Rows
, FALSE
, NULL
) == FAIL
)
8366 * If there are windows or status lines below, try to put them at the
8367 * correct place. If we can't do that, they have to be redrawn.
8369 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
8371 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8372 line_count
, (int)Rows
, NULL
) == FAIL
)
8374 wp
->w_redr_status
= TRUE
;
8375 win_rest_invalid(wp
->w_next
);
8379 * If this is the last window and there is no status line, redraw the
8380 * command line later.
8384 redraw_cmdline
= TRUE
;
8389 * Common code for win_ins_lines() and win_del_lines().
8390 * Returns OK or FAIL when the work has been done.
8391 * Returns MAYBE when not finished yet.
8394 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8403 if (!redrawing() || line_count
<= 0)
8406 /* only a few lines left: redraw is faster */
8407 if (mayclear
&& Rows
- line_count
< 5
8408 #ifdef FEAT_VERTSPLIT
8409 && wp
->w_width
== Columns
8413 screenclear(); /* will set wp->w_lines_valid to 0 */
8418 * Delete all remaining lines
8420 if (row
+ line_count
>= wp
->w_height
)
8422 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8423 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8429 * when scrolling, the message on the command line should be cleared,
8430 * otherwise it will stay there forever.
8432 clear_cmdline
= TRUE
;
8435 * If the terminal can set a scroll region, use that.
8436 * Always do this in a vertically split window. This will redraw from
8437 * ScreenLines[] when t_CV isn't defined. That's faster than using
8439 * Don't use a scroll region when we are going to redraw the text, writing
8440 * a character in the lower right corner of the scroll region causes a
8441 * scroll-up in the DJGPP version.
8444 #ifdef FEAT_VERTSPLIT
8445 || W_WIDTH(wp
) != Columns
8449 #ifdef FEAT_VERTSPLIT
8450 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8452 scroll_region_set(wp
, row
);
8454 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8455 wp
->w_height
- row
, FALSE
, wp
);
8457 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8458 wp
->w_height
- row
, wp
);
8459 #ifdef FEAT_VERTSPLIT
8460 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8462 scroll_region_reset();
8467 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8475 * window 'wp' and everything after it is messed up, mark it for redraw
8478 win_rest_invalid(wp
)
8487 redraw_win_later(wp
, NOT_VALID
);
8489 wp
->w_redr_status
= TRUE
;
8493 redraw_cmdline
= TRUE
;
8497 * The rest of the routines in this file perform screen manipulations. The
8498 * given operation is performed physically on the screen. The corresponding
8499 * change is also made to the internal screen image. In this way, the editor
8500 * anticipates the effect of editing changes on the appearance of the screen.
8501 * That way, when we call screenupdate a complete redraw isn't usually
8502 * necessary. Another advantage is that we can keep adding code to anticipate
8503 * screen changes, and in the meantime, everything still works.
8507 * types for inserting or deleting lines
8517 #define USE_REDRAW 9
8520 * insert lines on the screen and update ScreenLines[]
8521 * 'end' is the line after the scrolled part. Normally it is Rows.
8522 * When scrolling region used 'off' is the offset from the top for the region.
8523 * 'row' and 'end' are relative to the start of the region.
8525 * return FAIL for failure, OK for success.
8528 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8533 win_T
*wp
; /* NULL or window to use width from */
8541 int can_ce
= can_clear(T_CE
);
8545 * - there is no valid screen
8546 * - the screen has to be redrawn completely
8547 * - the line count is less than one
8548 * - the line count is more than 'ttyscroll'
8550 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8554 * There are seven ways to insert lines:
8555 * 0. When in a vertically split window and t_CV isn't set, redraw the
8556 * characters from ScreenLines[].
8557 * 1. Use T_CD (clear to end of display) if it exists and the result of
8558 * the insert is just empty lines
8559 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8560 * present or line_count > 1. It looks better if we do all the inserts
8562 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8563 * insert is just empty lines and T_CE is not present or line_count >
8565 * 4. Use T_AL (insert line) if it exists.
8566 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8568 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8570 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8571 * the 'da' flag is not set or we have clear line capability.
8572 * 8. redraw the characters from ScreenLines[].
8574 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8575 * the scrollbar for the window. It does have insert line, use that if it
8578 result_empty
= (row
+ line_count
>= end
);
8579 #ifdef FEAT_VERTSPLIT
8580 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8584 if (can_clear(T_CD
) && result_empty
)
8586 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8588 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8590 else if (*T_AL
!= NUL
)
8592 else if (can_ce
&& result_empty
)
8594 else if (*T_DL
!= NUL
&& result_empty
)
8596 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8602 * For clearing the lines screen_del_lines() is used. This will also take
8603 * care of t_db if necessary.
8605 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8606 type
== USE_T_CE
|| type
== USE_T_DL
)
8607 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8610 * If text is retained below the screen, first clear or delete as many
8611 * lines at the bottom of the window as are about to be inserted so that
8612 * the deleted lines won't later surface during a screen_del_lines.
8615 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8617 #ifdef FEAT_CLIPBOARD
8618 /* Remove a modeless selection when inserting lines halfway the screen
8619 * or not the full width of the screen. */
8621 # ifdef FEAT_VERTSPLIT
8622 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8625 clip_clear_selection();
8627 clip_scroll_selection(-line_count
);
8631 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8632 * scrolling is actually carried out. */
8633 gui_dont_update_cursor();
8636 if (*T_CCS
!= NUL
) /* cursor relative to region */
8639 cursor_row
= row
+ off
;
8642 * Shift LineOffset[] line_count down to reflect the inserted lines.
8643 * Clear the inserted lines in ScreenLines[].
8647 for (i
= 0; i
< line_count
; ++i
)
8649 #ifdef FEAT_VERTSPLIT
8650 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8652 /* need to copy part of a line */
8654 while ((j
-= line_count
) >= row
)
8655 linecopy(j
+ line_count
, j
, wp
);
8657 if (can_clear((char_u
*)" "))
8658 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8660 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8661 LineWraps
[j
] = FALSE
;
8667 temp
= LineOffset
[j
];
8668 while ((j
-= line_count
) >= row
)
8670 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8671 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8673 LineOffset
[j
+ line_count
] = temp
;
8674 LineWraps
[j
+ line_count
] = FALSE
;
8675 if (can_clear((char_u
*)" "))
8676 lineclear(temp
, (int)Columns
);
8678 lineinvalid(temp
, (int)Columns
);
8682 screen_stop_highlight();
8683 windgoto(cursor_row
, 0);
8685 #ifdef FEAT_VERTSPLIT
8686 /* redraw the characters */
8687 if (type
== USE_REDRAW
)
8688 redraw_block(row
, end
, wp
);
8691 if (type
== USE_T_CAL
)
8693 term_append_lines(line_count
);
8694 screen_start(); /* don't know where cursor is now */
8698 for (i
= 0; i
< line_count
; i
++)
8700 if (type
== USE_T_AL
)
8702 if (i
&& cursor_row
!= 0)
8703 windgoto(cursor_row
, 0);
8706 else /* type == USE_T_SR */
8708 screen_start(); /* don't know where cursor is now */
8713 * With scroll-reverse and 'da' flag set we need to clear the lines that
8714 * have been scrolled down into the region.
8716 if (type
== USE_T_SR
&& *T_DA
)
8718 for (i
= 0; i
< line_count
; ++i
)
8720 windgoto(off
+ i
, 0);
8722 screen_start(); /* don't know where cursor is now */
8727 gui_can_update_cursor();
8729 out_flush(); /* always flush after a scroll */
8735 * delete lines on the screen and update ScreenLines[]
8736 * 'end' is the line after the scrolled part. Normally it is Rows.
8737 * When scrolling region used 'off' is the offset from the top for the region.
8738 * 'row' and 'end' are relative to the start of the region.
8740 * Return OK for success, FAIL if the lines are not deleted.
8743 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8748 int force
; /* even when line_count > p_ttyscroll */
8749 win_T
*wp UNUSED
; /* NULL or window to use width from */
8756 int result_empty
; /* result is empty until end of region */
8757 int can_delete
; /* deleting line codes can be used */
8762 * - there is no valid screen
8763 * - the screen has to be redrawn completely
8764 * - the line count is less than one
8765 * - the line count is more than 'ttyscroll'
8767 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8768 (!force
&& line_count
> p_ttyscroll
))
8772 * Check if the rest of the current region will become empty.
8774 result_empty
= row
+ line_count
>= end
;
8777 * We can delete lines only when 'db' flag not set or when 'ce' option
8780 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8783 * There are six ways to delete lines:
8784 * 0. When in a vertically split window and t_CV isn't set, redraw the
8785 * characters from ScreenLines[].
8786 * 1. Use T_CD if it exists and the result is empty.
8787 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8788 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8789 * none of the other ways work.
8790 * 4. Use T_CE (erase line) if the result is empty.
8791 * 5. Use T_DL (delete line) if it exists.
8792 * 6. redraw the characters from ScreenLines[].
8794 #ifdef FEAT_VERTSPLIT
8795 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8799 if (can_clear(T_CD
) && result_empty
)
8801 #if defined(__BEOS__) && defined(BEOS_DR8)
8803 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8804 * its internal termcap... this works okay for tests which test *T_DB !=
8805 * NUL. It has the disadvantage that the user cannot use any :set t_*
8806 * command to get T_DB (back) to empty_option, only :set term=... will do
8808 * Anyway, this hack will hopefully go away with the next OS release.
8811 else if (row
== 0 && T_DB
== empty_option
8812 && (line_count
== 1 || *T_CDL
== NUL
))
8814 else if (row
== 0 && (
8816 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8817 * up, so use delete-line command */
8823 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8825 else if (can_clear(T_CE
) && result_empty
8826 #ifdef FEAT_VERTSPLIT
8827 && (wp
== NULL
|| wp
->w_width
== Columns
)
8831 else if (*T_DL
!= NUL
&& can_delete
)
8833 else if (*T_CDL
!= NUL
&& can_delete
)
8838 #ifdef FEAT_CLIPBOARD
8839 /* Remove a modeless selection when deleting lines halfway the screen or
8840 * not the full width of the screen. */
8842 # ifdef FEAT_VERTSPLIT
8843 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8846 clip_clear_selection();
8848 clip_scroll_selection(line_count
);
8852 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8853 * scrolling is actually carried out. */
8854 gui_dont_update_cursor();
8857 if (*T_CCS
!= NUL
) /* cursor relative to region */
8864 cursor_row
= row
+ off
;
8865 cursor_end
= end
+ off
;
8869 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8870 * Clear the inserted lines in ScreenLines[].
8874 for (i
= 0; i
< line_count
; ++i
)
8876 #ifdef FEAT_VERTSPLIT
8877 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8879 /* need to copy part of a line */
8881 while ((j
+= line_count
) <= end
- 1)
8882 linecopy(j
- line_count
, j
, wp
);
8884 if (can_clear((char_u
*)" "))
8885 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8887 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8888 LineWraps
[j
] = FALSE
;
8893 /* whole width, moving the line pointers is faster */
8895 temp
= LineOffset
[j
];
8896 while ((j
+= line_count
) <= end
- 1)
8898 LineOffset
[j
- line_count
] = LineOffset
[j
];
8899 LineWraps
[j
- line_count
] = LineWraps
[j
];
8901 LineOffset
[j
- line_count
] = temp
;
8902 LineWraps
[j
- line_count
] = FALSE
;
8903 if (can_clear((char_u
*)" "))
8904 lineclear(temp
, (int)Columns
);
8906 lineinvalid(temp
, (int)Columns
);
8910 screen_stop_highlight();
8912 #ifdef FEAT_VERTSPLIT
8913 /* redraw the characters */
8914 if (type
== USE_REDRAW
)
8915 redraw_block(row
, end
, wp
);
8918 if (type
== USE_T_CD
) /* delete the lines */
8920 windgoto(cursor_row
, 0);
8922 screen_start(); /* don't know where cursor is now */
8924 else if (type
== USE_T_CDL
)
8926 windgoto(cursor_row
, 0);
8927 term_delete_lines(line_count
);
8928 screen_start(); /* don't know where cursor is now */
8931 * Deleting lines at top of the screen or scroll region: Just scroll
8932 * the whole screen (scroll region) up by outputting newlines on the
8935 else if (type
== USE_NL
)
8937 windgoto(cursor_end
- 1, 0);
8938 for (i
= line_count
; --i
>= 0; )
8939 out_char('\n'); /* cursor will remain on same line */
8943 for (i
= line_count
; --i
>= 0; )
8945 if (type
== USE_T_DL
)
8947 windgoto(cursor_row
, 0);
8948 out_str(T_DL
); /* delete a line */
8950 else /* type == USE_T_CE */
8952 windgoto(cursor_row
+ i
, 0);
8953 out_str(T_CE
); /* erase a line */
8955 screen_start(); /* don't know where cursor is now */
8960 * If the 'db' flag is set, we need to clear the lines that have been
8961 * scrolled up at the bottom of the region.
8963 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8965 for (i
= line_count
; i
> 0; --i
)
8967 windgoto(cursor_end
- i
, 0);
8968 out_str(T_CE
); /* erase a line */
8969 screen_start(); /* don't know where cursor is now */
8974 gui_can_update_cursor();
8976 out_flush(); /* always flush after a scroll */
8983 * show the current mode and ruler
8985 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8986 * If clear_cmdline is FALSE there may be a message there that needs to be
8987 * cleared only if a mode is shown.
8988 * Return the length of the message (0 if no message).
8998 #ifdef FEAT_INS_EXPAND
9002 do_mode
= ((p_smd
&& msg_silent
== 0)
9003 && ((State
& INSERT
)
9009 if (do_mode
|| Recording
)
9012 * Don't show mode right now, when not redrawing or inside a mapping.
9013 * Call char_avail() only when we are going to show something, because
9014 * it takes a bit of time.
9016 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
9018 redraw_cmdline
= TRUE
; /* show mode later */
9022 nwr_save
= need_wait_return
;
9024 /* wait a bit before overwriting an important message */
9025 check_for_delay(FALSE
);
9027 /* if the cmdline is more than one line high, erase top lines */
9028 need_clear
= clear_cmdline
;
9029 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
9030 msg_clr_cmdline(); /* will reset clear_cmdline */
9032 /* Position on the last line in the window, column 0 */
9035 attr
= hl_attr(HLF_CM
); /* Highlight mode */
9038 MSG_PUTS_ATTR("--", attr
);
9039 #if defined(FEAT_XIM)
9040 # if 0 /* old version, changed by SungHyun Nam July 2008 */
9041 if (xic
!= NULL
&& im_get_status() && !p_imdisable
9042 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
9045 # if defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
9046 preedit_get_status()
9052 # if defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
9053 /* most of the time, it's not XIM being used */
9054 MSG_PUTS_ATTR(" IM", attr
);
9056 MSG_PUTS_ATTR(" XIM", attr
);
9059 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
9062 if (hangul_input_state_get())
9063 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
9066 #ifdef FEAT_INS_EXPAND
9067 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
9069 /* These messages can get long, avoid a wrap in a narrow
9070 * window. Prefer showing edit_submode_extra. */
9071 length
= (Rows
- msg_row
) * Columns
- 3;
9072 if (edit_submode_extra
!= NULL
)
9073 length
-= vim_strsize(edit_submode_extra
);
9076 if (edit_submode_pre
!= NULL
)
9077 length
-= vim_strsize(edit_submode_pre
);
9078 if (length
- vim_strsize(edit_submode
) > 0)
9080 if (edit_submode_pre
!= NULL
)
9081 msg_puts_attr(edit_submode_pre
, attr
);
9082 msg_puts_attr(edit_submode
, attr
);
9084 if (edit_submode_extra
!= NULL
)
9086 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
9087 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
9088 sub_attr
= hl_attr(edit_submode_highl
);
9091 msg_puts_attr(edit_submode_extra
, sub_attr
);
9099 #ifdef FEAT_VREPLACE
9100 if (State
& VREPLACE_FLAG
)
9101 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
9104 if (State
& REPLACE_FLAG
)
9105 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
9106 else if (State
& INSERT
)
9108 #ifdef FEAT_RIGHTLEFT
9110 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
9112 MSG_PUTS_ATTR(_(" INSERT"), attr
);
9114 else if (restart_edit
== 'I')
9115 MSG_PUTS_ATTR(_(" (insert)"), attr
);
9116 else if (restart_edit
== 'R')
9117 MSG_PUTS_ATTR(_(" (replace)"), attr
);
9118 else if (restart_edit
== 'V')
9119 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
9120 #ifdef FEAT_RIGHTLEFT
9122 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
9125 MSG_PUTS_ATTR(farsi_text_5
, attr
);
9129 if (State
& LANGMAP
)
9132 if (curwin
->w_p_arab
)
9133 MSG_PUTS_ATTR(_(" Arabic"), attr
);
9136 MSG_PUTS_ATTR(_(" (lang)"), attr
);
9139 if ((State
& INSERT
) && p_paste
)
9140 MSG_PUTS_ATTR(_(" (paste)"), attr
);
9147 /* Don't concatenate separate words to avoid translation
9149 switch ((VIsual_select
? 4 : 0)
9150 + (VIsual_mode
== Ctrl_V
) * 2
9151 + (VIsual_mode
== 'V'))
9153 case 0: p
= N_(" VISUAL"); break;
9154 case 1: p
= N_(" VISUAL LINE"); break;
9155 case 2: p
= N_(" VISUAL BLOCK"); break;
9156 case 4: p
= N_(" SELECT"); break;
9157 case 5: p
= N_(" SELECT LINE"); break;
9158 default: p
= N_(" SELECT BLOCK"); break;
9160 MSG_PUTS_ATTR(_(p
), attr
);
9163 MSG_PUTS_ATTR(" --", attr
);
9169 #ifdef FEAT_INS_EXPAND
9170 && edit_submode
== NULL
/* otherwise it gets too long */
9174 MSG_PUTS_ATTR(_("recording"), attr
);
9178 mode_displayed
= TRUE
;
9179 if (need_clear
|| clear_cmdline
)
9181 msg_didout
= FALSE
; /* overwrite this message */
9184 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
9186 else if (clear_cmdline
&& msg_silent
== 0)
9187 /* Clear the whole command line. Will reset "clear_cmdline". */
9190 #ifdef FEAT_CMDL_INFO
9192 /* In Visual mode the size of the selected area must be redrawn. */
9197 /* If the last window has no status line, the ruler is after the mode
9198 * message and must be redrawn */
9200 # ifdef FEAT_WINDOWS
9201 && lastwin
->w_status_height
== 0
9204 win_redr_ruler(lastwin
, TRUE
);
9206 redraw_cmdline
= FALSE
;
9207 clear_cmdline
= FALSE
;
9213 * Position for a mode message.
9223 * Delete mode message. Used when ESC is typed which is expected to end
9224 * Insert mode (but Insert mode didn't end yet!).
9225 * Caller should check "mode_displayed".
9232 * Don't delete it right now, when not redrawing or inside a mapping.
9234 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
9235 redraw_cmdline
= TRUE
; /* delete mode later */
9240 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
9245 #if defined(FEAT_WINDOWS)
9247 * Draw the tab pages line at the top of the Vim window.
9264 int attr_sel
= hl_attr(HLF_TPS
);
9265 int attr_nosel
= hl_attr(HLF_TP
);
9266 int attr_fill
= hl_attr(HLF_TPF
);
9269 int use_sep_chars
= (t_colors
< 8
9275 redraw_tabline
= FALSE
;
9277 #ifdef FEAT_GUI_TABLINE
9278 /* Take care of a GUI tabline. */
9279 if (gui_use_tabline())
9281 gui_update_tabline();
9286 if (tabline_height() < 1)
9289 #if defined(FEAT_STL_OPT)
9291 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9292 for (scol
= 0; scol
< Columns
; ++scol
)
9293 TabPageIdxs
[scol
] = 0;
9295 /* Use the 'tabline' option if it's set. */
9298 int save_called_emsg
= called_emsg
;
9300 /* Check for an error. If there is one we would loop in redrawing the
9301 * screen. Avoid that by making 'tabline' empty. */
9302 called_emsg
= FALSE
;
9303 win_redr_custom(NULL
, FALSE
);
9305 set_string_option_direct((char_u
*)"tabline", -1,
9306 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9307 called_emsg
|= save_called_emsg
;
9312 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
9315 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
9322 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
9327 if (tp
->tp_topframe
== topframe
)
9329 if (use_sep_chars
&& col
> 0)
9330 screen_putchar('|', 0, col
++, attr
);
9332 if (tp
->tp_topframe
!= topframe
)
9335 screen_putchar(' ', 0, col
++, attr
);
9344 cwp
= tp
->tp_curwin
;
9345 wp
= tp
->tp_firstwin
;
9349 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
9350 if (bufIsChanged(wp
->w_buffer
))
9352 if (modified
|| wincount
> 1)
9356 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
9357 len
= (int)STRLEN(NameBuff
);
9358 if (col
+ len
>= Columns
- 3)
9360 screen_puts_len(NameBuff
, len
, 0, col
,
9361 #if defined(FEAT_SYN_HL)
9362 hl_combine_attr(attr
, hl_attr(HLF_T
))
9370 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
9371 screen_putchar(' ', 0, col
++, attr
);
9374 room
= scol
- col
+ tabwidth
- 1;
9377 /* Get buffer name in NameBuff[] */
9378 get_trans_bufname(cwp
->w_buffer
);
9379 shorten_dir(NameBuff
);
9380 len
= vim_strsize(NameBuff
);
9386 len
-= ptr2cells(p
);
9396 if (len
> Columns
- col
- 1)
9397 len
= Columns
- col
- 1;
9399 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9402 screen_putchar(' ', 0, col
++, attr
);
9404 /* Store the tab page number in TabPageIdxs[], so that
9405 * jump_to_mouse() knows where each one is. */
9408 TabPageIdxs
[scol
++] = tabcount
;
9415 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9417 /* Put an "X" for closing the current tab if there are several. */
9418 if (first_tabpage
->tp_next
!= NULL
)
9420 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9421 TabPageIdxs
[Columns
- 1] = -999;
9425 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9427 redraw_tabline
= FALSE
;
9431 * Get buffer name for "buf" into NameBuff[].
9432 * Takes care of special buffer names and translates special characters.
9435 get_trans_bufname(buf
)
9438 if (buf_spname(buf
) != NULL
)
9439 STRCPY(NameBuff
, buf_spname(buf
));
9441 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9442 trans_characters(NameBuff
, MAXPATHL
);
9446 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9448 * Get the character to use in a status line. Get its attributes in "*attr".
9451 fillchar_status(attr
, is_curwin
)
9458 *attr
= hl_attr(HLF_S
);
9463 *attr
= hl_attr(HLF_SNC
);
9466 /* Use fill when there is highlighting, and highlighting of current
9467 * window differs, or the fillchars differ, or this is not the
9469 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9470 || !is_curwin
|| firstwin
== lastwin
)
9471 || (fill_stl
!= fill_stlnc
)))
9479 #ifdef FEAT_VERTSPLIT
9481 * Get the character to use in a separator between vertically split windows.
9482 * Get its attributes in "*attr".
9488 *attr
= hl_attr(HLF_C
);
9489 if (*attr
== 0 && fill_vert
== ' ')
9497 * Return TRUE if redrawing should currently be done.
9502 return (!RedrawingDisabled
9503 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9507 * Return TRUE if printing messages should currently be done.
9512 return (!(p_lz
&& char_avail() && !KeyTyped
));
9516 * Show current status info in ruler and various other places
9517 * If always is FALSE, only show ruler if position has changed.
9523 if (!always
&& !redrawing())
9525 #ifdef FEAT_INS_EXPAND
9528 # ifdef FEAT_WINDOWS
9529 /* Don't redraw right now, do it later. */
9530 curwin
->w_redr_status
= TRUE
;
9535 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9536 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9538 redraw_custom_statusline(curwin
);
9542 #ifdef FEAT_CMDL_INFO
9543 win_redr_ruler(curwin
, always
);
9548 # ifdef FEAT_STL_OPT
9549 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9550 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9556 /* Redraw the tab pages line if needed. */
9562 #ifdef FEAT_CMDL_INFO
9564 win_redr_ruler(wp
, always
)
9568 #define RULER_BUF_LEN 70
9569 char_u buffer
[RULER_BUF_LEN
];
9573 int empty_line
= FALSE
;
9578 #ifdef FEAT_VERTSPLIT
9581 int width
= Columns
;
9582 # define WITH_OFF(x) x
9583 # define WITH_WIDTH(x) x
9585 # define WITH_OFF(x) 0
9586 # define WITH_WIDTH(x) Columns
9587 # define this_ru_col ru_col
9590 /* If 'ruler' off or redrawing disabled, don't do anything */
9595 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9596 * after deleting lines, before cursor.lnum is corrected.
9598 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9601 #ifdef FEAT_INS_EXPAND
9602 /* Don't draw the ruler while doing insert-completion, it might overwrite
9603 * the (long) mode message. */
9604 # ifdef FEAT_WINDOWS
9605 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9607 if (edit_submode
!= NULL
)
9609 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9617 int save_called_emsg
= called_emsg
;
9619 called_emsg
= FALSE
;
9620 win_redr_custom(wp
, TRUE
);
9622 set_string_option_direct((char_u
*)"rulerformat", -1,
9623 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9624 called_emsg
|= save_called_emsg
;
9630 * Check if not in Insert mode and the line is empty (will show "0-1").
9632 if (!(State
& INSERT
)
9633 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9637 * Only draw the ruler when something changed.
9639 validate_virtcol_win(wp
);
9642 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9643 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9644 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9645 #ifdef FEAT_VIRTUALEDIT
9646 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9648 || wp
->w_topline
!= wp
->w_ru_topline
9649 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9651 || wp
->w_topfill
!= wp
->w_ru_topfill
9653 || empty_line
!= wp
->w_ru_empty
)
9657 if (wp
->w_status_height
)
9659 row
= W_WINROW(wp
) + wp
->w_height
;
9660 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9661 # ifdef FEAT_VERTSPLIT
9663 width
= W_WIDTH(wp
);
9672 #ifdef FEAT_VERTSPLIT
9678 /* In list mode virtcol needs to be recomputed */
9679 virtcol
= wp
->w_virtcol
;
9680 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9682 wp
->w_p_list
= FALSE
;
9683 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9684 wp
->w_p_list
= TRUE
;
9688 * Some sprintfs return the length, some return a pointer.
9689 * To avoid portability problems we use strlen() here.
9691 vim_snprintf((char *)buffer
, RULER_BUF_LEN
, "%ld,",
9692 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9694 : (long)(wp
->w_cursor
.lnum
));
9695 len
= STRLEN(buffer
);
9696 col_print(buffer
+ len
, RULER_BUF_LEN
- len
,
9697 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9701 * Add a "50%" if there is room for it.
9702 * On the last line, don't print in the last column (scrolls the
9703 * screen up on some terminals).
9705 i
= (int)STRLEN(buffer
);
9706 get_rel_pos(wp
, buffer
+ i
+ 1, RULER_BUF_LEN
- i
- 1);
9707 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9709 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9712 #ifdef FEAT_VERTSPLIT
9713 this_ru_col
= ru_col
- (Columns
- width
);
9714 if (this_ru_col
< 0)
9717 /* Never use more than half the window/screen width, leave the other
9718 * half for the filename. */
9719 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9720 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9721 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9723 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9727 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9730 buffer
[i
++] = fillchar
;
9733 get_rel_pos(wp
, buffer
+ i
, RULER_BUF_LEN
- i
);
9735 /* Truncate at window boundary. */
9740 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9742 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9743 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9752 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9753 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9755 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9757 screen_fill(row
, row
+ 1,
9758 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9759 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9760 fillchar
, fillchar
, attr
);
9761 /* don't redraw the cmdline because of showing the ruler */
9763 wp
->w_ru_cursor
= wp
->w_cursor
;
9764 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9765 wp
->w_ru_empty
= empty_line
;
9766 wp
->w_ru_topline
= wp
->w_topline
;
9767 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9769 wp
->w_ru_topfill
= wp
->w_topfill
;
9775 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9777 * Return the width of the 'number' column.
9778 * Caller may need to check if 'number' is set.
9779 * Otherwise it depends on 'numberwidth' and the line count.
9788 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9789 if (lnum
== wp
->w_nrwidth_line_count
)
9790 return wp
->w_nrwidth_width
;
9791 wp
->w_nrwidth_line_count
= lnum
;
9800 /* 'numberwidth' gives the minimal width plus one */
9801 if (n
< wp
->w_p_nuw
- 1)
9802 n
= wp
->w_p_nuw
- 1;
9804 wp
->w_nrwidth_width
= n
;