1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
11 * screen.c: code for displaying on the screen
13 * Output to the screen (console, terminal emulator or GUI window) is minimized
14 * by remembering what is already on the screen, and only updating the parts
17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently
18 * displayed (excluding text written by external commands).
19 * ScreenAttrs[off] Contains the associated attributes.
20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[]
22 * LineWraps[row] Flag for each line whether it wraps to the next line.
24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form
25 * one character which occupies two display cells.
26 * For UTF-8 a multi-byte character is converted to Unicode and stored in
27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII
28 * character without composing chars ScreenLinesUC[] will be 0. When the
29 * character occupies two display cells the next byte in ScreenLines[] is 0.
30 * ScreenLinesC[][] contain up to 'maxcombine' composing characters
31 * (drawn on top of the first character). They are 0 when not used.
32 * ScreenLines2[] is only used for euc-jp to store the second byte if the
33 * first byte is 0x8e (single-width character).
35 * The screen_*() functions write to the screen and handle updating
38 * update_screen() is the function that updates all windows and status lines.
39 * It is called form the main loop when must_redraw is non-zero. It may be
40 * called from other places when an immediate screen update is needed.
42 * The part of the buffer that is displayed in a window is set with:
43 * - w_topline (first buffer line in window)
44 * - w_topfill (filler line above the first line)
45 * - w_leftcol (leftmost window cell in window),
46 * - w_skipcol (skipped window cells of first line)
48 * Commands that only move the cursor around in a window, do not need to take
49 * action to update the display. The main loop will check if w_topline is
50 * valid and update it (scroll the window) when needed.
52 * Commands that scroll a window change w_topline and must call
53 * check_cursor() to move the cursor into the visible part of the window, and
54 * call redraw_later(VALID) to have the window displayed by update_screen()
57 * Commands that change text in the buffer must call changed_bytes() or
58 * changed_lines() to mark the area that changed and will require updating
59 * later. The main loop will call update_screen(), which will update each
60 * window that shows the changed buffer. This assumes text above the change
61 * can remain displayed as it is. Text after the change may need updating for
62 * scrolling, folding and syntax highlighting.
64 * Commands that change how a window is displayed (e.g., setting 'list') or
65 * invalidate the contents of a window in another way (e.g., change fold
66 * settings), must call redraw_later(NOT_VALID) to have the whole window
67 * redisplayed by update_screen() later.
69 * Commands that change how a buffer is displayed (e.g., setting 'tabstop')
70 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the
71 * buffer redisplayed by update_screen() later.
73 * Commands that change highlighting and possibly cause a scroll too must call
74 * redraw_later(SOME_VALID) to update the whole window but still use scrolling
75 * to avoid redrawing everything. But the length of displayed lines must not
76 * change, use NOT_VALID then.
78 * Commands that move the window position must call redraw_later(NOT_VALID).
79 * TODO: should minimize redrawing by scrolling when possible.
81 * Commands that change everything (e.g., resizing the screen) must call
82 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR).
84 * Things that are handled indirectly:
85 * - When messages scroll the screen up, msg_scrolled will be set and
86 * update_screen() called to redraw.
92 * The attributes that are actually active for writing to the screen.
94 static int screen_attr
= 0;
97 * Positioning the cursor is reduced by remembering the last position.
98 * Mostly used by windgoto() and screen_char().
100 static int screen_cur_row
, screen_cur_col
; /* last known cursor position */
102 #ifdef FEAT_SEARCH_EXTRA
103 static match_T search_hl
; /* used for 'hlsearch' highlight matching */
107 static foldinfo_T win_foldinfo
; /* info for 'foldcolumn' */
111 * Buffer for one screen line (characters and attributes).
113 static schar_T
*current_ScreenLine
;
115 static void win_update
__ARGS((win_T
*wp
));
116 static void win_draw_end
__ARGS((win_T
*wp
, int c1
, int c2
, int row
, int endrow
, hlf_T hl
));
118 static void fold_line
__ARGS((win_T
*wp
, long fold_count
, foldinfo_T
*foldinfo
, linenr_T lnum
, int row
));
119 static void fill_foldcolumn
__ARGS((char_u
*p
, win_T
*wp
, int closed
, linenr_T lnum
));
120 static void copy_text_attr
__ARGS((int off
, char_u
*buf
, int len
, int attr
));
122 static int win_line
__ARGS((win_T
*, linenr_T
, int, int, int nochange
));
123 static int char_needs_redraw
__ARGS((int off_from
, int off_to
, int cols
));
124 #ifdef FEAT_RIGHTLEFT
125 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
, int rlflag
));
126 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl))
128 static void screen_line
__ARGS((int row
, int coloff
, int endcol
, int clear_width
));
129 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c))
131 #ifdef FEAT_VERTSPLIT
132 static void draw_vsep_win
__ARGS((win_T
*wp
, int row
));
135 static void redraw_custum_statusline
__ARGS((win_T
*wp
));
137 #ifdef FEAT_SEARCH_EXTRA
138 #define SEARCH_HL_PRIORITY 0
139 static void start_search_hl
__ARGS((void));
140 static void end_search_hl
__ARGS((void));
141 static void prepare_search_hl
__ARGS((win_T
*wp
, linenr_T lnum
));
142 static void next_search_hl
__ARGS((win_T
*win
, match_T
*shl
, linenr_T lnum
, colnr_T mincol
));
144 static void screen_start_highlight
__ARGS((int attr
));
145 static void screen_char
__ARGS((unsigned off
, int row
, int col
));
147 static void screen_char_2
__ARGS((unsigned off
, int row
, int col
));
149 static void screenclear2
__ARGS((void));
150 static void lineclear
__ARGS((unsigned off
, int width
));
151 static void lineinvalid
__ARGS((unsigned off
, int width
));
152 #ifdef FEAT_VERTSPLIT
153 static void linecopy
__ARGS((int to
, int from
, win_T
*wp
));
154 static void redraw_block
__ARGS((int row
, int end
, win_T
*wp
));
156 static int win_do_lines
__ARGS((win_T
*wp
, int row
, int line_count
, int mayclear
, int del
));
157 static void win_rest_invalid
__ARGS((win_T
*wp
));
158 static void msg_pos_mode
__ARGS((void));
159 #if defined(FEAT_WINDOWS)
160 static void draw_tabline
__ARGS((void));
162 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
163 static int fillchar_status
__ARGS((int *attr
, int is_curwin
));
165 #ifdef FEAT_VERTSPLIT
166 static int fillchar_vsep
__ARGS((int *attr
));
169 static void win_redr_custom
__ARGS((win_T
*wp
, int draw_ruler
));
171 #ifdef FEAT_CMDL_INFO
172 static void win_redr_ruler
__ARGS((win_T
*wp
, int always
));
175 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
176 /* Ugly global: overrule attribute used by screen_char() */
177 static int screen_char_attr
= 0;
181 * Redraw the current window later, with update_screen(type).
182 * Set must_redraw only if not already set to a higher value.
183 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
189 redraw_win_later(curwin
, type
);
193 redraw_win_later(wp
, type
)
197 if (wp
->w_redr_type
< type
)
199 wp
->w_redr_type
= type
;
200 if (type
>= NOT_VALID
)
201 wp
->w_lines_valid
= 0;
202 if (must_redraw
< type
) /* must_redraw is the maximum of all windows */
208 * Force a complete redraw later. Also resets the highlighting. To be used
209 * after executing a shell command that messes up the screen.
214 redraw_all_later(CLEAR
);
217 /* Use a code that will reset gui.highlight_mask in
218 * gui_stop_highlight(). */
219 screen_attr
= HL_ALL
+ 1;
222 /* Use attributes that is very unlikely to appear in text. */
223 screen_attr
= HL_BOLD
| HL_UNDERLINE
| HL_INVERSE
;
227 * Mark all windows to be redrawn later.
230 redraw_all_later(type
)
237 redraw_win_later(wp
, type
);
242 * Mark all windows that are editing the current buffer to be updated later.
245 redraw_curbuf_later(type
)
248 redraw_buf_later(curbuf
, type
);
252 redraw_buf_later(buf
, type
)
260 if (wp
->w_buffer
== buf
)
261 redraw_win_later(wp
, type
);
266 * Changed something in the current window, at buffer line "lnum", that
267 * requires that line and possibly other lines to be redrawn.
268 * Used when entering/leaving Insert mode with the cursor on a folded line.
269 * Used to remove the "$" from a change command.
270 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
271 * may become invalid and the whole window will have to be redrawn.
275 redrawWinline(lnum
, invalid
)
277 int invalid
; /* 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 if (!screen_valid(TRUE
))
332 if (type
< must_redraw
) /* use maximal type */
335 /* must_redraw is reset here, so that when we run into some weird
336 * reason to redraw while busy redrawing (e.g., asynchronous
337 * scrolling), or update_topline() in win_update() will cause a
338 * scroll, the screen will be redrawn later or in win_update(). */
342 /* Need to update w_lines[]. */
343 if (curwin
->w_lines_valid
== 0 && type
< NOT_VALID
)
348 redraw_later(type
); /* remember type for next time */
350 if (type
> INVERTED_ALL
)
351 curwin
->w_lines_valid
= 0; /* don't use w_lines[].wl_size now */
355 updating_screen
= TRUE
;
357 ++display_tick
; /* let syntax code know we're in a next round of
358 * display updating */
362 * if the screen was scrolled up when displaying a message, scroll it down
366 clear_cmdline
= TRUE
;
367 if (msg_scrolled
> Rows
- 5) /* clearing is faster */
369 else if (type
!= CLEAR
)
371 check_for_delay(FALSE
);
372 if (screen_ins_lines(0, 0, msg_scrolled
, (int)Rows
, NULL
) == FAIL
)
376 if (W_WINROW(wp
) < msg_scrolled
)
378 if (W_WINROW(wp
) + wp
->w_height
> msg_scrolled
379 && wp
->w_redr_type
< REDRAW_TOP
380 && wp
->w_lines_valid
> 0
381 && wp
->w_topline
== wp
->w_lines
[0].wl_lnum
)
383 wp
->w_upd_rows
= msg_scrolled
- W_WINROW(wp
);
384 wp
->w_redr_type
= REDRAW_TOP
;
388 wp
->w_redr_type
= NOT_VALID
;
390 if (W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
)
392 wp
->w_redr_status
= TRUE
;
397 redraw_cmdline
= TRUE
;
399 redraw_tabline
= TRUE
;
403 need_wait_return
= FALSE
;
406 /* reset cmdline_row now (may have been changed temporarily) */
409 /* Check for changed highlighting */
410 if (need_highlight_changed
)
413 if (type
== CLEAR
) /* first clear screen */
415 screenclear(); /* will reset clear_cmdline */
419 if (clear_cmdline
) /* going to clear cmdline (done below) */
420 check_for_delay(FALSE
);
422 #ifdef FEAT_LINEBREAK
423 /* Force redraw when width of 'number' column changes. */
424 if (curwin
->w_redr_type
< NOT_VALID
425 && curwin
->w_nrwidth
!= (curwin
->w_p_nu
? number_width(curwin
) : 0))
426 curwin
->w_redr_type
= NOT_VALID
;
430 * Only start redrawing if there is really something to do.
432 if (type
== INVERTED
)
434 if (curwin
->w_redr_type
< type
436 && curwin
->w_lines
[0].wl_valid
438 && curwin
->w_topfill
== curwin
->w_old_topfill
439 && curwin
->w_botfill
== curwin
->w_old_botfill
441 && curwin
->w_topline
== curwin
->w_lines
[0].wl_lnum
)
445 && curwin
->w_old_cursor_lnum
== curwin
->w_cursor
.lnum
446 && curwin
->w_old_visual_mode
== VIsual_mode
447 && (curwin
->w_valid
& VALID_VIRTCOL
)
448 && curwin
->w_old_curswant
== curwin
->w_curswant
)
451 curwin
->w_redr_type
= type
;
454 /* Redraw the tab pages line if needed. */
455 if (redraw_tabline
|| type
>= NOT_VALID
)
461 * Correct stored syntax highlighting info for changes in each displayed
462 * buffer. Each buffer must only be done once.
466 if (wp
->w_buffer
->b_mod_set
)
471 /* Check if we already did this buffer. */
472 for (wwp
= firstwin
; wwp
!= wp
; wwp
= wwp
->w_next
)
473 if (wwp
->w_buffer
== wp
->w_buffer
)
480 syntax_present(wp
->w_buffer
))
481 syn_stack_apply_changes(wp
->w_buffer
);
487 * Go from top to bottom through the windows, redrawing the ones that need
490 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
493 #ifdef FEAT_SEARCH_EXTRA
494 search_hl
.rm
.regprog
= NULL
;
498 if (wp
->w_redr_type
!= 0)
501 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
505 # ifdef FEAT_SEARCH_EXTRA
508 # ifdef FEAT_CLIPBOARD
509 /* When Visual area changed, may have to update selection. */
510 if (clip_star
.available
&& clip_isautosel())
511 clip_update_selection();
514 /* Remove the cursor before starting to do anything, because
515 * scrolling may make it difficult to redraw the text under
526 /* redraw status line after the window to minimize cursor movement */
527 if (wp
->w_redr_status
)
534 #if defined(FEAT_SEARCH_EXTRA)
539 /* Reset b_mod_set flags. Going through all windows is probably faster
540 * than going through all buffers (there could be many buffers). */
541 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
542 wp
->w_buffer
->b_mod_set
= FALSE
;
544 curbuf
->b_mod_set
= FALSE
;
547 updating_screen
= FALSE
;
549 gui_may_resize_shell();
552 /* Clear or redraw the command line. Done last, because scrolling may
553 * mess up the command line. */
554 if (clear_cmdline
|| redraw_cmdline
)
557 /* May put up an introductory message when not editing a file */
558 if (!did_intro
&& bufempty()
559 && curbuf
->b_fname
== NULL
561 && firstwin
->w_next
== NULL
563 && vim_strchr(p_shm
, SHM_INTRO
) == NULL
)
564 intro_message(FALSE
);
568 /* Redraw the cursor and update the scrollbars when all screen updating is
572 out_flush(); /* required before updating the cursor */
574 gui_update_cursor(FALSE
, FALSE
);
575 gui_update_scrollbars(FALSE
);
580 #if defined(FEAT_SIGNS) || defined(FEAT_GUI)
581 static void update_prepare
__ARGS((void));
582 static void update_finish
__ARGS((void));
585 * Prepare for updating one or more windows.
591 updating_screen
= TRUE
;
593 /* Remove the cursor before starting to do anything, because scrolling may
594 * make it difficult to redraw the text under it. */
598 #ifdef FEAT_SEARCH_EXTRA
604 * Finish updating one or more windows.
612 # ifdef FEAT_SEARCH_EXTRA
616 updating_screen
= FALSE
;
619 gui_may_resize_shell();
621 /* Redraw the cursor and update the scrollbars when all screen updating is
625 out_flush(); /* required before updating the cursor */
626 gui_update_cursor(FALSE
, FALSE
);
627 gui_update_scrollbars(FALSE
);
633 #if defined(FEAT_SIGNS) || defined(PROTO)
635 update_debug_sign(buf
, lnum
)
643 win_foldinfo
.fi_level
= 0;
646 /* update/delete a specific mark */
649 if (buf
!= NULL
&& lnum
> 0)
651 if (wp
->w_buffer
== buf
&& lnum
>= wp
->w_topline
652 && lnum
< wp
->w_botline
)
654 if (wp
->w_redraw_top
== 0 || wp
->w_redraw_top
> lnum
)
655 wp
->w_redraw_top
= lnum
;
656 if (wp
->w_redraw_bot
== 0 || wp
->w_redraw_bot
< lnum
)
657 wp
->w_redraw_bot
= lnum
;
658 redraw_win_later(wp
, VALID
);
662 redraw_win_later(wp
, VALID
);
663 if (wp
->w_redr_type
!= 0)
670 /* update all windows that need updating */
674 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
676 if (wp
->w_redr_type
!= 0)
678 if (wp
->w_redr_status
)
682 if (curwin
->w_redr_type
!= 0)
691 #if defined(FEAT_GUI) || defined(PROTO)
693 * Update a single window, its status line and maybe the command line msg.
694 * Used for the GUI scrollbar.
702 #ifdef FEAT_CLIPBOARD
703 /* When Visual area changed, may have to update selection. */
704 if (clip_star
.available
&& clip_isautosel())
705 clip_update_selection();
711 /* When the screen was cleared redraw the tab pages line. */
715 if (wp
->w_redr_status
716 # ifdef FEAT_CMDL_INFO
720 || *p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
731 * Update a single window.
733 * This may cause the windows below it also to be redrawn (when clearing the
734 * screen or scrolling lines).
736 * How the window is redrawn depends on wp->w_redr_type. Each type also
737 * implies the one below it.
738 * NOT_VALID redraw the whole window
739 * SOME_VALID redraw the whole window but do scroll when possible
740 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID
741 * INVERTED redraw the changed part of the Visual area
742 * INVERTED_ALL redraw the whole Visual area
743 * VALID 1. scroll up/down to adjust for a changed w_topline
744 * 2. update lines at the top when scrolled down
745 * 3. redraw changed text:
746 * - if wp->w_buffer->b_mod_set set, update lines between
747 * b_mod_top and b_mod_bot.
748 * - if wp->w_redraw_top non-zero, redraw lines between
749 * wp->w_redraw_top and wp->w_redr_bot.
750 * - continue redrawing when syntax status is invalid.
751 * 4. if scrolled up, update lines at the bottom.
752 * This results in three areas that may need updating:
753 * top: from first row to top_end (when scrolled down)
754 * mid: from mid_start to mid_end (update inversion or changed text)
755 * bot: from bot_start to last row (when scrolled up)
761 buf_T
*buf
= wp
->w_buffer
;
763 int top_end
= 0; /* Below last row of the top area that needs
764 updating. 0 when no top area updating. */
765 int mid_start
= 999;/* first row of the mid area that needs
766 updating. 999 when no mid area updating. */
767 int mid_end
= 0; /* Below last row of the mid area that needs
768 updating. 0 when no mid area updating. */
769 int bot_start
= 999;/* first row of the bot area that needs
770 updating. 999 when no bot area updating */
772 int scrolled_down
= FALSE
; /* TRUE when scrolled down when
773 w_topline got smaller a bit */
775 #ifdef FEAT_SEARCH_EXTRA
776 matchitem_T
*cur
; /* points to the match list */
777 int top_to_mod
= FALSE
; /* redraw above mod_top */
780 int row
; /* current window row to display */
781 linenr_T lnum
; /* current buffer lnum to display */
782 int idx
; /* current index in w_lines[] */
783 int srow
; /* starting row of the current line */
785 int eof
= FALSE
; /* if TRUE, we hit the end of the file */
786 int didline
= FALSE
; /* if TRUE, we finished the last line */
789 static int recursive
= FALSE
; /* being called recursively */
790 int old_botline
= wp
->w_botline
;
795 /* remember what happened to the previous line, to know if
796 * check_visual_highlight() can be used */
797 #define DID_NONE 1 /* didn't update a line */
798 #define DID_LINE 2 /* updated a normal line */
799 #define DID_FOLD 3 /* updated a folded line */
800 int did_update
= DID_NONE
;
801 linenr_T syntax_last_parsed
= 0; /* last parsed text line */
803 linenr_T mod_top
= 0;
804 linenr_T mod_bot
= 0;
805 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
809 type
= wp
->w_redr_type
;
811 if (type
== NOT_VALID
)
814 wp
->w_redr_status
= TRUE
;
816 wp
->w_lines_valid
= 0;
819 /* Window is zero-height: nothing to draw. */
820 if (wp
->w_height
== 0)
826 #ifdef FEAT_VERTSPLIT
827 /* Window is zero-width: Only need to draw the separator. */
828 if (wp
->w_width
== 0)
830 /* draw the vertical separator right of this window */
831 draw_vsep_win(wp
, 0);
837 #ifdef FEAT_SEARCH_EXTRA
838 /* Setup for match and 'hlsearch' highlighting. Disable any previous
840 cur
= wp
->w_match_head
;
843 cur
->hl
.rm
= cur
->match
;
844 if (cur
->hlg_id
== 0)
847 cur
->hl
.attr
= syn_id2attr(cur
->hlg_id
);
850 cur
->hl
.first_lnum
= 0;
852 /* Set the time limit to 'redrawtime'. */
853 profile_setlimit(p_rdt
, &(cur
->hl
.tm
));
859 search_hl
.first_lnum
= 0;
860 /* time limit is set at the toplevel, for all windows */
863 #ifdef FEAT_LINEBREAK
864 /* Force redraw when width of 'number' column changes. */
865 i
= wp
->w_p_nu
? number_width(wp
) : 0;
866 if (wp
->w_nrwidth
!= i
)
874 if (buf
->b_mod_set
&& buf
->b_mod_xlines
!= 0 && wp
->w_redraw_top
!= 0)
877 * When there are both inserted/deleted lines and specific lines to be
878 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw
879 * everything (only happens when redrawing is off for while).
886 * Set mod_top to the first line that needs displaying because of
887 * changes. Set mod_bot to the first line after the changes.
889 mod_top
= wp
->w_redraw_top
;
890 if (wp
->w_redraw_bot
!= 0)
891 mod_bot
= wp
->w_redraw_bot
+ 1;
894 wp
->w_redraw_top
= 0; /* reset for next time */
895 wp
->w_redraw_bot
= 0;
898 if (mod_top
== 0 || mod_top
> buf
->b_mod_top
)
900 mod_top
= buf
->b_mod_top
;
902 /* Need to redraw lines above the change that may be included
903 * in a pattern match. */
904 if (syntax_present(buf
))
906 mod_top
-= buf
->b_syn_sync_linebreaks
;
912 if (mod_bot
== 0 || mod_bot
< buf
->b_mod_bot
)
913 mod_bot
= buf
->b_mod_bot
;
915 #ifdef FEAT_SEARCH_EXTRA
916 /* When 'hlsearch' is on and using a multi-line search pattern, a
917 * change in one line may make the Search highlighting in a
918 * previous line invalid. Simple solution: redraw all visible
919 * lines above the change.
920 * Same for a match pattern.
922 if (search_hl
.rm
.regprog
!= NULL
923 && re_multiline(search_hl
.rm
.regprog
))
927 cur
= wp
->w_match_head
;
930 if (cur
->match
.regprog
!= NULL
931 && re_multiline(cur
->match
.regprog
))
942 if (mod_top
!= 0 && hasAnyFolding(wp
))
944 linenr_T lnumt
, lnumb
;
947 * A change in a line can cause lines above it to become folded or
948 * unfolded. Find the top most buffer line that may be affected.
949 * If the line was previously folded and displayed, get the first
950 * line of that fold. If the line is folded now, get the first
951 * folded line. Use the minimum of these two.
954 /* Find last valid w_lines[] entry above mod_top. Set lnumt to
955 * the line below it. If there is no valid entry, use w_topline.
956 * Find the first valid w_lines[] entry below mod_bot. Set lnumb
957 * to this line. If there is no valid entry, use MAXLNUM. */
958 lnumt
= wp
->w_topline
;
960 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
961 if (wp
->w_lines
[i
].wl_valid
)
963 if (wp
->w_lines
[i
].wl_lastlnum
< mod_top
)
964 lnumt
= wp
->w_lines
[i
].wl_lastlnum
+ 1;
965 if (lnumb
== MAXLNUM
&& wp
->w_lines
[i
].wl_lnum
>= mod_bot
)
967 lnumb
= wp
->w_lines
[i
].wl_lnum
;
968 /* When there is a fold column it might need updating
969 * in the next line ("J" just above an open fold). */
975 (void)hasFoldingWin(wp
, mod_top
, &mod_top
, NULL
, TRUE
, NULL
);
979 /* Now do the same for the bottom line (one above mod_bot). */
981 (void)hasFoldingWin(wp
, mod_bot
, NULL
, &mod_bot
, TRUE
, NULL
);
988 /* When a change starts above w_topline and the end is below
989 * w_topline, start redrawing at w_topline.
990 * If the end of the change is above w_topline: do like no change was
991 * made, but redraw the first line to find changes in syntax. */
992 if (mod_top
!= 0 && mod_top
< wp
->w_topline
)
994 if (mod_bot
> wp
->w_topline
)
995 mod_top
= wp
->w_topline
;
997 else if (syntax_present(buf
))
1002 /* When line numbers are displayed need to redraw all lines below
1003 * inserted/deleted lines. */
1004 if (mod_top
!= 0 && buf
->b_mod_xlines
!= 0 && wp
->w_p_nu
)
1009 * When only displaying the lines at the top, set top_end. Used when
1010 * window has scrolled down for msg_scrolled.
1012 if (type
== REDRAW_TOP
)
1015 for (i
= 0; i
< wp
->w_lines_valid
; ++i
)
1017 j
+= wp
->w_lines
[i
].wl_size
;
1018 if (j
>= wp
->w_upd_rows
)
1025 /* not found (cannot happen?): redraw everything */
1028 /* top area defined, the rest is VALID */
1032 /* Trick: we want to avoid clearing the screen twice. screenclear() will
1033 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
1034 * non-zero and thus not FALSE) will indicate that screenclear() was not
1037 screen_cleared
= MAYBE
;
1040 * If there are no changes on the screen that require a complete redraw,
1041 * handle three cases:
1042 * 1: we are off the top of the screen by a few lines: scroll down
1043 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1044 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1045 * w_lines[] that needs updating.
1047 if ((type
== VALID
|| type
== SOME_VALID
1048 || type
== INVERTED
|| type
== INVERTED_ALL
)
1050 && !wp
->w_botfill
&& !wp
->w_old_botfill
1054 if (mod_top
!= 0 && wp
->w_topline
== mod_top
)
1057 * w_topline is the first changed line, the scrolling will be done
1061 else if (wp
->w_lines
[0].wl_valid
1062 && (wp
->w_topline
< wp
->w_lines
[0].wl_lnum
1064 || (wp
->w_topline
== wp
->w_lines
[0].wl_lnum
1065 && wp
->w_topfill
> wp
->w_old_topfill
)
1070 * New topline is above old topline: May scroll down.
1073 if (hasAnyFolding(wp
))
1077 /* count the number of lines we are off, counting a sequence
1078 * of folded lines as one */
1080 for (ln
= wp
->w_topline
; ln
< wp
->w_lines
[0].wl_lnum
; ++ln
)
1083 if (j
>= wp
->w_height
- 2)
1085 (void)hasFoldingWin(wp
, ln
, NULL
, &ln
, TRUE
, NULL
);
1090 j
= wp
->w_lines
[0].wl_lnum
- wp
->w_topline
;
1091 if (j
< wp
->w_height
- 2) /* not too far off */
1093 i
= plines_m_win(wp
, wp
->w_topline
, wp
->w_lines
[0].wl_lnum
- 1);
1095 /* insert extra lines for previously invisible filler lines */
1096 if (wp
->w_lines
[0].wl_lnum
!= wp
->w_topline
)
1097 i
+= diff_check_fill(wp
, wp
->w_lines
[0].wl_lnum
)
1098 - wp
->w_old_topfill
;
1100 if (i
< wp
->w_height
- 2) /* less than a screen off */
1103 * Try to insert the correct number of lines.
1104 * If not the last window, delete the lines at the bottom.
1105 * win_ins_lines may fail when the terminal can't do it.
1108 check_for_delay(FALSE
);
1109 if (win_ins_lines(wp
, 0, i
, FALSE
, wp
== firstwin
) == OK
)
1111 if (wp
->w_lines_valid
!= 0)
1113 /* Need to update rows that are new, stop at the
1114 * first one that scrolled down. */
1117 scrolled_down
= TRUE
;
1120 /* Move the entries that were scrolled, disable
1121 * the entries for the lines to be redrawn. */
1122 if ((wp
->w_lines_valid
+= j
) > wp
->w_height
)
1123 wp
->w_lines_valid
= wp
->w_height
;
1124 for (idx
= wp
->w_lines_valid
; idx
- j
>= 0; idx
--)
1125 wp
->w_lines
[idx
] = wp
->w_lines
[idx
- j
];
1127 wp
->w_lines
[idx
--].wl_valid
= FALSE
;
1131 mid_start
= 0; /* redraw all lines */
1134 mid_start
= 0; /* redraw all lines */
1137 mid_start
= 0; /* redraw all lines */
1142 * New topline is at or below old topline: May scroll up.
1143 * When topline didn't change, find first entry in w_lines[] that
1147 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */
1150 for (i
= 0; i
< wp
->w_lines_valid
; i
++)
1152 if (wp
->w_lines
[i
].wl_valid
1153 && wp
->w_lines
[i
].wl_lnum
== wp
->w_topline
)
1158 row
+= wp
->w_lines
[i
].wl_size
;
1162 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1169 * Try to delete the correct number of lines.
1170 * wp->w_topline is at wp->w_lines[i].wl_lnum.
1173 /* If the topline didn't change, delete old filler lines,
1174 * otherwise delete filler lines of the new topline... */
1175 if (wp
->w_lines
[0].wl_lnum
== wp
->w_topline
)
1176 row
+= wp
->w_old_topfill
;
1178 row
+= diff_check_fill(wp
, wp
->w_topline
);
1179 /* ... but don't delete new filler lines. */
1180 row
-= wp
->w_topfill
;
1184 check_for_delay(FALSE
);
1185 if (win_del_lines(wp
, 0, row
, FALSE
, wp
== firstwin
) == OK
)
1186 bot_start
= wp
->w_height
- row
;
1188 mid_start
= 0; /* redraw all lines */
1190 if ((row
== 0 || bot_start
< 999) && wp
->w_lines_valid
!= 0)
1193 * Skip the lines (below the deleted lines) that are still
1194 * valid and don't need redrawing. Copy their info
1195 * upwards, to compensate for the deleted lines. Set
1196 * bot_start to the first row that needs redrawing.
1202 wp
->w_lines
[idx
] = wp
->w_lines
[j
];
1203 /* stop at line that didn't fit, unless it is still
1204 * valid (no lines deleted) */
1205 if (row
> 0 && bot_start
+ row
1206 + (int)wp
->w_lines
[j
].wl_size
> wp
->w_height
)
1208 wp
->w_lines_valid
= idx
+ 1;
1211 bot_start
+= wp
->w_lines
[idx
++].wl_size
;
1213 /* stop at the last valid entry in w_lines[].wl_size */
1214 if (++j
>= wp
->w_lines_valid
)
1216 wp
->w_lines_valid
= idx
;
1221 /* Correct the first entry for filler lines at the top
1222 * when it won't get updated below. */
1223 if (wp
->w_p_diff
&& bot_start
> 0)
1224 wp
->w_lines
[0].wl_size
=
1225 plines_win_nofill(wp
, wp
->w_topline
, TRUE
)
1232 /* When starting redraw in the first line, redraw all lines. When
1233 * there is only one window it's probably faster to clear the screen
1237 mid_end
= wp
->w_height
;
1238 if (lastwin
== firstwin
)
1240 /* Clear the screen when it was not done by win_del_lines() or
1241 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE
1243 if (screen_cleared
!= TRUE
)
1246 /* The screen was cleared, redraw the tab pages line. */
1253 /* When win_del_lines() or win_ins_lines() caused the screen to be
1254 * cleared (only happens for the first window) or when screenclear()
1255 * was called directly above, "must_redraw" will have been set to
1256 * NOT_VALID, need to reset it here to avoid redrawing twice. */
1257 if (screen_cleared
== TRUE
)
1262 /* Not VALID or INVERTED: redraw all lines. */
1264 mid_end
= wp
->w_height
;
1267 if (type
== SOME_VALID
)
1269 /* SOME_VALID: redraw all lines. */
1271 mid_end
= wp
->w_height
;
1276 /* check if we are updating or removing the inverted part */
1277 if ((VIsual_active
&& buf
== curwin
->w_buffer
)
1278 || (wp
->w_old_cursor_lnum
!= 0 && type
!= NOT_VALID
))
1285 && (VIsual_mode
!= wp
->w_old_visual_mode
1286 || type
== INVERTED_ALL
))
1289 * If the type of Visual selection changed, redraw the whole
1290 * selection. Also when the ownership of the X selection is
1293 if (curwin
->w_cursor
.lnum
< VIsual
.lnum
)
1295 from
= curwin
->w_cursor
.lnum
;
1301 to
= curwin
->w_cursor
.lnum
;
1303 /* redraw more when the cursor moved as well */
1304 if (wp
->w_old_cursor_lnum
< from
)
1305 from
= wp
->w_old_cursor_lnum
;
1306 if (wp
->w_old_cursor_lnum
> to
)
1307 to
= wp
->w_old_cursor_lnum
;
1308 if (wp
->w_old_visual_lnum
< from
)
1309 from
= wp
->w_old_visual_lnum
;
1310 if (wp
->w_old_visual_lnum
> to
)
1311 to
= wp
->w_old_visual_lnum
;
1316 * Find the line numbers that need to be updated: The lines
1317 * between the old cursor position and the current cursor
1318 * position. Also check if the Visual position changed.
1320 if (curwin
->w_cursor
.lnum
< wp
->w_old_cursor_lnum
)
1322 from
= curwin
->w_cursor
.lnum
;
1323 to
= wp
->w_old_cursor_lnum
;
1327 from
= wp
->w_old_cursor_lnum
;
1328 to
= curwin
->w_cursor
.lnum
;
1329 if (from
== 0) /* Visual mode just started */
1333 if (VIsual
.lnum
!= wp
->w_old_visual_lnum
1334 || VIsual
.col
!= wp
->w_old_visual_col
)
1336 if (wp
->w_old_visual_lnum
< from
1337 && wp
->w_old_visual_lnum
!= 0)
1338 from
= wp
->w_old_visual_lnum
;
1339 if (wp
->w_old_visual_lnum
> to
)
1340 to
= wp
->w_old_visual_lnum
;
1341 if (VIsual
.lnum
< from
)
1343 if (VIsual
.lnum
> to
)
1349 * If in block mode and changed column or curwin->w_curswant:
1351 * First compute the actual start and end column.
1353 if (VIsual_mode
== Ctrl_V
)
1357 getvcols(wp
, &VIsual
, &curwin
->w_cursor
, &fromc
, &toc
);
1359 if (curwin
->w_curswant
== MAXCOL
)
1362 if (fromc
!= wp
->w_old_cursor_fcol
1363 || toc
!= wp
->w_old_cursor_lcol
)
1365 if (from
> VIsual
.lnum
)
1367 if (to
< VIsual
.lnum
)
1370 wp
->w_old_cursor_fcol
= fromc
;
1371 wp
->w_old_cursor_lcol
= toc
;
1376 /* Use the line numbers of the old Visual area. */
1377 if (wp
->w_old_cursor_lnum
< wp
->w_old_visual_lnum
)
1379 from
= wp
->w_old_cursor_lnum
;
1380 to
= wp
->w_old_visual_lnum
;
1384 from
= wp
->w_old_visual_lnum
;
1385 to
= wp
->w_old_cursor_lnum
;
1390 * There is no need to update lines above the top of the window.
1392 if (from
< wp
->w_topline
)
1393 from
= wp
->w_topline
;
1396 * If we know the value of w_botline, use it to restrict the update to
1397 * the lines that are visible in the window.
1399 if (wp
->w_valid
& VALID_BOTLINE
)
1401 if (from
>= wp
->w_botline
)
1402 from
= wp
->w_botline
- 1;
1403 if (to
>= wp
->w_botline
)
1404 to
= wp
->w_botline
- 1;
1408 * Find the minimal part to be updated.
1409 * Watch out for scrolling that made entries in w_lines[] invalid.
1410 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets
1411 * top_end; need to redraw from top_end to the "to" line.
1412 * A middle mouse click with a Visual selection may change the text
1413 * above the Visual area and reset wl_valid, do count these for
1414 * mid_end (in srow).
1418 lnum
= wp
->w_topline
;
1422 mid_start
= top_end
;
1425 while (lnum
< from
&& idx
< wp
->w_lines_valid
) /* find start */
1427 if (wp
->w_lines
[idx
].wl_valid
)
1428 mid_start
+= wp
->w_lines
[idx
].wl_size
;
1429 else if (!scrolled_down
)
1430 srow
+= wp
->w_lines
[idx
].wl_size
;
1432 # ifdef FEAT_FOLDING
1433 if (idx
< wp
->w_lines_valid
&& wp
->w_lines
[idx
].wl_valid
)
1434 lnum
= wp
->w_lines
[idx
].wl_lnum
;
1440 mid_end
= wp
->w_height
;
1441 for ( ; idx
< wp
->w_lines_valid
; ++idx
) /* find end */
1443 if (wp
->w_lines
[idx
].wl_valid
1444 && wp
->w_lines
[idx
].wl_lnum
>= to
+ 1)
1446 /* Only update until first row of this line */
1450 srow
+= wp
->w_lines
[idx
].wl_size
;
1455 if (VIsual_active
&& buf
== curwin
->w_buffer
)
1457 wp
->w_old_visual_mode
= VIsual_mode
;
1458 wp
->w_old_cursor_lnum
= curwin
->w_cursor
.lnum
;
1459 wp
->w_old_visual_lnum
= VIsual
.lnum
;
1460 wp
->w_old_visual_col
= VIsual
.col
;
1461 wp
->w_old_curswant
= curwin
->w_curswant
;
1465 wp
->w_old_visual_mode
= 0;
1466 wp
->w_old_cursor_lnum
= 0;
1467 wp
->w_old_visual_lnum
= 0;
1468 wp
->w_old_visual_col
= 0;
1470 #endif /* FEAT_VISUAL */
1472 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1473 /* reset got_int, otherwise regexp won't work */
1474 save_got_int
= got_int
;
1478 win_foldinfo
.fi_level
= 0;
1482 * Update all the window rows.
1484 idx
= 0; /* first entry in w_lines[].wl_size */
1487 lnum
= wp
->w_topline
; /* first line shown in window */
1490 /* stop updating when reached the end of the window (check for _past_
1491 * the end of the window is at the end of the loop) */
1492 if (row
== wp
->w_height
)
1498 /* stop updating when hit the end of the file */
1499 if (lnum
> buf
->b_ml
.ml_line_count
)
1505 /* Remember the starting row of the line that is going to be dealt
1506 * with. It is used further down when the line doesn't fit. */
1510 * Update a line when it is in an area that needs updating, when it
1511 * has changes or w_lines[idx] is invalid.
1512 * bot_start may be halfway a wrapped line after using
1513 * win_del_lines(), check if the current line includes it.
1514 * When syntax folding is being used, the saved syntax states will
1515 * already have been updated, we can't see where the syntax state is
1516 * the same again, just update until the end of the window.
1519 || (row
>= mid_start
&& row
< mid_end
)
1520 #ifdef FEAT_SEARCH_EXTRA
1523 || idx
>= wp
->w_lines_valid
1524 || (row
+ wp
->w_lines
[idx
].wl_size
> bot_start
)
1530 || did_update
== DID_FOLD
1531 || (did_update
== DID_LINE
1532 && syntax_present(buf
)
1534 # ifdef FEAT_FOLDING
1535 (foldmethodIsSyntax(wp
)
1536 && hasAnyFolding(wp
)) ||
1538 syntax_check_changed(lnum
)))
1542 #ifdef FEAT_SEARCH_EXTRA
1543 if (lnum
== mod_top
)
1548 * When at start of changed lines: May scroll following lines
1549 * up or down to minimize redrawing.
1550 * Don't do this when the change continues until the end.
1551 * Don't scroll when dollar_vcol is non-zero, keep the "$".
1554 && mod_bot
!= MAXLNUM
1555 && !(dollar_vcol
!= 0 && mod_bot
== mod_top
+ 1))
1562 /* Count the old number of window rows, using w_lines[], which
1563 * should still contain the sizes for the lines as they are
1564 * currently displayed. */
1565 for (i
= idx
; i
< wp
->w_lines_valid
; ++i
)
1567 /* Only valid lines have a meaningful wl_lnum. Invalid
1568 * lines are part of the changed area. */
1569 if (wp
->w_lines
[i
].wl_valid
1570 && wp
->w_lines
[i
].wl_lnum
== mod_bot
)
1572 old_rows
+= wp
->w_lines
[i
].wl_size
;
1574 if (wp
->w_lines
[i
].wl_valid
1575 && wp
->w_lines
[i
].wl_lastlnum
+ 1 == mod_bot
)
1577 /* Must have found the last valid entry above mod_bot.
1578 * Add following invalid entries. */
1580 while (i
< wp
->w_lines_valid
1581 && !wp
->w_lines
[i
].wl_valid
)
1582 old_rows
+= wp
->w_lines
[i
++].wl_size
;
1588 if (i
>= wp
->w_lines_valid
)
1590 /* We can't find a valid line below the changed lines,
1591 * need to redraw until the end of the window.
1592 * Inserting/deleting lines has no use. */
1597 /* Able to count old number of rows: Count new window
1598 * rows, and may insert/delete lines */
1600 for (l
= lnum
; l
< mod_bot
; ++l
)
1603 if (hasFoldingWin(wp
, l
, NULL
, &l
, TRUE
, NULL
))
1608 if (l
== wp
->w_topline
)
1609 new_rows
+= plines_win_nofill(wp
, l
, TRUE
)
1613 new_rows
+= plines_win(wp
, l
, TRUE
);
1615 if (new_rows
> wp
->w_height
- row
- 2)
1617 /* it's getting too much, must redraw the rest */
1622 xtra_rows
= new_rows
- old_rows
;
1625 /* May scroll text up. If there is not enough
1626 * remaining text or scrolling fails, must redraw the
1627 * rest. If scrolling works, must redraw the text
1628 * below the scrolled text. */
1629 if (row
- xtra_rows
>= wp
->w_height
- 2)
1633 check_for_delay(FALSE
);
1634 if (win_del_lines(wp
, row
,
1635 -xtra_rows
, FALSE
, FALSE
) == FAIL
)
1638 bot_start
= wp
->w_height
+ xtra_rows
;
1641 else if (xtra_rows
> 0)
1643 /* May scroll text down. If there is not enough
1644 * remaining text of scrolling fails, must redraw the
1646 if (row
+ xtra_rows
>= wp
->w_height
- 2)
1650 check_for_delay(FALSE
);
1651 if (win_ins_lines(wp
, row
+ old_rows
,
1652 xtra_rows
, FALSE
, FALSE
) == FAIL
)
1654 else if (top_end
> row
+ old_rows
)
1655 /* Scrolled the part at the top that requires
1657 top_end
+= xtra_rows
;
1661 /* When not updating the rest, may need to move w_lines[]
1663 if (mod_bot
!= MAXLNUM
&& i
!= j
)
1667 int x
= row
+ new_rows
;
1669 /* move entries in w_lines[] upwards */
1672 /* stop at last valid entry in w_lines[] */
1673 if (i
>= wp
->w_lines_valid
)
1675 wp
->w_lines_valid
= j
;
1678 wp
->w_lines
[j
] = wp
->w_lines
[i
];
1679 /* stop at a line that won't fit */
1680 if (x
+ (int)wp
->w_lines
[j
].wl_size
1683 wp
->w_lines_valid
= j
+ 1;
1686 x
+= wp
->w_lines
[j
++].wl_size
;
1694 /* move entries in w_lines[] downwards */
1696 wp
->w_lines_valid
+= j
;
1697 if (wp
->w_lines_valid
> wp
->w_height
)
1698 wp
->w_lines_valid
= wp
->w_height
;
1699 for (i
= wp
->w_lines_valid
; i
- j
>= idx
; --i
)
1700 wp
->w_lines
[i
] = wp
->w_lines
[i
- j
];
1702 /* The w_lines[] entries for inserted lines are
1703 * now invalid, but wl_size may be used above.
1707 wp
->w_lines
[i
].wl_size
= 0;
1708 wp
->w_lines
[i
--].wl_valid
= FALSE
;
1717 * When lines are folded, display one line for all of them.
1718 * Otherwise, display normally (can be several display lines when
1721 fold_count
= foldedCount(wp
, lnum
, &win_foldinfo
);
1722 if (fold_count
!= 0)
1724 fold_line(wp
, fold_count
, &win_foldinfo
, lnum
, row
);
1727 wp
->w_lines
[idx
].wl_folded
= TRUE
;
1728 wp
->w_lines
[idx
].wl_lastlnum
= lnum
+ fold_count
;
1730 did_update
= DID_FOLD
;
1735 if (idx
< wp
->w_lines_valid
1736 && wp
->w_lines
[idx
].wl_valid
1737 && wp
->w_lines
[idx
].wl_lnum
== lnum
1738 && lnum
> wp
->w_topline
1739 && !(dy_flags
& DY_LASTLINE
)
1740 && srow
+ wp
->w_lines
[idx
].wl_size
> wp
->w_height
1742 && diff_check_fill(wp
, lnum
) == 0
1746 /* This line is not going to fit. Don't draw anything here,
1747 * will draw "@ " lines below. */
1748 row
= wp
->w_height
+ 1;
1752 #ifdef FEAT_SEARCH_EXTRA
1753 prepare_search_hl(wp
, lnum
);
1756 /* Let the syntax stuff know we skipped a few lines. */
1757 if (syntax_last_parsed
!= 0 && syntax_last_parsed
+ 1 < lnum
1758 && syntax_present(buf
))
1759 syntax_end_parsing(syntax_last_parsed
+ 1);
1765 row
= win_line(wp
, lnum
, srow
, wp
->w_height
, mod_top
== 0);
1768 wp
->w_lines
[idx
].wl_folded
= FALSE
;
1769 wp
->w_lines
[idx
].wl_lastlnum
= lnum
;
1772 did_update
= DID_LINE
;
1773 syntax_last_parsed
= lnum
;
1777 wp
->w_lines
[idx
].wl_lnum
= lnum
;
1778 wp
->w_lines
[idx
].wl_valid
= TRUE
;
1779 if (row
> wp
->w_height
) /* past end of screen */
1781 /* we may need the size of that too long line later on */
1782 if (dollar_vcol
== 0)
1783 wp
->w_lines
[idx
].wl_size
= plines_win(wp
, lnum
, TRUE
);
1787 if (dollar_vcol
== 0)
1788 wp
->w_lines
[idx
].wl_size
= row
- srow
;
1791 lnum
+= fold_count
+ 1;
1798 /* This line does not need updating, advance to the next one */
1799 row
+= wp
->w_lines
[idx
++].wl_size
;
1800 if (row
> wp
->w_height
) /* past end of screen */
1803 lnum
= wp
->w_lines
[idx
- 1].wl_lastlnum
+ 1;
1808 did_update
= DID_NONE
;
1812 if (lnum
> buf
->b_ml
.ml_line_count
)
1819 * End of loop over all window lines.
1823 if (idx
> wp
->w_lines_valid
)
1824 wp
->w_lines_valid
= idx
;
1828 * Let the syntax stuff know we stop parsing here.
1830 if (syntax_last_parsed
!= 0 && syntax_present(buf
))
1831 syntax_end_parsing(syntax_last_parsed
+ 1);
1835 * If we didn't hit the end of the file, and we didn't finish the last
1836 * line we were working on, then the line didn't fit.
1838 wp
->w_empty_rows
= 0;
1840 wp
->w_filler_rows
= 0;
1842 if (!eof
&& !didline
)
1844 if (lnum
== wp
->w_topline
)
1847 * Single line that does not fit!
1848 * Don't overwrite it, it can be edited.
1850 wp
->w_botline
= lnum
+ 1;
1853 else if (diff_check_fill(wp
, lnum
) >= wp
->w_height
- srow
)
1855 /* Window ends in filler lines. */
1856 wp
->w_botline
= lnum
;
1857 wp
->w_filler_rows
= wp
->w_height
- srow
;
1860 else if (dy_flags
& DY_LASTLINE
) /* 'display' has "lastline" */
1863 * Last line isn't finished: Display "@@@" at the end.
1865 screen_fill(W_WINROW(wp
) + wp
->w_height
- 1,
1866 W_WINROW(wp
) + wp
->w_height
,
1867 (int)W_ENDCOL(wp
) - 3, (int)W_ENDCOL(wp
),
1868 '@', '@', hl_attr(HLF_AT
));
1869 set_empty_rows(wp
, srow
);
1870 wp
->w_botline
= lnum
;
1874 win_draw_end(wp
, '@', ' ', srow
, wp
->w_height
, HLF_AT
);
1875 wp
->w_botline
= lnum
;
1880 #ifdef FEAT_VERTSPLIT
1881 draw_vsep_win(wp
, row
);
1883 if (eof
) /* we hit the end of the file */
1885 wp
->w_botline
= buf
->b_ml
.ml_line_count
+ 1;
1887 j
= diff_check_fill(wp
, wp
->w_botline
);
1888 if (j
> 0 && !wp
->w_botfill
)
1891 * Display filler lines at the end of the file
1893 if (char2cells(fill_diff
) > 1)
1897 if (row
+ j
> wp
->w_height
)
1898 j
= wp
->w_height
- row
;
1899 win_draw_end(wp
, i
, i
, row
, row
+ (int)j
, HLF_DED
);
1904 else if (dollar_vcol
== 0)
1905 wp
->w_botline
= lnum
;
1907 /* make sure the rest of the screen is blank */
1908 /* put '~'s on rows that aren't part of the file. */
1909 win_draw_end(wp
, '~', ' ', row
, wp
->w_height
, HLF_AT
);
1912 /* Reset the type of redrawing required, the window has been updated. */
1913 wp
->w_redr_type
= 0;
1915 wp
->w_old_topfill
= wp
->w_topfill
;
1916 wp
->w_old_botfill
= wp
->w_botfill
;
1919 if (dollar_vcol
== 0)
1922 * There is a trick with w_botline. If we invalidate it on each
1923 * change that might modify it, this will cause a lot of expensive
1924 * calls to plines() in update_topline() each time. Therefore the
1925 * value of w_botline is often approximated, and this value is used to
1926 * compute the value of w_topline. If the value of w_botline was
1927 * wrong, check that the value of w_topline is correct (cursor is on
1928 * the visible part of the text). If it's not, we need to redraw
1929 * again. Mostly this just means scrolling up a few lines, so it
1930 * doesn't look too bad. Only do this for the current window (where
1931 * changes are relevant).
1933 wp
->w_valid
|= VALID_BOTLINE
;
1934 if (wp
== curwin
&& wp
->w_botline
!= old_botline
&& !recursive
)
1937 curwin
->w_valid
&= ~VALID_TOPLINE
;
1938 update_topline(); /* may invalidate w_botline again */
1939 if (must_redraw
!= 0)
1941 /* Don't update for changes in buffer again. */
1942 i
= curbuf
->b_mod_set
;
1943 curbuf
->b_mod_set
= FALSE
;
1946 curbuf
->b_mod_set
= i
;
1952 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1953 /* restore got_int, unless CTRL-C was hit while redrawing */
1955 got_int
= save_got_int
;
1960 static int draw_signcolumn
__ARGS((win_T
*wp
));
1963 * Return TRUE when window "wp" has a column to draw signs in.
1969 return (wp
->w_buffer
->b_signlist
!= NULL
1970 # ifdef FEAT_NETBEANS_INTG
1978 * Clear the rest of the window and mark the unused lines with "c1". use "c2"
1979 * as the filler character.
1982 win_draw_end(wp
, c1
, c2
, row
, endrow
, hl
)
1990 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
1997 #ifdef FEAT_RIGHTLEFT
2000 /* No check for cmdline window: should never be right-left. */
2001 # ifdef FEAT_FOLDING
2006 /* draw the fold column at the right */
2007 if (n
> W_WIDTH(wp
))
2009 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2010 W_ENDCOL(wp
) - n
, (int)W_ENDCOL(wp
),
2011 ' ', ' ', hl_attr(HLF_FC
));
2015 if (draw_signcolumn(wp
))
2019 /* draw the sign column left of the fold column */
2020 if (nn
> W_WIDTH(wp
))
2022 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2023 W_ENDCOL(wp
) - nn
, (int)W_ENDCOL(wp
) - n
,
2024 ' ', ' ', hl_attr(HLF_SC
));
2028 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2029 W_WINCOL(wp
), W_ENDCOL(wp
) - 1 - FDC_OFF
,
2030 c2
, c2
, hl_attr(hl
));
2031 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2032 W_ENDCOL(wp
) - 1 - FDC_OFF
, W_ENDCOL(wp
) - FDC_OFF
,
2033 c1
, c2
, hl_attr(hl
));
2039 if (cmdwin_type
!= 0 && wp
== curwin
)
2041 /* draw the cmdline character in the leftmost column */
2043 if (n
> wp
->w_width
)
2045 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2046 W_WINCOL(wp
), (int)W_WINCOL(wp
) + n
,
2047 cmdwin_type
, ' ', hl_attr(HLF_AT
));
2051 if (wp
->w_p_fdc
> 0)
2053 int nn
= n
+ wp
->w_p_fdc
;
2055 /* draw the fold column at the left */
2056 if (nn
> W_WIDTH(wp
))
2058 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2059 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2060 ' ', ' ', hl_attr(HLF_FC
));
2065 if (draw_signcolumn(wp
))
2069 /* draw the sign column after the fold column */
2070 if (nn
> W_WIDTH(wp
))
2072 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2073 W_WINCOL(wp
) + n
, (int)W_WINCOL(wp
) + nn
,
2074 ' ', ' ', hl_attr(HLF_SC
));
2078 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + endrow
,
2079 W_WINCOL(wp
) + FDC_OFF
, (int)W_ENDCOL(wp
),
2080 c1
, c2
, hl_attr(hl
));
2082 set_empty_rows(wp
, row
);
2087 * Display one folded line.
2090 fold_line(wp
, fold_count
, foldinfo
, lnum
, row
)
2093 foldinfo_T
*foldinfo
;
2099 linenr_T lnume
= lnum
+ fold_count
- 1;
2105 int off
= (int)(current_ScreenLine
- ScreenLines
);
2108 /* Build the fold line:
2109 * 1. Add the cmdwin_type for the command-line window
2110 * 2. Add the 'foldcolumn'
2111 * 3. Add the 'number' column
2112 * 4. Compose the text
2114 * 6. set highlighting for the Visual area an other text
2119 * 1. Add the cmdwin_type for the command-line window
2120 * Ignores 'rightleft', this window is never right-left.
2123 if (cmdwin_type
!= 0 && wp
== curwin
)
2125 ScreenLines
[off
] = cmdwin_type
;
2126 ScreenAttrs
[off
] = hl_attr(HLF_AT
);
2129 ScreenLinesUC
[off
] = 0;
2136 * 2. Add the 'foldcolumn'
2139 if (fdc
> W_WIDTH(wp
) - col
)
2140 fdc
= W_WIDTH(wp
) - col
;
2143 fill_foldcolumn(buf
, wp
, TRUE
, lnum
);
2144 #ifdef FEAT_RIGHTLEFT
2149 copy_text_attr(off
+ W_WIDTH(wp
) - fdc
- col
, buf
, fdc
,
2151 /* reverse the fold column */
2152 for (i
= 0; i
< fdc
; ++i
)
2153 ScreenLines
[off
+ W_WIDTH(wp
) - i
- 1 - col
] = buf
[i
];
2157 copy_text_attr(off
+ col
, buf
, fdc
, hl_attr(HLF_FC
));
2161 #ifdef FEAT_RIGHTLEFT
2162 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
2163 for (ri = 0; ri < l; ++ri) \
2164 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \
2166 for (ri = 0; ri < l; ++ri) \
2167 ScreenAttrs[off + (p) + ri] = v
2169 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
2170 ScreenAttrs[off + (p) + ri] = v
2173 /* Set all attributes of the 'number' column and the text */
2174 RL_MEMSET(col
, hl_attr(HLF_FL
), W_WIDTH(wp
) - col
);
2177 /* If signs are being displayed, add two spaces. */
2178 if (draw_signcolumn(wp
))
2180 len
= W_WIDTH(wp
) - col
;
2185 # ifdef FEAT_RIGHTLEFT
2187 /* the line number isn't reversed */
2188 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
,
2189 (char_u
*)" ", len
, hl_attr(HLF_FL
));
2192 copy_text_attr(off
+ col
, (char_u
*)" ", len
, hl_attr(HLF_FL
));
2199 * 3. Add the 'number' column
2203 len
= W_WIDTH(wp
) - col
;
2206 int w
= number_width(wp
);
2210 sprintf((char *)buf
, "%*ld ", w
, (long)lnum
);
2211 #ifdef FEAT_RIGHTLEFT
2213 /* the line number isn't reversed */
2214 copy_text_attr(off
+ W_WIDTH(wp
) - len
- col
, buf
, len
,
2218 copy_text_attr(off
+ col
, buf
, len
, hl_attr(HLF_FL
));
2224 * 4. Compose the folded-line string with 'foldtext', if set.
2226 text
= get_foldtext(wp
, lnum
, lnume
, foldinfo
, buf
);
2228 txtcol
= col
; /* remember where text starts */
2231 * 5. move the text to current_ScreenLine. Fill up with "fill_fold".
2232 * Right-left text is put in columns 0 - number-col, normal text is put
2233 * in columns number-col - window-width.
2239 int u8c
, u8cc
[MAX_MCO
];
2245 int prev_c
= 0; /* previous Arabic character */
2246 int prev_c1
= 0; /* first composing char for prev_c */
2249 # ifdef FEAT_RIGHTLEFT
2256 /* Store multibyte characters in ScreenLines[] et al. correctly. */
2257 for (p
= text
; *p
!= NUL
; )
2259 cells
= (*mb_ptr2cells
)(p
);
2260 c_len
= (*mb_ptr2len
)(p
);
2261 if (col
+ cells
> W_WIDTH(wp
)
2262 # ifdef FEAT_RIGHTLEFT
2263 - (wp
->w_p_rl
? col
: 0)
2267 ScreenLines
[idx
] = *p
;
2270 u8c
= utfc_ptr2char(p
, u8cc
);
2271 if (*p
< 0x80 && u8cc
[0] == 0)
2273 ScreenLinesUC
[idx
] = 0;
2281 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
2283 /* Do Arabic shaping. */
2288 /* The idea of what is the previous and next
2289 * character depends on 'rightleft'. */
2294 nc
= utf_ptr2char(p
+ c_len
);
2299 pc
= utfc_ptr2char(p
+ c_len
, pcc
);
2305 u8c
= arabic_shape(u8c
, &firstbyte
, &u8cc
[0],
2307 ScreenLines
[idx
] = firstbyte
;
2312 /* Non-BMP character: display as ? or fullwidth ?. */
2315 ScreenLinesUC
[idx
] = (cells
== 2) ? 0xff1f : (int)'?';
2318 ScreenLinesUC
[idx
] = u8c
;
2319 for (i
= 0; i
< Screen_mco
; ++i
)
2321 ScreenLinesC
[i
][idx
] = u8cc
[i
];
2327 ScreenLines
[idx
+ 1] = 0;
2329 else if (cells
> 1) /* double-byte character */
2331 if (enc_dbcs
== DBCS_JPNU
&& *p
== 0x8e)
2332 ScreenLines2
[idx
] = p
[1];
2334 ScreenLines
[idx
+ 1] = p
[1];
2344 len
= (int)STRLEN(text
);
2345 if (len
> W_WIDTH(wp
) - col
)
2346 len
= W_WIDTH(wp
) - col
;
2349 #ifdef FEAT_RIGHTLEFT
2351 STRNCPY(current_ScreenLine
, text
, len
);
2354 STRNCPY(current_ScreenLine
+ col
, text
, len
);
2359 /* Fill the rest of the line with the fold filler */
2360 #ifdef FEAT_RIGHTLEFT
2364 while (col
< W_WIDTH(wp
)
2365 #ifdef FEAT_RIGHTLEFT
2366 - (wp
->w_p_rl
? txtcol
: 0)
2373 if (fill_fold
>= 0x80)
2375 ScreenLinesUC
[off
+ col
] = fill_fold
;
2376 ScreenLinesC
[0][off
+ col
] = 0;
2379 ScreenLinesUC
[off
+ col
] = 0;
2382 ScreenLines
[off
+ col
++] = fill_fold
;
2389 * 6. set highlighting for the Visual area an other text.
2390 * If all folded lines are in the Visual area, highlight the line.
2393 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2395 if (ltoreq(curwin
->w_cursor
, VIsual
))
2397 /* Visual is after curwin->w_cursor */
2398 top
= &curwin
->w_cursor
;
2403 /* Visual is before curwin->w_cursor */
2405 bot
= &curwin
->w_cursor
;
2407 if (lnum
>= top
->lnum
2408 && lnume
<= bot
->lnum
2409 && (VIsual_mode
!= 'v'
2410 || ((lnum
> top
->lnum
2411 || (lnum
== top
->lnum
2413 && (lnume
< bot
->lnum
2414 || (lnume
== bot
->lnum
2415 && (bot
->col
- (*p_sel
== 'e'))
2416 >= STRLEN(ml_get_buf(wp
->w_buffer
, lnume
, FALSE
)))))))
2418 if (VIsual_mode
== Ctrl_V
)
2420 /* Visual block mode: highlight the chars part of the block */
2421 if (wp
->w_old_cursor_fcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2423 if (wp
->w_old_cursor_lcol
+ txtcol
< (colnr_T
)W_WIDTH(wp
))
2424 len
= wp
->w_old_cursor_lcol
;
2426 len
= W_WIDTH(wp
) - txtcol
;
2427 RL_MEMSET(wp
->w_old_cursor_fcol
+ txtcol
, hl_attr(HLF_V
),
2428 len
- (int)wp
->w_old_cursor_fcol
);
2433 /* Set all attributes of the text */
2434 RL_MEMSET(txtcol
, hl_attr(HLF_V
), W_WIDTH(wp
) - txtcol
);
2441 /* Show 'cursorcolumn' in the fold line. */
2444 txtcol
+= wp
->w_virtcol
;
2446 txtcol
-= wp
->w_skipcol
;
2448 txtcol
-= wp
->w_leftcol
;
2449 if (txtcol
>= 0 && txtcol
< W_WIDTH(wp
))
2450 ScreenAttrs
[off
+ txtcol
] = hl_combine_attr(
2451 ScreenAttrs
[off
+ txtcol
], hl_attr(HLF_CUC
));
2455 SCREEN_LINE(row
+ W_WINROW(wp
), W_WINCOL(wp
), (int)W_WIDTH(wp
),
2456 (int)W_WIDTH(wp
), FALSE
);
2459 * Update w_cline_height and w_cline_folded if the cursor line was
2460 * updated (saves a call to plines() later).
2463 && lnum
<= curwin
->w_cursor
.lnum
2464 && lnume
>= curwin
->w_cursor
.lnum
)
2466 curwin
->w_cline_row
= row
;
2467 curwin
->w_cline_height
= 1;
2468 curwin
->w_cline_folded
= TRUE
;
2469 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
2474 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
2477 copy_text_attr(off
, buf
, len
, attr
)
2485 mch_memmove(ScreenLines
+ off
, buf
, (size_t)len
);
2488 vim_memset(ScreenLinesUC
+ off
, 0, sizeof(u8char_T
) * (size_t)len
);
2490 for (i
= 0; i
< len
; ++i
)
2491 ScreenAttrs
[off
+ i
] = attr
;
2495 * Fill the foldcolumn at "p" for window "wp".
2496 * Only to be called when 'foldcolumn' > 0.
2499 fill_foldcolumn(p
, wp
, closed
, lnum
)
2502 int closed
; /* TRUE of FALSE */
2503 linenr_T lnum
; /* current line number */
2510 /* Init to all spaces. */
2511 copy_spaces(p
, (size_t)wp
->w_p_fdc
);
2513 level
= win_foldinfo
.fi_level
;
2516 /* If there is only one column put more info in it. */
2517 empty
= (wp
->w_p_fdc
== 1) ? 0 : 1;
2519 /* If the column is too narrow, we start at the lowest level that
2520 * fits and use numbers to indicated the depth. */
2521 first_level
= level
- wp
->w_p_fdc
- closed
+ 1 + empty
;
2522 if (first_level
< 1)
2525 for (i
= 0; i
+ empty
< wp
->w_p_fdc
; ++i
)
2527 if (win_foldinfo
.fi_lnum
== lnum
2528 && first_level
+ i
>= win_foldinfo
.fi_low_level
)
2530 else if (first_level
== 1)
2532 else if (first_level
+ i
<= 9)
2533 p
[i
] = '0' + first_level
+ i
;
2536 if (first_level
+ i
== level
)
2541 p
[i
>= wp
->w_p_fdc
? i
- 1 : i
] = '+';
2543 #endif /* FEAT_FOLDING */
2546 * Display line "lnum" of window 'wp' on the screen.
2547 * Start at row "startrow", stop when "endrow" is reached.
2548 * wp->w_virtcol needs to be valid.
2550 * Return the number of last row the line occupies.
2554 win_line(wp
, lnum
, startrow
, endrow
, nochange
)
2559 int nochange
; /* not updating for changed text */
2561 int col
; /* visual column on screen */
2562 unsigned off
; /* offset in ScreenLines/ScreenAttrs */
2563 int c
= 0; /* init for GCC */
2564 long vcol
= 0; /* virtual column (for tabs) */
2565 long vcol_prev
= -1; /* "vcol" of previous character */
2566 char_u
*line
; /* current line */
2567 char_u
*ptr
; /* current position in "line" */
2568 int row
; /* row in the window, excl w_winrow */
2569 int screen_row
; /* row on the screen, incl w_winrow */
2571 char_u extra
[18]; /* "%ld" and 'fdc' must fit in here */
2572 int n_extra
= 0; /* number of extra chars */
2573 char_u
*p_extra
= NULL
; /* string of extra chars, plus NUL */
2574 int c_extra
= NUL
; /* extra chars, all the same */
2575 int extra_attr
= 0; /* attributes when n_extra != 0 */
2576 static char_u
*at_end_str
= (char_u
*)""; /* used for p_extra when
2577 displaying lcs_eol at end-of-line */
2578 int lcs_eol_one
= lcs_eol
; /* lcs_eol until it's been used */
2579 int lcs_prec_todo
= lcs_prec
; /* lcs_prec until it's been used */
2581 /* saved "extra" items for when draw_state becomes WL_LINE (again) */
2582 int saved_n_extra
= 0;
2583 char_u
*saved_p_extra
= NULL
;
2584 int saved_c_extra
= 0;
2585 int saved_char_attr
= 0;
2587 int n_attr
= 0; /* chars with special attr */
2588 int saved_attr2
= 0; /* char_attr saved for n_attr */
2589 int n_attr3
= 0; /* chars with overruling special attr */
2590 int saved_attr3
= 0; /* char_attr saved for n_attr3 */
2592 int n_skip
= 0; /* nr of chars to skip for 'nowrap' */
2594 int fromcol
, tocol
; /* start/end of inverting */
2595 int fromcol_prev
= -2; /* start of inverting after cursor */
2596 int noinvcur
= FALSE
; /* don't invert the cursor */
2603 int char_attr
= 0; /* attributes for next character */
2604 int attr_pri
= FALSE
; /* char_attr has priority */
2605 int area_highlighting
= FALSE
; /* Visual or incsearch highlighting
2607 int attr
= 0; /* attributes for area highlighting */
2608 int area_attr
= 0; /* attributes desired by highlighting */
2609 int search_attr
= 0; /* attributes desired by 'hlsearch' */
2611 int vcol_save_attr
= 0; /* saved attr for 'cursorcolumn' */
2612 int syntax_attr
= 0; /* attributes desired by syntax */
2613 int has_syntax
= FALSE
; /* this buffer has syntax highl. */
2615 int eol_hl_off
= 0; /* 1 if highlighted char after EOL */
2618 int has_spell
= FALSE
; /* this buffer has spell checking */
2619 # define SPWORDLEN 150
2620 char_u nextline
[SPWORDLEN
* 2];/* text with start of the next line */
2621 int nextlinecol
= 0; /* column where nextline[] starts */
2622 int nextline_idx
= 0; /* index in nextline[] where next line
2624 int spell_attr
= 0; /* attributes desired by spelling */
2625 int word_end
= 0; /* last byte with same spell_attr */
2626 static linenr_T checked_lnum
= 0; /* line number for "checked_col" */
2627 static int checked_col
= 0; /* column in "checked_lnum" up to which
2628 * there are no spell errors */
2629 static int cap_col
= -1; /* column to check for Cap word */
2630 static linenr_T capcol_lnum
= 0; /* line number where "cap_col" used */
2631 int cur_checked_col
= 0; /* checked column for current line */
2633 int extra_check
; /* has syntax or linebreak */
2635 int multi_attr
= 0; /* attributes desired by multibyte */
2636 int mb_l
= 1; /* multi-byte byte length */
2637 int mb_c
= 0; /* decoded multi-byte character */
2638 int mb_utf8
= FALSE
; /* screen char is UTF-8 char */
2639 int u8cc
[MAX_MCO
]; /* composing UTF-8 chars */
2642 int filler_lines
; /* nr of filler lines to be drawn */
2643 int filler_todo
; /* nr of filler lines still to do + 1 */
2644 hlf_T diff_hlf
= (hlf_T
)0; /* type of diff highlighting */
2645 int change_start
= MAXCOL
; /* first col of changed area */
2646 int change_end
= -1; /* last col of changed area */
2648 colnr_T trailcol
= MAXCOL
; /* start of trailing spaces */
2649 #ifdef FEAT_LINEBREAK
2650 int need_showbreak
= FALSE
;
2652 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
2653 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
2655 int line_attr
= 0; /* attribute for the whole line */
2657 #ifdef FEAT_SEARCH_EXTRA
2658 matchitem_T
*cur
; /* points to the match list */
2659 match_T
*shl
; /* points to search_hl or a match */
2660 int shl_flag
; /* flag to indicate whether search_hl
2661 has been processed or not */
2662 int prevcol_hl_flag
; /* flag to indicate whether prevcol
2663 equals startcol of search_hl or one
2667 int prev_c
= 0; /* previous Arabic character */
2668 int prev_c1
= 0; /* first composing char for prev_c */
2670 #if defined(LINE_ATTR)
2671 int did_line_attr
= 0;
2674 /* draw_state: items that are drawn in sequence: */
2675 #define WL_START 0 /* nothing done yet */
2677 # define WL_CMDLINE WL_START + 1 /* cmdline window column */
2679 # define WL_CMDLINE WL_START
2682 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */
2684 # define WL_FOLD WL_CMDLINE
2687 # define WL_SIGN WL_FOLD + 1 /* column for signs */
2689 # define WL_SIGN WL_FOLD /* column for signs */
2691 #define WL_NR WL_SIGN + 1 /* line number */
2692 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
2693 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */
2695 # define WL_SBR WL_NR
2697 #define WL_LINE WL_SBR + 1 /* text in the line */
2698 int draw_state
= WL_START
; /* what to draw next */
2699 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2700 int feedback_col
= 0;
2701 int feedback_old_attr
= -1;
2705 if (startrow
> endrow
) /* past the end already! */
2709 screen_row
= row
+ W_WINROW(wp
);
2712 * To speed up the loop below, set extra_check when there is linebreak,
2713 * trailing white space and/or syntax processing to be done.
2715 #ifdef FEAT_LINEBREAK
2716 extra_check
= wp
->w_p_lbr
;
2722 * Highlight the line if this buffer is in the code_check.c watchlist,
2723 * and there is an associated error in the corresponding error/warning
2726 if (cc_is_buf_watched(curbuf
)) {
2727 switch (cc_get_ew_type(curbuf
, lnum
)) {
2728 case /*CC_WARNING*/1:
2729 line_attr
= hl_attr(HLF_WM
);
2732 line_attr
= hl_attr(HLF_E
);
2741 if (syntax_present(wp
->w_buffer
) && !wp
->w_buffer
->b_syn_error
)
2743 /* Prepare for syntax highlighting in this line. When there is an
2744 * error, stop syntax highlighting. */
2745 save_did_emsg
= did_emsg
;
2747 syntax_start(wp
, lnum
);
2749 wp
->w_buffer
->b_syn_error
= TRUE
;
2752 did_emsg
= save_did_emsg
;
2761 && *wp
->w_buffer
->b_p_spl
!= NUL
2762 && wp
->w_buffer
->b_langp
.ga_len
> 0
2763 && *(char **)(wp
->w_buffer
->b_langp
.ga_data
) != NULL
)
2765 /* Prepare for spell checking. */
2769 /* Get the start of the next line, so that words that wrap to the next
2770 * line are found too: "et<line-break>al.".
2771 * Trick: skip a few chars for C/shell/Vim comments */
2772 nextline
[SPWORDLEN
] = NUL
;
2773 if (lnum
< wp
->w_buffer
->b_ml
.ml_line_count
)
2775 line
= ml_get_buf(wp
->w_buffer
, lnum
+ 1, FALSE
);
2776 spell_cat_line(nextline
+ SPWORDLEN
, line
, SPWORDLEN
);
2779 /* When a word wrapped from the previous line the start of the current
2781 if (lnum
== checked_lnum
)
2782 cur_checked_col
= checked_col
;
2785 /* When there was a sentence end in the previous line may require a
2786 * word starting with capital in this line. In line 1 always check
2787 * the first word. */
2788 if (lnum
!= capcol_lnum
)
2797 * handle visual active in this window
2802 if (VIsual_active
&& wp
->w_buffer
== curwin
->w_buffer
)
2804 /* Visual is after curwin->w_cursor */
2805 if (ltoreq(curwin
->w_cursor
, VIsual
))
2807 top
= &curwin
->w_cursor
;
2810 else /* Visual is before curwin->w_cursor */
2813 bot
= &curwin
->w_cursor
;
2815 if (VIsual_mode
== Ctrl_V
) /* block mode */
2817 if (lnum
>= top
->lnum
&& lnum
<= bot
->lnum
)
2819 fromcol
= wp
->w_old_cursor_fcol
;
2820 tocol
= wp
->w_old_cursor_lcol
;
2823 else /* non-block mode */
2825 if (lnum
> top
->lnum
&& lnum
<= bot
->lnum
)
2827 else if (lnum
== top
->lnum
)
2829 if (VIsual_mode
== 'V') /* linewise */
2833 getvvcol(wp
, top
, (colnr_T
*)&fromcol
, NULL
, NULL
);
2834 if (gchar_pos(top
) == NUL
)
2835 tocol
= fromcol
+ 1;
2838 if (VIsual_mode
!= 'V' && lnum
== bot
->lnum
)
2840 if (*p_sel
== 'e' && bot
->col
== 0
2841 #ifdef FEAT_VIRTUALEDIT
2849 else if (bot
->col
== MAXCOL
)
2855 getvvcol(wp
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2858 getvvcol(wp
, &pos
, NULL
, NULL
, (colnr_T
*)&tocol
);
2866 /* Check if the character under the cursor should not be inverted */
2867 if (!highlight_match
&& lnum
== curwin
->w_cursor
.lnum
&& wp
== curwin
2875 /* if inverting in this line set area_highlighting */
2878 area_highlighting
= TRUE
;
2879 attr
= hl_attr(HLF_V
);
2880 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
2881 if (clip_star
.available
&& !clip_star
.owned
&& clip_isautosel())
2882 attr
= hl_attr(HLF_VNC
);
2888 * handle 'incsearch' and ":s///c" highlighting
2891 #endif /* FEAT_VISUAL */
2894 && lnum
>= curwin
->w_cursor
.lnum
2895 && lnum
<= curwin
->w_cursor
.lnum
+ search_match_lines
)
2897 if (lnum
== curwin
->w_cursor
.lnum
)
2898 getvcol(curwin
, &(curwin
->w_cursor
),
2899 (colnr_T
*)&fromcol
, NULL
, NULL
);
2902 if (lnum
== curwin
->w_cursor
.lnum
+ search_match_lines
)
2905 pos
.col
= search_match_endcol
;
2906 getvcol(curwin
, &pos
, (colnr_T
*)&tocol
, NULL
, NULL
);
2910 if (fromcol
== tocol
) /* do at least one character */
2911 tocol
= fromcol
+ 1; /* happens when past end of line */
2912 area_highlighting
= TRUE
;
2913 attr
= hl_attr(HLF_I
);
2917 filler_lines
= diff_check(wp
, lnum
);
2918 if (filler_lines
< 0)
2920 if (filler_lines
== -1)
2922 if (diff_find_change(wp
, lnum
, &change_start
, &change_end
))
2923 diff_hlf
= HLF_ADD
; /* added line */
2924 else if (change_start
== 0)
2925 diff_hlf
= HLF_TXD
; /* changed text */
2927 diff_hlf
= HLF_CHD
; /* changed line */
2930 diff_hlf
= HLF_ADD
; /* added line */
2932 area_highlighting
= TRUE
;
2934 if (lnum
== wp
->w_topline
)
2935 filler_lines
= wp
->w_topfill
;
2936 filler_todo
= filler_lines
;
2941 /* If this line has a sign with line highlighting set line_attr. */
2942 v
= buf_getsigntype(wp
->w_buffer
, lnum
, SIGN_LINEHL
);
2944 line_attr
= sign_get_attr((int)v
, TRUE
);
2946 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
2947 /* Highlight the current line in the quickfix window. */
2948 if (bt_quickfix(wp
->w_buffer
) && qf_current_entry(wp
) == lnum
)
2949 line_attr
= hl_attr(HLF_L
);
2952 area_highlighting
= TRUE
;
2955 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
2961 /* For checking first word with a capital skip white space. */
2963 cap_col
= (int)(skipwhite(line
) - line
);
2965 /* To be able to spell-check over line boundaries copy the end of the
2966 * current line into nextline[]. Above the start of the next line was
2967 * copied to nextline[SPWORDLEN]. */
2968 if (nextline
[SPWORDLEN
] == NUL
)
2970 /* No next line or it is empty. */
2971 nextlinecol
= MAXCOL
;
2976 v
= (long)STRLEN(line
);
2979 /* Short line, use it completely and append the start of the
2982 mch_memmove(nextline
, line
, (size_t)v
);
2983 STRMOVE(nextline
+ v
, nextline
+ SPWORDLEN
);
2984 nextline_idx
= v
+ 1;
2988 /* Long line, use only the last SPWORDLEN bytes. */
2989 nextlinecol
= v
- SPWORDLEN
;
2990 mch_memmove(nextline
, line
+ nextlinecol
, SPWORDLEN
);
2991 nextline_idx
= SPWORDLEN
+ 1;
2997 /* find start of trailing whitespace */
2998 if (wp
->w_p_list
&& lcs_trail
)
3000 trailcol
= (colnr_T
)STRLEN(ptr
);
3001 while (trailcol
> (colnr_T
)0 && vim_iswhite(ptr
[trailcol
- 1]))
3003 trailcol
+= (colnr_T
) (ptr
- line
);
3008 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
3009 * first character to be displayed.
3018 char_u
*prev_ptr
= ptr
;
3020 while (vcol
< v
&& *ptr
!= NUL
)
3022 c
= win_lbr_chartabsize(wp
, ptr
, (colnr_T
)vcol
, NULL
);
3030 #ifdef FEAT_VIRTUALEDIT
3031 /* When 'virtualedit' is set the end of the line may be before the
3032 * start of the displayed part. */
3033 if (vcol
< v
&& *ptr
== NUL
&& virtual_active())
3037 /* Handle a character that's not completely on the screen: Put ptr at
3038 * that character but skip the first few screen characters. */
3051 * Adjust for when the inverted text is before the screen,
3052 * and when the start of the inverted text is before the screen.
3056 else if (fromcol
>= 0 && fromcol
< vcol
)
3059 #ifdef FEAT_LINEBREAK
3060 /* When w_skipcol is non-zero, first line needs 'showbreak' */
3062 need_showbreak
= TRUE
;
3065 /* When spell checking a word we need to figure out the start of the
3066 * word and if it's badly spelled or not. */
3070 colnr_T linecol
= (colnr_T
)(ptr
- line
);
3071 hlf_T spell_hlf
= HLF_COUNT
;
3074 wp
->w_cursor
.lnum
= lnum
;
3075 wp
->w_cursor
.col
= linecol
;
3076 len
= spell_move_to(wp
, FORWARD
, TRUE
, TRUE
, &spell_hlf
);
3078 /* spell_move_to() may call ml_get() and make "line" invalid */
3079 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3080 ptr
= line
+ linecol
;
3082 if (len
== 0 || (int)wp
->w_cursor
.col
> ptr
- line
)
3084 /* no bad word found at line start, don't check until end of a
3086 spell_hlf
= HLF_COUNT
;
3087 word_end
= (int)(spell_to_word_end(ptr
, wp
->w_buffer
)
3092 /* bad word found, use attributes until end of word */
3093 word_end
= wp
->w_cursor
.col
+ len
+ 1;
3095 /* Turn index into actual attributes. */
3096 if (spell_hlf
!= HLF_COUNT
)
3097 spell_attr
= highlight_attr
[spell_hlf
];
3102 /* Need to restart syntax highlighting for this line. */
3104 syntax_start(wp
, lnum
);
3111 * Correct highlighting for cursor that can't be disabled.
3112 * Avoids having to check this for each character.
3118 if ((colnr_T
)fromcol
== wp
->w_virtcol
)
3120 /* highlighting starts at cursor, let it start just after the
3122 fromcol_prev
= fromcol
;
3125 else if ((colnr_T
)fromcol
< wp
->w_virtcol
)
3126 /* restart highlighting after the cursor */
3127 fromcol_prev
= wp
->w_virtcol
;
3129 if (fromcol
>= tocol
)
3133 #ifdef FEAT_SEARCH_EXTRA
3135 * Handle highlighting the last used search pattern and matches.
3136 * Do this for both search_hl and the match list.
3138 cur
= wp
->w_match_head
;
3140 while (cur
!= NULL
|| shl_flag
== FALSE
)
3142 if (shl_flag
== FALSE
)
3149 shl
->startcol
= MAXCOL
;
3150 shl
->endcol
= MAXCOL
;
3152 if (shl
->rm
.regprog
!= NULL
)
3154 v
= (long)(ptr
- line
);
3155 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3157 /* Need to get the line again, a multi-line regexp may have made it
3159 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3162 if (shl
->lnum
!= 0 && shl
->lnum
<= lnum
)
3164 if (shl
->lnum
== lnum
)
3165 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3168 if (lnum
== shl
->lnum
+ shl
->rm
.endpos
[0].lnum
3169 - shl
->rm
.startpos
[0].lnum
)
3170 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3172 shl
->endcol
= MAXCOL
;
3173 /* Highlight one character for an empty match. */
3174 if (shl
->startcol
== shl
->endcol
)
3177 if (has_mbyte
&& line
[shl
->endcol
] != NUL
)
3178 shl
->endcol
+= (*mb_ptr2len
)(line
+ shl
->endcol
);
3183 if ((long)shl
->startcol
< v
) /* match at leftcol */
3185 shl
->attr_cur
= shl
->attr
;
3186 search_attr
= shl
->attr
;
3188 area_highlighting
= TRUE
;
3191 if (shl
!= &search_hl
&& cur
!= NULL
)
3197 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is
3198 * active, because it's not clear what is selected then. */
3199 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
&& !VIsual_active
)
3201 line_attr
= hl_attr(HLF_CUL
);
3202 area_highlighting
= TRUE
;
3206 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
3208 #ifdef FEAT_RIGHTLEFT
3211 /* Rightleft window: process the text in the normal direction, but put
3212 * it in current_ScreenLine[] from right to left. Start at the
3213 * rightmost column of the window. */
3214 col
= W_WIDTH(wp
) - 1;
3220 * Repeat for the whole displayed line.
3224 /* Skip this quickly when working on the text. */
3225 if (draw_state
!= WL_LINE
)
3228 if (draw_state
== WL_CMDLINE
- 1 && n_extra
== 0)
3230 draw_state
= WL_CMDLINE
;
3231 if (cmdwin_type
!= 0 && wp
== curwin
)
3233 /* Draw the cmdline character. */
3235 c_extra
= cmdwin_type
;
3236 char_attr
= hl_attr(HLF_AT
);
3242 if (draw_state
== WL_FOLD
- 1 && n_extra
== 0)
3244 draw_state
= WL_FOLD
;
3245 if (wp
->w_p_fdc
> 0)
3247 /* Draw the 'foldcolumn'. */
3248 fill_foldcolumn(extra
, wp
, FALSE
, lnum
);
3249 n_extra
= wp
->w_p_fdc
;
3251 p_extra
[n_extra
] = NUL
;
3253 char_attr
= hl_attr(HLF_FC
);
3259 if (draw_state
== WL_SIGN
- 1 && n_extra
== 0)
3261 draw_state
= WL_SIGN
;
3262 /* Show the sign column when there are any signs in this
3263 * buffer or when using Netbeans. */
3264 if (draw_signcolumn(wp
)
3271 # ifdef FEAT_SIGN_ICONS
3275 /* Draw two cells with the sign value or blank. */
3277 char_attr
= hl_attr(HLF_SC
);
3280 if (row
== startrow
)
3282 text_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3284 # ifdef FEAT_SIGN_ICONS
3285 icon_sign
= buf_getsigntype(wp
->w_buffer
, lnum
,
3287 if (gui
.in_use
&& icon_sign
!= 0)
3289 /* Use the image in this position. */
3290 c_extra
= SIGN_BYTE
;
3291 # ifdef FEAT_NETBEANS_INTG
3292 if (buf_signcount(wp
->w_buffer
, lnum
) > 1)
3293 c_extra
= MULTISIGN_BYTE
;
3295 char_attr
= icon_sign
;
3301 p_extra
= sign_get_text(text_sign
);
3302 if (p_extra
!= NULL
)
3305 n_extra
= (int)STRLEN(p_extra
);
3307 char_attr
= sign_get_attr(text_sign
, FALSE
);
3314 if (draw_state
== WL_NR
- 1 && n_extra
== 0)
3317 /* Display the line number. After the first fill with blanks
3318 * when the 'n' flag isn't in 'cpo' */
3324 || vim_strchr(p_cpo
, CPO_NUMCOL
) == NULL
))
3326 /* Draw the line number (empty space after wrapping). */
3333 sprintf((char *)extra
, "%*ld ",
3334 number_width(wp
), (long)lnum
);
3335 if (wp
->w_skipcol
> 0)
3336 for (p_extra
= extra
; *p_extra
== ' '; ++p_extra
)
3338 #ifdef FEAT_RIGHTLEFT
3339 if (wp
->w_p_rl
) /* reverse line numbers */
3347 n_extra
= number_width(wp
) + 1;
3348 char_attr
= hl_attr(HLF_N
);
3350 /* When 'cursorline' is set highlight the line number of
3351 * the current line differently. */
3352 if (wp
->w_p_cul
&& lnum
== wp
->w_cursor
.lnum
)
3353 char_attr
= hl_combine_attr(hl_attr(HLF_CUL
), char_attr
);
3358 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
3359 if (draw_state
== WL_SBR
- 1 && n_extra
== 0)
3361 draw_state
= WL_SBR
;
3363 if (filler_todo
> 0)
3365 /* Draw "deleted" diff line(s). */
3366 if (char2cells(fill_diff
) > 1)
3369 c_extra
= fill_diff
;
3370 # ifdef FEAT_RIGHTLEFT
3375 n_extra
= W_WIDTH(wp
) - col
;
3376 char_attr
= hl_attr(HLF_DED
);
3379 # ifdef FEAT_LINEBREAK
3380 if (*p_sbr
!= NUL
&& need_showbreak
)
3382 /* Draw 'showbreak' at the start of each broken line. */
3385 n_extra
= (int)STRLEN(p_sbr
);
3386 char_attr
= hl_attr(HLF_AT
);
3387 need_showbreak
= FALSE
;
3388 /* Correct end of highlighted area for 'showbreak',
3389 * required when 'linebreak' is also set. */
3397 if (draw_state
== WL_LINE
- 1 && n_extra
== 0)
3399 draw_state
= WL_LINE
;
3402 /* Continue item from end of wrapped line. */
3403 n_extra
= saved_n_extra
;
3404 c_extra
= saved_c_extra
;
3405 p_extra
= saved_p_extra
;
3406 char_attr
= saved_char_attr
;
3413 /* When still displaying '$' of change command, stop at cursor */
3414 if (dollar_vcol
!= 0 && wp
== curwin
3415 && lnum
== wp
->w_cursor
.lnum
&& vcol
>= (long)wp
->w_virtcol
3421 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, -(int)W_WIDTH(wp
),
3423 /* Pretend we have finished updating the window. Except when
3424 * 'cursorcolumn' is set. */
3427 row
= wp
->w_cline_row
+ wp
->w_cline_height
;
3434 if (draw_state
== WL_LINE
&& area_highlighting
)
3436 /* handle Visual or match highlighting in this line */
3439 || (has_mbyte
&& vcol
+ 1 == fromcol
&& n_extra
== 0
3440 && (*mb_ptr2cells
)(ptr
) > 1)
3442 || ((int)vcol_prev
== fromcol_prev
3444 area_attr
= attr
; /* start highlighting */
3445 else if (area_attr
!= 0
3447 || (noinvcur
&& (colnr_T
)vcol
== wp
->w_virtcol
)))
3448 area_attr
= 0; /* stop highlighting */
3450 #ifdef FEAT_SEARCH_EXTRA
3454 * Check for start/end of search pattern match.
3455 * After end, check for start/end of next match.
3456 * When another match, have to check for start again.
3457 * Watch out for matching an empty string!
3458 * Do this for 'search_hl' and the match list (ordered by
3461 v
= (long)(ptr
- line
);
3462 cur
= wp
->w_match_head
;
3464 while (cur
!= NULL
|| shl_flag
== FALSE
)
3466 if (shl_flag
== FALSE
3468 && cur
->priority
> SEARCH_HL_PRIORITY
)
3476 while (shl
->rm
.regprog
!= NULL
)
3478 if (shl
->startcol
!= MAXCOL
3479 && v
>= (long)shl
->startcol
3480 && v
< (long)shl
->endcol
)
3482 shl
->attr_cur
= shl
->attr
;
3484 else if (v
== (long)shl
->endcol
)
3488 next_search_hl(wp
, shl
, lnum
, (colnr_T
)v
);
3490 /* Need to get the line again, a multi-line regexp
3491 * may have made it invalid. */
3492 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3495 if (shl
->lnum
== lnum
)
3497 shl
->startcol
= shl
->rm
.startpos
[0].col
;
3498 if (shl
->rm
.endpos
[0].lnum
== 0)
3499 shl
->endcol
= shl
->rm
.endpos
[0].col
;
3501 shl
->endcol
= MAXCOL
;
3503 if (shl
->startcol
== shl
->endcol
)
3505 /* highlight empty match, try again after
3509 shl
->endcol
+= (*mb_ptr2len
)(line
3516 /* Loop to check if the match starts at the
3517 * current position */
3523 if (shl
!= &search_hl
&& cur
!= NULL
)
3527 /* Use attributes from match with highest priority among
3528 * 'search_hl' and the match list. */
3529 search_attr
= search_hl
.attr_cur
;
3530 cur
= wp
->w_match_head
;
3532 while (cur
!= NULL
|| shl_flag
== FALSE
)
3534 if (shl_flag
== FALSE
3536 && cur
->priority
> SEARCH_HL_PRIORITY
)
3544 if (shl
->attr_cur
!= 0)
3545 search_attr
= shl
->attr_cur
;
3546 if (shl
!= &search_hl
&& cur
!= NULL
)
3553 if (diff_hlf
!= (hlf_T
)0)
3555 if (diff_hlf
== HLF_CHD
&& ptr
- line
>= change_start
3557 diff_hlf
= HLF_TXD
; /* changed text */
3558 if (diff_hlf
== HLF_TXD
&& ptr
- line
> change_end
3560 diff_hlf
= HLF_CHD
; /* changed line */
3561 line_attr
= hl_attr(diff_hlf
);
3565 /* Decide which of the highlight attributes to use. */
3568 char_attr
= area_attr
;
3569 else if (search_attr
!= 0)
3570 char_attr
= search_attr
;
3572 /* Use line_attr when not in the Visual or 'incsearch' area
3573 * (area_attr may be 0 when "noinvcur" is set). */
3574 else if (line_attr
!= 0 && ((fromcol
== -10 && tocol
== MAXCOL
)
3575 || (vcol
< fromcol
|| vcol
>= tocol
)))
3576 char_attr
= line_attr
;
3583 char_attr
= syntax_attr
;
3591 * Get the next character to put on the screen.
3594 * The "p_extra" points to the extra stuff that is inserted to
3595 * represent special characters (non-printable stuff) and other
3596 * things. When all characters are the same, c_extra is used.
3597 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
3598 * "p_extra[n_extra]".
3599 * For the '$' of the 'list' option, n_extra == 1, p_extra == "".
3607 mb_c
= c
; /* doesn't handle non-utf-8 multi-byte! */
3608 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3627 /* If the UTF-8 character is more than one byte:
3628 * Decode it into "mb_c". */
3629 mb_l
= (*mb_ptr2len
)(p_extra
);
3635 mb_c
= utfc_ptr2char(p_extra
, u8cc
);
3642 /* if this is a DBCS character, put it in "mb_c" */
3643 mb_l
= MB_BYTE2LEN(c
);
3644 if (mb_l
>= n_extra
)
3647 mb_c
= (c
<< 8) + p_extra
[1];
3649 if (mb_l
== 0) /* at the NUL at end-of-line */
3652 /* If a double-width char doesn't fit display a '>' in the
3655 # ifdef FEAT_RIGHTLEFT
3656 wp
->w_p_rl
? (col
<= 0) :
3658 (col
>= W_WIDTH(wp
) - 1))
3659 && (*mb_char2cells
)(mb_c
) == 2)
3665 multi_attr
= hl_attr(HLF_AT
);
3666 /* put the pointer back to output the double-width
3667 * character at the start of the next line. */
3673 n_extra
-= mb_l
- 1;
3674 p_extra
+= mb_l
- 1;
3685 * Get a character from the line itself.
3694 /* If the UTF-8 character is more than one byte: Decode it
3696 mb_l
= (*mb_ptr2len
)(ptr
);
3700 mb_c
= utfc_ptr2char(ptr
, u8cc
);
3701 /* Overlong encoded ASCII or ASCII with composing char
3702 * is displayed normally, except a NUL. */
3707 /* At start of the line we can have a composing char.
3708 * Draw it as a space with a composing char. */
3709 if (utf_iscomposing(mb_c
))
3713 for (i
= Screen_mco
- 1; i
> 0; --i
)
3714 u8cc
[i
] = u8cc
[i
- 1];
3720 if ((mb_l
== 1 && c
>= 0x80)
3721 || (mb_l
>= 1 && mb_c
== 0)
3722 || (mb_l
> 1 && (!vim_isprintc(mb_c
)
3729 * Illegal UTF-8 byte: display as <xx>.
3730 * Non-BMP character : display as ? or fullwidth ?.
3736 transchar_hex(extra
, mb_c
);
3737 # ifdef FEAT_RIGHTLEFT
3738 if (wp
->w_p_rl
) /* reverse */
3743 else if (utf_char2cells(mb_c
) != 2)
3746 /* 0xff1f in UTF-8: full-width '?' */
3747 STRCPY(extra
, "\357\274\237");
3752 mb_c
= mb_ptr2char_adv(&p_extra
);
3753 mb_utf8
= (c
>= 0x80);
3754 n_extra
= (int)STRLEN(p_extra
);
3756 if (area_attr
== 0 && search_attr
== 0)
3758 n_attr
= n_extra
+ 1;
3759 extra_attr
= hl_attr(HLF_8
);
3760 saved_attr2
= char_attr
; /* save current attr */
3763 else if (mb_l
== 0) /* at the NUL at end-of-line */
3766 else if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(mb_c
))
3768 /* Do Arabic shaping. */
3772 /* The idea of what is the previous and next
3773 * character depends on 'rightleft'. */
3778 nc
= utf_ptr2char(ptr
+ mb_l
);
3783 pc
= utfc_ptr2char(ptr
+ mb_l
, pcc
);
3789 mb_c
= arabic_shape(mb_c
, &c
, &u8cc
[0], pc
, pc1
, nc
);
3797 mb_l
= MB_BYTE2LEN(c
);
3798 if (mb_l
== 0) /* at the NUL at end-of-line */
3802 /* We assume a second byte below 32 is illegal.
3803 * Hopefully this is OK for all double-byte encodings!
3806 mb_c
= (c
<< 8) + ptr
[1];
3811 /* head byte at end of line */
3813 transchar_nonprint(extra
, c
);
3817 /* illegal tail byte */
3819 STRCPY(extra
, "XX");
3822 n_extra
= (int)STRLEN(extra
) - 1;
3825 if (area_attr
== 0 && search_attr
== 0)
3827 n_attr
= n_extra
+ 1;
3828 extra_attr
= hl_attr(HLF_8
);
3829 saved_attr2
= char_attr
; /* save current attr */
3835 /* If a double-width char doesn't fit display a '>' in the
3836 * last column; the character is displayed at the start of the
3839 # ifdef FEAT_RIGHTLEFT
3840 wp
->w_p_rl
? (col
<= 0) :
3842 (col
>= W_WIDTH(wp
) - 1))
3843 && (*mb_char2cells
)(mb_c
) == 2)
3849 multi_attr
= hl_attr(HLF_AT
);
3850 /* Put pointer back so that the character will be
3851 * displayed at the start of the next line. */
3854 else if (*ptr
!= NUL
)
3857 /* If a double-width char doesn't fit at the left side display
3858 * a '<' in the first column. */
3859 if (n_skip
> 0 && mb_l
> 1)
3864 if (area_attr
== 0 && search_attr
== 0)
3866 n_attr
= n_extra
+ 1;
3867 extra_attr
= hl_attr(HLF_AT
);
3868 saved_attr2
= char_attr
; /* save current attr */
3879 /* 'list' : change char 160 to lcs_nbsp. */
3880 if (wp
->w_p_list
&& (c
== 160
3882 || (mb_utf8
&& mb_c
== 160)
3887 if (area_attr
== 0 && search_attr
== 0)
3890 extra_attr
= hl_attr(HLF_8
);
3891 saved_attr2
= char_attr
; /* save current attr */
3895 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
3909 int can_spell
= TRUE
;
3913 /* Get syntax attribute, unless still at the start of the line
3914 * (double-wide char that doesn't fit). */
3915 v
= (long)(ptr
- line
);
3916 if (has_syntax
&& v
> 0)
3918 /* Get the syntax attribute for the character. If there
3919 * is an error, disable syntax highlighting. */
3920 save_did_emsg
= did_emsg
;
3923 syntax_attr
= get_syntax_attr((colnr_T
)v
- 1,
3925 has_spell
? &can_spell
:
3931 wp
->w_buffer
->b_syn_error
= TRUE
;
3935 did_emsg
= save_did_emsg
;
3937 /* Need to get the line again, a multi-line regexp may
3938 * have made it invalid. */
3939 line
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3943 char_attr
= syntax_attr
;
3945 char_attr
= hl_combine_attr(syntax_attr
, char_attr
);
3950 /* Check spelling (unless at the end of the line).
3951 * Only do this when there is no syntax highlighting, the
3952 * @Spell cluster is not used or the current syntax item
3953 * contains the @Spell cluster. */
3954 if (has_spell
&& v
>= word_end
&& v
> cur_checked_col
)
3959 char_attr
= syntax_attr
;
3967 char_u
*prev_ptr
, *p
;
3969 hlf_T spell_hlf
= HLF_COUNT
;
3973 prev_ptr
= ptr
- mb_l
;
3980 /* Use nextline[] if possible, it has the start of the
3981 * next line concatenated. */
3982 if ((prev_ptr
- line
) - nextlinecol
>= 0)
3983 p
= nextline
+ (prev_ptr
- line
) - nextlinecol
;
3986 cap_col
-= (int)(prev_ptr
- line
);
3987 len
= spell_check(wp
, p
, &spell_hlf
, &cap_col
,
3991 /* In Insert mode only highlight a word that
3992 * doesn't touch the cursor. */
3993 if (spell_hlf
!= HLF_COUNT
3994 && (State
& INSERT
) != 0
3995 && wp
->w_cursor
.lnum
== lnum
3996 && wp
->w_cursor
.col
>=
3997 (colnr_T
)(prev_ptr
- line
)
3998 && wp
->w_cursor
.col
< (colnr_T
)word_end
)
4000 spell_hlf
= HLF_COUNT
;
4001 spell_redraw_lnum
= lnum
;
4004 if (spell_hlf
== HLF_COUNT
&& p
!= prev_ptr
4005 && (p
- nextline
) + len
> nextline_idx
)
4007 /* Remember that the good word continues at the
4008 * start of the next line. */
4009 checked_lnum
= lnum
+ 1;
4010 checked_col
= (int)((p
- nextline
) + len
- nextline_idx
);
4013 /* Turn index into actual attributes. */
4014 if (spell_hlf
!= HLF_COUNT
)
4015 spell_attr
= highlight_attr
[spell_hlf
];
4020 && (p
- nextline
) + cap_col
>= nextline_idx
)
4022 /* Remember that the word in the next line
4023 * must start with a capital. */
4024 capcol_lnum
= lnum
+ 1;
4025 cap_col
= (int)((p
- nextline
) + cap_col
4029 /* Compute the actual column. */
4030 cap_col
+= (int)(prev_ptr
- line
);
4034 if (spell_attr
!= 0)
4037 char_attr
= hl_combine_attr(char_attr
, spell_attr
);
4039 char_attr
= hl_combine_attr(spell_attr
, char_attr
);
4042 #ifdef FEAT_LINEBREAK
4044 * Found last space before word: check for line break.
4046 if (wp
->w_p_lbr
&& vim_isbreak(c
) && !vim_isbreak(*ptr
)
4049 n_extra
= win_lbr_chartabsize(wp
, ptr
- (
4053 1), (colnr_T
)vcol
, NULL
) - 1;
4060 if (trailcol
!= MAXCOL
&& ptr
> line
+ trailcol
&& c
== ' ')
4066 extra_attr
= hl_attr(HLF_8
);
4067 saved_attr2
= char_attr
; /* save current attr */
4071 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4084 * Handling of non-printable characters.
4086 if (!(chartab
[c
& 0xff] & CT_PRINT_CHAR
))
4089 * when getting a character from the file, we may have to
4090 * turn it into something else on the way to putting it
4091 * into "ScreenLines".
4093 if (c
== TAB
&& (!wp
->w_p_list
|| lcs_tab1
))
4095 /* tab amount depends on current column */
4096 n_extra
= (int)wp
->w_buffer
->b_p_ts
4097 - vcol
% (int)wp
->w_buffer
->b_p_ts
- 1;
4099 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4105 n_attr
= n_extra
+ 1;
4106 extra_attr
= hl_attr(HLF_8
);
4107 saved_attr2
= char_attr
; /* save current attr */
4110 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4125 && ((wp
->w_p_list
&& lcs_eol
> 0)
4126 || ((fromcol
>= 0 || fromcol_prev
>= 0)
4129 && VIsual_mode
!= Ctrl_V
4132 # ifdef FEAT_RIGHTLEFT
4133 wp
->w_p_rl
? (col
>= 0) :
4135 (col
< W_WIDTH(wp
)))
4137 && (colnr_T
)vcol
== wp
->w_virtcol
)))
4138 && lcs_eol_one
>= 0)
4140 /* Display a '$' after the line or highlight an extra
4141 * character if the line break is included. */
4142 #if defined(FEAT_DIFF) || defined(LINE_ATTR)
4143 /* For a diff line the highlighting continues after the
4147 diff_hlf
== (hlf_T
)0
4158 #ifdef FEAT_VIRTUALEDIT
4159 /* In virtualedit, visual selections may extend
4160 * beyond end of line. */
4161 if (area_highlighting
&& virtual_active()
4162 && tocol
!= MAXCOL
&& vcol
< tocol
)
4167 p_extra
= at_end_str
;
4177 --ptr
; /* put it back at the NUL */
4180 extra_attr
= hl_attr(HLF_AT
);
4185 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4192 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4197 p_extra
= transchar(c
);
4198 #ifdef FEAT_RIGHTLEFT
4199 if ((dy_flags
& DY_UHEX
) && wp
->w_p_rl
)
4200 rl_mirror(p_extra
); /* reverse "<12>" */
4202 n_extra
= byte2cells(c
) - 1;
4207 n_attr
= n_extra
+ 1;
4208 extra_attr
= hl_attr(HLF_8
);
4209 saved_attr2
= char_attr
; /* save current attr */
4212 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4215 #ifdef FEAT_VIRTUALEDIT
4216 else if (VIsual_active
4217 && (VIsual_mode
== Ctrl_V
4218 || VIsual_mode
== 'v')
4223 # ifdef FEAT_RIGHTLEFT
4224 wp
->w_p_rl
? (col
>= 0) :
4226 (col
< W_WIDTH(wp
))))
4229 --ptr
; /* put it back at the NUL */
4232 #if defined(LINE_ATTR)
4235 diff_hlf
!= (hlf_T
)0 ||
4239 # ifdef FEAT_RIGHTLEFT
4240 wp
->w_p_rl
? (col
>= 0) :
4242 (col
< W_WIDTH(wp
))))
4244 /* Highlight until the right side of the window */
4246 --ptr
; /* put it back at the NUL */
4248 /* Remember we do the char for line highlighting. */
4251 /* don't do search HL for the rest of the line */
4252 if (line_attr
!= 0 && char_attr
== search_attr
&& col
> 0)
4253 char_attr
= line_attr
;
4255 if (diff_hlf
== HLF_TXD
)
4258 if (attr
== 0 || char_attr
!= attr
)
4259 char_attr
= hl_attr(diff_hlf
);
4267 /* Don't override visual selection highlighting. */
4269 && draw_state
== WL_LINE
4271 char_attr
= extra_attr
;
4273 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
4274 /* XIM don't send preedit_start and preedit_end, but they send
4275 * preedit_changed and commit. Thus Vim can't set "im_is_active", use
4276 * im_is_preediting() here. */
4278 && lnum
== curwin
->w_cursor
.lnum
4281 && im_is_preediting()
4282 && draw_state
== WL_LINE
)
4286 if (preedit_end_col
== MAXCOL
)
4287 getvcol(curwin
, &(curwin
->w_cursor
), &tcol
, NULL
, NULL
);
4289 tcol
= preedit_end_col
;
4290 if ((long)preedit_start_col
<= vcol
&& vcol
< (long)tcol
)
4292 if (feedback_old_attr
< 0)
4295 feedback_old_attr
= char_attr
;
4297 char_attr
= im_get_feedback_attr(feedback_col
);
4299 char_attr
= feedback_old_attr
;
4302 else if (feedback_old_attr
>= 0)
4304 char_attr
= feedback_old_attr
;
4305 feedback_old_attr
= -1;
4311 * Handle the case where we are in column 0 but not on the first
4312 * character of the line and the user wants us to show us a
4313 * special character (via 'listchars' option "precedes:<char>".
4315 if (lcs_prec_todo
!= NUL
4316 && (wp
->w_p_wrap
? wp
->w_skipcol
> 0 : wp
->w_leftcol
> 0)
4320 && draw_state
> WL_NR
4324 lcs_prec_todo
= NUL
;
4327 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4334 mb_utf8
= FALSE
; /* don't draw as UTF-8 */
4338 saved_attr3
= char_attr
; /* save current attr */
4339 char_attr
= hl_attr(HLF_AT
); /* later copied to char_attr */
4345 * At end of the text line or just after the last character.
4348 #if defined(LINE_ATTR)
4349 || did_line_attr
== 1
4353 #ifdef FEAT_SEARCH_EXTRA
4354 long prevcol
= (long)(ptr
- line
) - (c
== NUL
);
4356 /* we're not really at that column when skipping some text */
4357 if ((long)(wp
->w_p_wrap
? wp
->w_skipcol
: wp
->w_leftcol
) > prevcol
)
4361 /* invert at least one char, used for Visual and empty line or
4362 * highlight match at end of line. If it's beyond the last
4363 * char on the screen, just overwrite that one (tricky!) Not
4364 * needed when a '$' was displayed for 'list'. */
4365 #ifdef FEAT_SEARCH_EXTRA
4366 prevcol_hl_flag
= FALSE
;
4367 if (prevcol
== (long)search_hl
.startcol
)
4368 prevcol_hl_flag
= TRUE
;
4371 cur
= wp
->w_match_head
;
4374 if (prevcol
== (long)cur
->hl
.startcol
)
4376 prevcol_hl_flag
= TRUE
;
4383 if (lcs_eol
== lcs_eol_one
4384 && ((area_attr
!= 0 && vcol
== fromcol
&& c
== NUL
)
4385 #ifdef FEAT_SEARCH_EXTRA
4386 /* highlight 'hlsearch' match at end of line */
4387 || (prevcol_hl_flag
== TRUE
4388 # if defined(LINE_ATTR)
4389 && did_line_attr
<= 1
4397 #ifdef FEAT_RIGHTLEFT
4406 if (col
>= W_WIDTH(wp
))
4411 /* At the window boundary, highlight the last character
4412 * instead (better than nothing). */
4418 /* Add a blank character to highlight. */
4419 ScreenLines
[off
] = ' ';
4422 ScreenLinesUC
[off
] = 0;
4425 #ifdef FEAT_SEARCH_EXTRA
4428 /* Use attributes from match with highest priority among
4429 * 'search_hl' and the match list. */
4430 char_attr
= search_hl
.attr
;
4431 cur
= wp
->w_match_head
;
4433 while (cur
!= NULL
|| shl_flag
== FALSE
)
4435 if (shl_flag
== FALSE
4437 && cur
->priority
> SEARCH_HL_PRIORITY
)
4445 if ((ptr
- line
) - 1 == (long)shl
->startcol
)
4446 char_attr
= shl
->attr
;
4447 if (shl
!= &search_hl
&& cur
!= NULL
)
4452 ScreenAttrs
[off
] = char_attr
;
4453 #ifdef FEAT_RIGHTLEFT
4473 * At end of the text line.
4478 if (eol_hl_off
> 0 && vcol
- eol_hl_off
== (long)wp
->w_virtcol
)
4480 /* highlight last char after line */
4486 /* Highlight 'cursorcolumn' past end of the line. */
4491 /* check if line ends before left margin */
4492 if (vcol
< v
+ col
- win_col_off(wp
))
4494 vcol
= v
+ col
- win_col_off(wp
);
4496 && (int)wp
->w_virtcol
>= vcol
- eol_hl_off
4497 && (int)wp
->w_virtcol
< W_WIDTH(wp
) * (row
- startrow
+ 1)
4499 && lnum
!= wp
->w_cursor
.lnum
4500 # ifdef FEAT_RIGHTLEFT
4505 while (col
< W_WIDTH(wp
))
4507 ScreenLines
[off
] = ' ';
4510 ScreenLinesUC
[off
] = 0;
4513 if (vcol
== (long)wp
->w_virtcol
)
4515 ScreenAttrs
[off
] = hl_attr(HLF_CUC
);
4518 ScreenAttrs
[off
++] = 0;
4524 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4529 * Update w_cline_height and w_cline_folded if the cursor line was
4530 * updated (saves a call to plines() later).
4532 if (wp
== curwin
&& lnum
== curwin
->w_cursor
.lnum
)
4534 curwin
->w_cline_row
= startrow
;
4535 curwin
->w_cline_height
= row
- startrow
;
4537 curwin
->w_cline_folded
= FALSE
;
4539 curwin
->w_valid
|= (VALID_CHEIGHT
|VALID_CROW
);
4545 /* line continues beyond line end */
4552 #ifdef FEAT_RIGHTLEFT
4553 wp
->w_p_rl
? col
== 0 :
4555 col
== W_WIDTH(wp
) - 1)
4557 || (wp
->w_p_list
&& lcs_eol_one
> 0)
4558 || (n_extra
&& (c_extra
!= NUL
|| *p_extra
!= NUL
))))
4561 char_attr
= hl_attr(HLF_AT
);
4564 if (enc_utf8
&& (*mb_char2len
)(c
) > 1)
4576 /* Highlight the cursor column if 'cursorcolumn' is set. But don't
4577 * highlight the cursor position itself. */
4578 if (wp
->w_p_cuc
&& vcol
== (long)wp
->w_virtcol
4579 && lnum
!= wp
->w_cursor
.lnum
4580 && draw_state
== WL_LINE
)
4582 vcol_save_attr
= char_attr
;
4583 char_attr
= hl_combine_attr(char_attr
, hl_attr(HLF_CUC
));
4586 vcol_save_attr
= -1;
4590 * Store character to be displayed.
4591 * Skip characters that are left of the screen for 'nowrap'.
4594 if (draw_state
< WL_LINE
|| n_skip
<= 0)
4597 * Store the character.
4599 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
4600 if (has_mbyte
&& wp
->w_p_rl
&& (*mb_char2cells
)(mb_c
) > 1)
4602 /* A double-wide character is: put first halve in left cell. */
4607 ScreenLines
[off
] = c
;
4609 if (enc_dbcs
== DBCS_JPNU
)
4610 ScreenLines2
[off
] = mb_c
& 0xff;
4617 ScreenLinesUC
[off
] = mb_c
;
4618 if ((c
& 0xff) == 0)
4619 ScreenLines
[off
] = 0x80; /* avoid storing zero */
4620 for (i
= 0; i
< Screen_mco
; ++i
)
4622 ScreenLinesC
[i
][off
] = u8cc
[i
];
4628 ScreenLinesUC
[off
] = 0;
4632 ScreenAttrs
[off
] = multi_attr
;
4637 ScreenAttrs
[off
] = char_attr
;
4640 if (has_mbyte
&& (*mb_char2cells
)(mb_c
) > 1)
4642 /* Need to fill two screen columns. */
4646 /* UTF-8: Put a 0 in the second screen char. */
4647 ScreenLines
[off
] = 0;
4649 /* DBCS: Put second byte in the second screen char. */
4650 ScreenLines
[off
] = mb_c
& 0xff;
4652 /* When "tocol" is halfway a character, set it to the end of
4653 * the character, otherwise highlighting won't stop. */
4656 #ifdef FEAT_RIGHTLEFT
4659 /* now it's time to backup one cell */
4666 #ifdef FEAT_RIGHTLEFT
4682 /* Only advance the "vcol" when after the 'number' column. */
4683 if (draw_state
>= WL_SBR
4691 if (vcol_save_attr
>= 0)
4692 char_attr
= vcol_save_attr
;
4695 /* restore attributes after "predeces" in 'listchars' */
4696 if (draw_state
> WL_NR
&& n_attr3
> 0 && --n_attr3
== 0)
4697 char_attr
= saved_attr3
;
4699 /* restore attributes after last 'listchars' or 'number' char */
4700 if (n_attr
> 0 && draw_state
== WL_LINE
&& --n_attr
== 0)
4701 char_attr
= saved_attr2
;
4704 * At end of screen line and there is more to come: Display the line
4705 * so far. If there is no more to display it is caught above.
4708 #ifdef FEAT_RIGHTLEFT
4709 wp
->w_p_rl
? (col
< 0) :
4711 (col
>= W_WIDTH(wp
)))
4716 || (wp
->w_p_list
&& lcs_eol
!= NUL
&& p_extra
!= at_end_str
)
4717 || (n_extra
!= 0 && (c_extra
!= NUL
|| *p_extra
!= NUL
)))
4720 SCREEN_LINE(screen_row
, W_WINCOL(wp
), col
, (int)W_WIDTH(wp
),
4725 /* When not wrapping and finished diff lines, or when displayed
4726 * '$' and highlighting until last column, break here. */
4731 ) || lcs_eol_one
== -1)
4734 /* When the window is too narrow draw all "@" lines. */
4735 if (draw_state
!= WL_LINE
4741 win_draw_end(wp
, '@', ' ', row
, wp
->w_height
, HLF_AT
);
4742 #ifdef FEAT_VERTSPLIT
4743 draw_vsep_win(wp
, row
);
4748 /* When line got too long for screen break here. */
4755 if (screen_cur_row
== screen_row
- 1
4759 && W_WIDTH(wp
) == Columns
)
4761 /* Remember that the line wraps, used for modeless copy. */
4762 LineWraps
[screen_row
- 1] = TRUE
;
4765 * Special trick to make copy/paste of wrapped lines work with
4766 * xterm/screen: write an extra character beyond the end of
4767 * the line. This will work with all terminal types
4768 * (regardless of the xn,am settings).
4769 * Only do this on a fast tty.
4770 * Only do this if the cursor is on the current line
4771 * (something has been written in it).
4772 * Don't do this for the GUI.
4773 * Don't do this for double-width characters.
4774 * Don't do this for a window not at the right screen border.
4782 && ((*mb_off2cells
)(LineOffset
[screen_row
],
4783 LineOffset
[screen_row
] + screen_Columns
)
4785 || (*mb_off2cells
)(LineOffset
[screen_row
- 1]
4787 LineOffset
[screen_row
] + screen_Columns
)
4792 /* First make sure we are at the end of the screen line,
4793 * then output the same character again to let the
4794 * terminal know about the wrap. If the terminal doesn't
4795 * auto-wrap, we overwrite the character. */
4796 if (screen_cur_col
!= W_WIDTH(wp
))
4797 screen_char(LineOffset
[screen_row
- 1]
4798 + (unsigned)Columns
- 1,
4799 screen_row
- 1, (int)(Columns
- 1));
4802 /* When there is a multi-byte character, just output a
4803 * space to keep it simple. */
4804 if (has_mbyte
&& MB_BYTE2LEN(ScreenLines
[LineOffset
[
4805 screen_row
- 1] + (Columns
- 1)]) > 1)
4809 out_char(ScreenLines
[LineOffset
[screen_row
- 1]
4811 /* force a redraw of the first char on the next line */
4812 ScreenAttrs
[LineOffset
[screen_row
]] = (sattr_T
)-1;
4813 screen_start(); /* don't know where cursor is now */
4818 off
= (unsigned)(current_ScreenLine
- ScreenLines
);
4819 #ifdef FEAT_RIGHTLEFT
4822 col
= W_WIDTH(wp
) - 1; /* col is not used if breaking! */
4827 /* reset the drawing state for the start of a wrapped line */
4828 draw_state
= WL_START
;
4829 saved_n_extra
= n_extra
;
4830 saved_p_extra
= p_extra
;
4831 saved_c_extra
= c_extra
;
4832 saved_char_attr
= char_attr
;
4834 lcs_prec_todo
= lcs_prec
;
4835 #ifdef FEAT_LINEBREAK
4837 if (filler_todo
<= 0)
4839 need_showbreak
= TRUE
;
4843 /* When the filler lines are actually below the last line of the
4844 * file, don't draw the line itself, break here. */
4845 if (filler_todo
== 0 && wp
->w_botfill
)
4850 } /* for every character in the line */
4853 /* After an empty line check first word for capital. */
4854 if (*skipwhite(line
) == NUL
)
4856 capcol_lnum
= lnum
+ 1;
4865 static int comp_char_differs
__ARGS((int, int));
4868 * Return if the composing characters at "off_from" and "off_to" differ.
4871 comp_char_differs(off_from
, off_to
)
4877 for (i
= 0; i
< Screen_mco
; ++i
)
4879 if (ScreenLinesC
[i
][off_from
] != ScreenLinesC
[i
][off_to
])
4881 if (ScreenLinesC
[i
][off_from
] == 0)
4889 * Check whether the given character needs redrawing:
4890 * - the (first byte of the) character is different
4891 * - the attributes are different
4892 * - the character is multi-byte and the next byte is different
4893 * - the character is two cells wide and the second cell differs.
4896 char_needs_redraw(off_from
, off_to
, cols
)
4902 && ((ScreenLines
[off_from
] != ScreenLines
[off_to
]
4903 || ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
4907 && MB_BYTE2LEN(ScreenLines
[off_from
]) > 1
4908 && (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off_from
] == 0x8e
4909 ? ScreenLines2
[off_from
] != ScreenLines2
[off_to
]
4910 : (cols
> 1 && ScreenLines
[off_from
+ 1]
4911 != ScreenLines
[off_to
+ 1])))
4913 && (ScreenLinesUC
[off_from
] != ScreenLinesUC
[off_to
]
4914 || (ScreenLinesUC
[off_from
] != 0
4915 && comp_char_differs(off_from
, off_to
))
4916 || (cols
> 1 && ScreenLines
[off_from
+ 1]
4917 != ScreenLines
[off_to
+ 1])))
4925 * Move one "cooked" screen line to the screen, but only the characters that
4926 * have actually changed. Handle insert/delete character.
4927 * "coloff" gives the first column on the screen for this line.
4928 * "endcol" gives the columns where valid characters are.
4929 * "clear_width" is the width of the window. It's > 0 if the rest of the line
4930 * needs to be cleared, negative otherwise.
4931 * "rlflag" is TRUE in a rightleft window:
4932 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
4933 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
4936 screen_line(row
, coloff
, endcol
, clear_width
4937 #ifdef FEAT_RIGHTLEFT
4945 #ifdef FEAT_RIGHTLEFT
4952 unsigned max_off_from
;
4953 unsigned max_off_to
;
4956 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
4959 int force
= FALSE
; /* force update rest of the line */
4960 int redraw_this
/* bool: does character need redraw? */
4962 = TRUE
/* For GUI when while-loop empty */
4965 int redraw_next
; /* redraw_this for next character */
4967 int clear_next
= FALSE
;
4968 int char_cells
; /* 1: normal char */
4969 /* 2: occupies two display cells */
4970 # define CHAR_CELLS char_cells
4972 # define CHAR_CELLS 1
4975 # ifdef FEAT_CLIPBOARD
4976 clip_may_clear_selection(row
, row
);
4979 off_from
= (unsigned)(current_ScreenLine
- ScreenLines
);
4980 off_to
= LineOffset
[row
] + coloff
;
4982 max_off_from
= off_from
+ screen_Columns
;
4983 max_off_to
= LineOffset
[row
] + screen_Columns
;
4986 #ifdef FEAT_RIGHTLEFT
4989 /* Clear rest first, because it's left of the text. */
4990 if (clear_width
> 0)
4992 while (col
<= endcol
&& ScreenLines
[off_to
] == ' '
4993 && ScreenAttrs
[off_to
] == 0
4995 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5003 screen_fill(row
, row
+ 1, col
+ coloff
,
5004 endcol
+ coloff
+ 1, ' ', ' ', 0);
5007 off_to
= LineOffset
[row
] + col
+ coloff
;
5009 endcol
= (clear_width
> 0 ? clear_width
: -clear_width
);
5011 #endif /* FEAT_RIGHTLEFT */
5013 redraw_next
= char_needs_redraw(off_from
, off_to
, endcol
- col
);
5015 while (col
< endcol
)
5018 if (has_mbyte
&& (col
+ 1 < endcol
))
5019 char_cells
= (*mb_off2cells
)(off_from
, max_off_from
);
5024 redraw_this
= redraw_next
;
5025 redraw_next
= force
|| char_needs_redraw(off_from
+ CHAR_CELLS
,
5026 off_to
+ CHAR_CELLS
, endcol
- col
- CHAR_CELLS
);
5029 /* If the next character was bold, then redraw the current character to
5030 * remove any pixels that might have spilt over into us. This only
5031 * happens in the GUI.
5033 if (redraw_next
&& gui
.in_use
)
5035 hl
= ScreenAttrs
[off_to
+ CHAR_CELLS
];
5037 hl
= syn_attr2attr(hl
);
5046 * Special handling when 'xs' termcap flag set (hpterm):
5047 * Attributes for characters are stored at the position where the
5048 * cursor is when writing the highlighting code. The
5049 * start-highlighting code must be written with the cursor on the
5050 * first highlighted character. The stop-highlighting code must
5051 * be written with the cursor just after the last highlighted
5053 * Overwriting a character doesn't remove it's highlighting. Need
5054 * to clear the rest of the line, and force redrawing it
5062 && ScreenAttrs
[off_to
] != 0
5063 && ScreenAttrs
[off_from
] != ScreenAttrs
[off_to
])
5066 * Need to remove highlighting attributes here.
5068 windgoto(row
, col
+ coloff
);
5069 out_str(T_CE
); /* clear rest of this screen line */
5070 screen_start(); /* don't know where cursor is now */
5071 force
= TRUE
; /* force redraw of rest of the line */
5072 redraw_next
= TRUE
; /* or else next char would miss out */
5075 * If the previous character was highlighted, need to stop
5076 * highlighting at this character.
5078 if (col
+ coloff
> 0 && ScreenAttrs
[off_to
- 1] != 0)
5080 screen_attr
= ScreenAttrs
[off_to
- 1];
5081 term_windgoto(row
, col
+ coloff
);
5082 screen_stop_highlight();
5085 screen_attr
= 0; /* highlighting has stopped */
5090 /* Check if overwriting a double-byte with a single-byte or
5091 * the other way around requires another character to be
5092 * redrawn. For UTF-8 this isn't needed, because comparing
5093 * ScreenLinesUC[] is sufficient. */
5096 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5098 /* Writing a single-cell character over a double-cell
5099 * character: need to redraw the next cell. */
5100 ScreenLines
[off_to
+ 1] = 0;
5103 else if (char_cells
== 2
5105 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5106 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)
5108 /* Writing the second half of a double-cell character over
5109 * a double-cell character: need to redraw the second
5111 ScreenLines
[off_to
+ 2] = 0;
5115 if (enc_dbcs
== DBCS_JPNU
)
5116 ScreenLines2
[off_to
] = ScreenLines2
[off_from
];
5118 /* When writing a single-width character over a double-width
5119 * character and at the end of the redrawn text, need to clear out
5120 * the right halve of the old character.
5121 * Also required when writing the right halve of a double-width
5122 * char over the left halve of an existing one. */
5123 if (has_mbyte
&& col
+ char_cells
== endcol
5124 && ((char_cells
== 1
5125 && (*mb_off2cells
)(off_to
, max_off_to
) > 1)
5127 && (*mb_off2cells
)(off_to
, max_off_to
) == 1
5128 && (*mb_off2cells
)(off_to
+ 1, max_off_to
) > 1)))
5132 ScreenLines
[off_to
] = ScreenLines
[off_from
];
5136 ScreenLinesUC
[off_to
] = ScreenLinesUC
[off_from
];
5137 if (ScreenLinesUC
[off_from
] != 0)
5141 for (i
= 0; i
< Screen_mco
; ++i
)
5142 ScreenLinesC
[i
][off_to
] = ScreenLinesC
[i
][off_from
];
5145 if (char_cells
== 2)
5146 ScreenLines
[off_to
+ 1] = ScreenLines
[off_from
+ 1];
5149 #if defined(FEAT_GUI) || defined(UNIX)
5150 /* The bold trick makes a single row of pixels appear in the next
5151 * character. When a bold character is removed, the next
5152 * character should be redrawn too. This happens for our own GUI
5153 * and for some xterms. */
5158 # if defined(FEAT_GUI) && defined(UNIX)
5166 hl
= ScreenAttrs
[off_to
];
5168 hl
= syn_attr2attr(hl
);
5173 ScreenAttrs
[off_to
] = ScreenAttrs
[off_from
];
5175 /* For simplicity set the attributes of second half of a
5176 * double-wide character equal to the first half. */
5177 if (char_cells
== 2)
5178 ScreenAttrs
[off_to
+ 1] = ScreenAttrs
[off_from
];
5180 if (enc_dbcs
!= 0 && char_cells
== 2)
5181 screen_char_2(off_to
, row
, col
+ coloff
);
5184 screen_char(off_to
, row
, col
+ coloff
);
5190 && col
+ coloff
> 0)
5192 if (ScreenAttrs
[off_to
] == ScreenAttrs
[off_to
- 1])
5195 * Don't output stop-highlight when moving the cursor, it will
5196 * stop the highlighting when it should continue.
5200 else if (screen_attr
!= 0)
5201 screen_stop_highlight();
5204 off_to
+= CHAR_CELLS
;
5205 off_from
+= CHAR_CELLS
;
5212 /* Clear the second half of a double-wide character of which the left
5213 * half was overwritten with a single-wide character. */
5214 ScreenLines
[off_to
] = ' ';
5216 ScreenLinesUC
[off_to
] = 0;
5217 screen_char(off_to
, row
, col
+ coloff
);
5222 #ifdef FEAT_RIGHTLEFT
5231 /* blank out the rest of the line */
5232 while (col
< clear_width
&& ScreenLines
[off_to
] == ' '
5233 && ScreenAttrs
[off_to
] == 0
5235 && (!enc_utf8
|| ScreenLinesUC
[off_to
] == 0)
5242 if (col
< clear_width
)
5246 * In the GUI, clearing the rest of the line may leave pixels
5247 * behind if the first character cleared was bold. Some bold
5248 * fonts spill over the left. In this case we redraw the previous
5249 * character too. If we didn't skip any blanks above, then we
5250 * only redraw if the character wasn't already redrawn anyway.
5252 if (gui
.in_use
&& (col
> startCol
|| !redraw_this
))
5254 hl
= ScreenAttrs
[off_to
];
5255 if (hl
> HL_ALL
|| (hl
& HL_BOLD
))
5260 /* for utf-8, ScreenLines[char_offset + 1] == 0 means
5261 * that its width is 2. */
5262 prev_cells
= ScreenLines
[off_to
- 1] == 0 ? 2 : 1;
5263 else if (enc_dbcs
!= 0)
5265 /* find previous character by counting from first
5266 * column and get its width. */
5267 unsigned off
= LineOffset
[row
];
5268 unsigned max_off
= LineOffset
[row
] + screen_Columns
;
5270 while (off
< off_to
)
5272 prev_cells
= (*mb_off2cells
)(off
, max_off
);
5277 if (enc_dbcs
!= 0 && prev_cells
> 1)
5278 screen_char_2(off_to
- prev_cells
, row
,
5279 col
+ coloff
- prev_cells
);
5282 screen_char(off_to
- prev_cells
, row
,
5283 col
+ coloff
- prev_cells
);
5287 screen_fill(row
, row
+ 1, col
+ coloff
, clear_width
+ coloff
,
5289 #ifdef FEAT_VERTSPLIT
5290 off_to
+= clear_width
- col
;
5296 if (clear_width
> 0)
5298 #ifdef FEAT_VERTSPLIT
5299 /* For a window that's left of another, draw the separator char. */
5300 if (col
+ coloff
< Columns
)
5304 c
= fillchar_vsep(&hl
);
5305 if (ScreenLines
[off_to
] != c
5307 || (enc_utf8
&& (int)ScreenLinesUC
[off_to
]
5308 != (c
>= 0x80 ? c
: 0))
5310 || ScreenAttrs
[off_to
] != hl
)
5312 ScreenLines
[off_to
] = c
;
5313 ScreenAttrs
[off_to
] = hl
;
5319 ScreenLinesUC
[off_to
] = c
;
5320 ScreenLinesC
[0][off_to
] = 0;
5323 ScreenLinesUC
[off_to
] = 0;
5326 screen_char(off_to
, row
, col
+ coloff
);
5331 LineWraps
[row
] = FALSE
;
5335 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
5337 * Mirror text "str" for right-left displaying.
5338 * Only works for single-byte characters (e.g., numbers).
5347 for (p1
= str
, p2
= str
+ STRLEN(str
) - 1; p1
< p2
; ++p1
, --p2
)
5356 #if defined(FEAT_WINDOWS) || defined(PROTO)
5358 * mark all status lines for redraw; used after first :cd
5365 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5366 if (wp
->w_status_height
)
5368 wp
->w_redr_status
= TRUE
;
5369 redraw_later(VALID
);
5374 * mark all status lines of the current buffer for redraw
5377 status_redraw_curbuf()
5381 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5382 if (wp
->w_status_height
!= 0 && wp
->w_buffer
== curbuf
)
5384 wp
->w_redr_status
= TRUE
;
5385 redraw_later(VALID
);
5390 * Redraw all status lines that need to be redrawn.
5393 redraw_statuslines()
5397 for (wp
= firstwin
; wp
; wp
= wp
->w_next
)
5398 if (wp
->w_redr_status
)
5399 win_redr_status(wp
);
5405 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO)
5407 * Redraw all status lines at the bottom of frame "frp".
5410 win_redraw_last_status(frp
)
5413 if (frp
->fr_layout
== FR_LEAF
)
5414 frp
->fr_win
->w_redr_status
= TRUE
;
5415 else if (frp
->fr_layout
== FR_ROW
)
5417 for (frp
= frp
->fr_child
; frp
!= NULL
; frp
= frp
->fr_next
)
5418 win_redraw_last_status(frp
);
5420 else /* frp->fr_layout == FR_COL */
5422 frp
= frp
->fr_child
;
5423 while (frp
->fr_next
!= NULL
)
5425 win_redraw_last_status(frp
);
5430 #ifdef FEAT_VERTSPLIT
5432 * Draw the verticap separator right of window "wp" starting with line "row".
5435 draw_vsep_win(wp
, row
)
5442 if (wp
->w_vsep_width
)
5444 /* draw the vertical separator right of this window */
5445 c
= fillchar_vsep(&hl
);
5446 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
5447 W_ENDCOL(wp
), W_ENDCOL(wp
) + 1,
5453 #ifdef FEAT_WILDMENU
5454 static int status_match_len
__ARGS((expand_T
*xp
, char_u
*s
));
5455 static int skip_status_match_char
__ARGS((expand_T
*xp
, char_u
*s
));
5458 * Get the length of an item as it will be shown in the status line.
5461 status_match_len(xp
, s
)
5468 int emenu
= (xp
->xp_context
== EXPAND_MENUS
5469 || xp
->xp_context
== EXPAND_MENUNAMES
);
5471 /* Check for menu separators - replace with '|'. */
5472 if (emenu
&& menu_is_separator(s
))
5478 s
+= skip_status_match_char(xp
, s
);
5479 len
+= ptr2cells(s
);
5487 * Return the number of characters that should be skipped in a status match.
5488 * These are backslashes used for escaping. Do show backslashes in help tags.
5491 skip_status_match_char(xp
, s
)
5495 if ((rem_backslash(s
) && xp
->xp_context
!= EXPAND_HELP
)
5497 || ((xp
->xp_context
== EXPAND_MENUS
5498 || xp
->xp_context
== EXPAND_MENUNAMES
)
5499 && (s
[0] == '\t' || (s
[0] == '\\' && s
[1] != NUL
)))
5503 #ifndef BACKSLASH_IN_FILENAME
5504 if (xp
->xp_shell
&& csh_like_shell() && s
[1] == '\\' && s
[2] == '!')
5513 * Show wildchar matches in the status line.
5514 * Show at least the "match" item.
5515 * We start at item 'first_match' in the list and show all matches that fit.
5517 * If inversion is possible we use it. Else '=' characters are used.
5520 win_redr_status_matches(xp
, num_matches
, matches
, match
, showtail
)
5523 char_u
**matches
; /* list of matches */
5527 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
5531 int clen
; /* length in screen cells */
5535 int highlight
= TRUE
;
5536 char_u
*selstart
= NULL
;
5537 int selstart_col
= 0;
5538 char_u
*selend
= NULL
;
5539 static int first_match
= 0;
5540 int add_left
= FALSE
;
5545 #if defined(FEAT_MBYTE) || defined(FEAT_MENU)
5549 if (matches
== NULL
) /* interrupted completion? */
5554 buf
= alloc((unsigned)Columns
* MB_MAXBYTES
+ 1);
5557 buf
= alloc((unsigned)Columns
+ 1);
5561 if (match
== -1) /* don't show match but original text */
5566 /* count 1 for the ending ">" */
5567 clen
= status_match_len(xp
, L_MATCH(match
)) + 3;
5570 else if (match
< first_match
)
5572 /* jumping left, as far as we can go */
5573 first_match
= match
;
5578 /* check if match fits on the screen */
5579 for (i
= first_match
; i
< match
; ++i
)
5580 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5581 if (first_match
> 0)
5583 /* jumping right, put match at the left */
5584 if ((long)clen
> Columns
)
5586 first_match
= match
;
5587 /* if showing the last match, we can add some on the left */
5589 for (i
= match
; i
< num_matches
; ++i
)
5591 clen
+= status_match_len(xp
, L_MATCH(i
)) + 2;
5592 if ((long)clen
>= Columns
)
5595 if (i
== num_matches
)
5600 while (first_match
> 0)
5602 clen
+= status_match_len(xp
, L_MATCH(first_match
- 1)) + 2;
5603 if ((long)clen
>= Columns
)
5608 fillchar
= fillchar_status(&attr
, TRUE
);
5610 if (first_match
== 0)
5623 while ((long)(clen
+ status_match_len(xp
, L_MATCH(i
)) + 2) < Columns
)
5627 selstart
= buf
+ len
;
5628 selstart_col
= clen
;
5632 /* Check for menu separators - replace with '|' */
5634 emenu
= (xp
->xp_context
== EXPAND_MENUS
5635 || xp
->xp_context
== EXPAND_MENUNAMES
);
5636 if (emenu
&& menu_is_separator(s
))
5638 STRCPY(buf
+ len
, transchar('|'));
5639 l
= (int)STRLEN(buf
+ len
);
5645 for ( ; *s
!= NUL
; ++s
)
5647 s
+= skip_status_match_char(xp
, s
);
5648 clen
+= ptr2cells(s
);
5650 if (has_mbyte
&& (l
= (*mb_ptr2len
)(s
)) > 1)
5652 STRNCPY(buf
+ len
, s
, l
);
5659 STRCPY(buf
+ len
, transchar_byte(*s
));
5660 len
+= (int)STRLEN(buf
+ len
);
5666 *(buf
+ len
++) = ' ';
5667 *(buf
+ len
++) = ' ';
5669 if (++i
== num_matches
)
5673 if (i
!= num_matches
)
5675 *(buf
+ len
++) = '>';
5681 row
= cmdline_row
- 1;
5684 if (wild_menu_showing
== 0)
5686 if (msg_scrolled
> 0)
5688 /* Put the wildmenu just above the command line. If there is
5689 * no room, scroll the screen one line up. */
5690 if (cmdline_row
== Rows
- 1)
5692 screen_del_lines(0, 0, 1, (int)Rows
, TRUE
, NULL
);
5700 wild_menu_showing
= WM_SCROLLED
;
5704 /* Create status line if needed by setting 'laststatus' to 2.
5705 * Set 'winminheight' to zero to avoid that the window is
5707 if (lastwin
->w_status_height
== 0)
5715 wild_menu_showing
= WM_SHOWN
;
5719 screen_puts(buf
, row
, 0, attr
);
5720 if (selstart
!= NULL
&& highlight
)
5723 screen_puts(selstart
, row
, selstart_col
, hl_attr(HLF_WM
));
5726 screen_fill(row
, row
+ 1, clen
, (int)Columns
, fillchar
, fillchar
, attr
);
5729 #ifdef FEAT_VERTSPLIT
5730 win_redraw_last_status(topframe
);
5732 lastwin
->w_redr_status
= TRUE
;
5738 #if defined(FEAT_WINDOWS) || defined(PROTO)
5740 * Redraw the status line of window wp.
5742 * If inversion is possible we use it. Else '=' characters are used.
5755 wp
->w_redr_status
= FALSE
;
5756 if (wp
->w_status_height
== 0)
5758 /* no status line, can only be last window */
5759 redraw_cmdline
= TRUE
;
5761 else if (!redrawing()
5762 #ifdef FEAT_INS_EXPAND
5763 /* don't update status line when popup menu is visible and may be
5769 /* Don't redraw right now, do it later. */
5770 wp
->w_redr_status
= TRUE
;
5773 else if (*p_stl
!= NUL
|| *wp
->w_p_stl
!= NUL
)
5775 /* redraw custom status line */
5776 redraw_custum_statusline(wp
);
5781 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5783 get_trans_bufname(wp
->w_buffer
);
5785 len
= (int)STRLEN(p
);
5787 if (wp
->w_buffer
->b_help
5788 #ifdef FEAT_QUICKFIX
5791 || bufIsChanged(wp
->w_buffer
)
5792 || wp
->w_buffer
->b_p_ro
)
5794 if (wp
->w_buffer
->b_help
)
5796 STRCPY(p
+ len
, _("[Help]"));
5797 len
+= (int)STRLEN(p
+ len
);
5799 #ifdef FEAT_QUICKFIX
5802 STRCPY(p
+ len
, _("[Preview]"));
5803 len
+= (int)STRLEN(p
+ len
);
5806 if (bufIsChanged(wp
->w_buffer
))
5808 STRCPY(p
+ len
, "[+]");
5811 if (wp
->w_buffer
->b_p_ro
)
5813 STRCPY(p
+ len
, "[RO]");
5817 #ifndef FEAT_VERTSPLIT
5818 this_ru_col
= ru_col
;
5819 if (this_ru_col
< (Columns
+ 1) / 2)
5820 this_ru_col
= (Columns
+ 1) / 2;
5822 this_ru_col
= ru_col
- (Columns
- W_WIDTH(wp
));
5823 if (this_ru_col
< (W_WIDTH(wp
) + 1) / 2)
5824 this_ru_col
= (W_WIDTH(wp
) + 1) / 2;
5825 if (this_ru_col
<= 1)
5827 p
= (char_u
*)"<"; /* No room for file name! */
5837 /* Count total number of display cells. */
5838 for (i
= 0; p
[i
] != NUL
; i
+= (*mb_ptr2len
)(p
+ i
))
5839 clen
+= (*mb_ptr2cells
)(p
+ i
);
5840 /* Find first character that will fit.
5841 * Going from start to end is much faster for DBCS. */
5842 for (i
= 0; p
[i
] != NUL
&& clen
>= this_ru_col
- 1;
5843 i
+= (*mb_ptr2len
)(p
+ i
))
5844 clen
-= (*mb_ptr2cells
)(p
+ i
);
5856 if (len
> this_ru_col
- 1)
5858 p
+= len
- (this_ru_col
- 1);
5860 len
= this_ru_col
- 1;
5863 row
= W_WINROW(wp
) + wp
->w_height
;
5864 screen_puts(p
, row
, W_WINCOL(wp
), attr
);
5865 screen_fill(row
, row
+ 1, len
+ W_WINCOL(wp
),
5866 this_ru_col
+ W_WINCOL(wp
), fillchar
, fillchar
, attr
);
5868 if (get_keymap_str(wp
, NameBuff
, MAXPATHL
)
5869 && (int)(this_ru_col
- len
) > (int)(STRLEN(NameBuff
) + 1))
5870 screen_puts(NameBuff
, row
, (int)(this_ru_col
- STRLEN(NameBuff
)
5871 - 1 + W_WINCOL(wp
)), attr
);
5873 #ifdef FEAT_CMDL_INFO
5874 win_redr_ruler(wp
, TRUE
);
5878 #ifdef FEAT_VERTSPLIT
5880 * May need to draw the character below the vertical separator.
5882 if (wp
->w_vsep_width
!= 0 && wp
->w_status_height
!= 0 && redrawing())
5884 if (stl_connected(wp
))
5885 fillchar
= fillchar_status(&attr
, wp
== curwin
);
5887 fillchar
= fillchar_vsep(&attr
);
5888 screen_putchar(fillchar
, W_WINROW(wp
) + wp
->w_height
, W_ENDCOL(wp
),
5896 * Redraw the status line according to 'statusline' and take care of any
5897 * errors encountered.
5900 redraw_custum_statusline(wp
)
5903 int save_called_emsg
= called_emsg
;
5905 called_emsg
= FALSE
;
5906 win_redr_custom(wp
, FALSE
);
5908 set_string_option_direct((char_u
*)"statusline", -1,
5909 (char_u
*)"", OPT_FREE
| (*wp
->w_p_stl
!= NUL
5910 ? OPT_LOCAL
: OPT_GLOBAL
), SID_ERROR
);
5911 called_emsg
|= save_called_emsg
;
5915 # ifdef FEAT_VERTSPLIT
5917 * Return TRUE if the status line of window "wp" is connected to the status
5918 * line of the window right of it. If not, then it's a vertical separator.
5919 * Only call if (wp->w_vsep_width != 0).
5928 while (fr
->fr_parent
!= NULL
)
5930 if (fr
->fr_parent
->fr_layout
== FR_COL
)
5932 if (fr
->fr_next
!= NULL
)
5937 if (fr
->fr_next
!= NULL
)
5946 #endif /* FEAT_WINDOWS */
5948 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO)
5950 * Get the value to show for the language mappings, active 'keymap'.
5953 get_keymap_str(wp
, buf
, len
)
5955 char_u
*buf
; /* buffer for the result */
5956 int len
; /* length of buffer */
5960 if (wp
->w_buffer
->b_p_iminsert
!= B_IMODE_LMAP
)
5965 buf_T
*old_curbuf
= curbuf
;
5966 win_T
*old_curwin
= curwin
;
5969 curbuf
= wp
->w_buffer
;
5971 STRCPY(buf
, "b:keymap_name"); /* must be writable */
5973 s
= p
= eval_to_string(buf
, NULL
, FALSE
);
5975 curbuf
= old_curbuf
;
5976 curwin
= old_curwin
;
5977 if (p
== NULL
|| *p
== NUL
)
5981 if (wp
->w_buffer
->b_kmap_state
& KEYMAP_LOADED
)
5982 p
= wp
->w_buffer
->b_p_keymap
;
5985 p
= (char_u
*)"lang";
5987 if ((int)(STRLEN(p
) + 3) < len
)
5988 sprintf((char *)buf
, "<%s>", p
);
5995 return buf
[0] != NUL
;
5999 #if defined(FEAT_STL_OPT) || defined(PROTO)
6001 * Redraw the status line or ruler of window "wp".
6002 * When "wp" is NULL redraw the tab pages line from 'tabline'.
6005 win_redr_custom(wp
, draw_ruler
)
6007 int draw_ruler
; /* TRUE or FALSE */
6018 char_u buf
[MAXPATHL
];
6020 struct stl_hlrec hltab
[STL_MAX_ITEM
];
6021 struct stl_hlrec tabtab
[STL_MAX_ITEM
];
6022 int use_sandbox
= FALSE
;
6024 /* setup environment for the task at hand */
6027 /* Use 'tabline'. Always at the first line of the screen. */
6031 attr
= hl_attr(HLF_TPF
);
6034 use_sandbox
= was_set_insecurely((char_u
*)"tabline", 0);
6039 row
= W_WINROW(wp
) + wp
->w_height
;
6040 fillchar
= fillchar_status(&attr
, wp
== curwin
);
6041 maxwidth
= W_WIDTH(wp
);
6046 /* advance past any leading group spec - implicit in ru_col */
6051 if (atoi((char *) p
))
6052 while (VIM_ISDIGIT(*p
))
6057 #ifdef FEAT_VERTSPLIT
6058 col
= ru_col
- (Columns
- W_WIDTH(wp
));
6059 if (col
< (W_WIDTH(wp
) + 1) / 2)
6060 col
= (W_WIDTH(wp
) + 1) / 2;
6063 if (col
> (Columns
+ 1) / 2)
6064 col
= (Columns
+ 1) / 2;
6066 maxwidth
= W_WIDTH(wp
) - col
;
6068 if (!wp
->w_status_height
)
6072 --maxwidth
; /* writing in last column may cause scrolling */
6078 use_sandbox
= was_set_insecurely((char_u
*)"rulerformat", 0);
6083 if (*wp
->w_p_stl
!= NUL
)
6088 use_sandbox
= was_set_insecurely((char_u
*)"statusline",
6089 *wp
->w_p_stl
== NUL
? 0 : OPT_LOCAL
);
6093 #ifdef FEAT_VERTSPLIT
6094 col
+= W_WINCOL(wp
);
6101 width
= build_stl_str_hl(wp
== NULL
? curwin
: wp
,
6104 fillchar
, maxwidth
, hltab
, tabtab
);
6105 len
= (int)STRLEN(buf
);
6107 while (width
< maxwidth
&& len
< sizeof(buf
) - 1)
6110 len
+= (*mb_char2bytes
)(fillchar
, buf
+ len
);
6112 buf
[len
++] = fillchar
;
6119 * Draw each snippet with the specified highlighting.
6123 for (n
= 0; hltab
[n
].start
!= NULL
; n
++)
6125 len
= (int)(hltab
[n
].start
- p
);
6126 screen_puts_len(p
, len
, row
, col
, curattr
);
6127 col
+= vim_strnsize(p
, len
);
6130 if (hltab
[n
].userhl
== 0)
6132 else if (hltab
[n
].userhl
< 0)
6133 curattr
= syn_id2attr(-hltab
[n
].userhl
);
6135 else if (wp
!= NULL
&& wp
!= curwin
&& wp
->w_status_height
!= 0)
6136 curattr
= highlight_stlnc
[hltab
[n
].userhl
- 1];
6139 curattr
= highlight_user
[hltab
[n
].userhl
- 1];
6141 screen_puts(p
, row
, col
, curattr
);
6145 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */
6150 for (n
= 0; tabtab
[n
].start
!= NULL
; n
++)
6152 len
+= vim_strnsize(p
, (int)(tabtab
[n
].start
- p
));
6154 TabPageIdxs
[col
++] = fillchar
;
6155 p
= tabtab
[n
].start
;
6156 fillchar
= tabtab
[n
].userhl
;
6158 while (col
< Columns
)
6159 TabPageIdxs
[col
++] = fillchar
;
6163 #endif /* FEAT_STL_OPT */
6166 * Output a single character directly to the screen and update ScreenLines.
6169 screen_putchar(c
, row
, col
, attr
)
6175 char_u buf
[MB_MAXBYTES
+ 1];
6177 buf
[(*mb_char2bytes
)(c
, buf
)] = NUL
;
6184 screen_puts(buf
, row
, col
, attr
);
6188 * Get a single character directly from ScreenLines into "bytes[]".
6189 * Also return its attribute in *attrp;
6192 screen_getbytes(row
, col
, bytes
, attrp
)
6200 if (ScreenLines
!= NULL
&& row
< screen_Rows
&& col
< screen_Columns
)
6202 off
= LineOffset
[row
] + col
;
6203 *attrp
= ScreenAttrs
[off
];
6204 bytes
[0] = ScreenLines
[off
];
6208 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6209 bytes
[utfc_char2bytes(off
, bytes
)] = NUL
;
6210 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6212 bytes
[0] = ScreenLines
[off
];
6213 bytes
[1] = ScreenLines2
[off
];
6216 else if (enc_dbcs
&& MB_BYTE2LEN(bytes
[0]) > 1)
6218 bytes
[1] = ScreenLines
[off
+ 1];
6226 static int screen_comp_differs
__ARGS((int, int*));
6229 * Return TRUE if composing characters for screen posn "off" differs from
6230 * composing characters in "u8cc".
6233 screen_comp_differs(off
, u8cc
)
6239 for (i
= 0; i
< Screen_mco
; ++i
)
6241 if (ScreenLinesC
[i
][off
] != (u8char_T
)u8cc
[i
])
6251 * Put string '*text' on the screen at position 'row' and 'col', with
6252 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[].
6253 * Note: only outputs within one row, message is truncated at screen boundary!
6254 * Note: if ScreenLines[], row and/or col is invalid, nothing is done.
6257 screen_puts(text
, row
, col
, attr
)
6263 screen_puts_len(text
, -1, row
, col
, attr
);
6267 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to
6271 screen_puts_len(text
, len
, row
, col
, attr
)
6284 int mbyte_cells
= 1;
6287 int clear_next_cell
= FALSE
;
6289 int prev_c
= 0; /* previous Arabic character */
6295 if (ScreenLines
== NULL
|| row
>= screen_Rows
) /* safety check */
6299 /* When drawing over the right halve of a double-wide char clear out the
6300 * left halve. Only needed in a terminal. */
6301 if (has_mbyte
&& col
> 0 && col
< screen_Columns
6305 && mb_fix_col(col
, row
) != col
)
6306 screen_puts_len((char_u
*)" ", 1, row
, col
- 1, 0);
6309 off
= LineOffset
[row
] + col
;
6311 max_off
= LineOffset
[row
] + screen_Columns
;
6313 while (col
< screen_Columns
6314 && (len
< 0 || (int)(ptr
- text
) < len
)
6319 /* check if this is the first byte of a multibyte */
6322 if (enc_utf8
&& len
> 0)
6323 mbyte_blen
= utfc_ptr2len_len(ptr
, (int)((text
+ len
) - ptr
));
6325 mbyte_blen
= (*mb_ptr2len
)(ptr
);
6326 if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6328 else if (enc_dbcs
!= 0)
6329 mbyte_cells
= mbyte_blen
;
6333 u8c
= utfc_ptr2char_len(ptr
, u8cc
,
6334 (int)((text
+ len
) - ptr
));
6336 u8c
= utfc_ptr2char(ptr
, u8cc
);
6337 mbyte_cells
= utf_char2cells(u8c
);
6339 /* Non-BMP character: display as ? or fullwidth ?. */
6342 u8c
= (mbyte_cells
== 2) ? 0xff1f : (int)'?';
6344 attr
= hl_attr(HLF_8
);
6348 if (p_arshape
&& !p_tbidi
&& ARABIC_CHAR(u8c
))
6350 /* Do Arabic shaping. */
6351 if (len
>= 0 && (int)(ptr
- text
) + mbyte_blen
>= len
)
6353 /* Past end of string to be displayed. */
6359 nc
= utfc_ptr2char(ptr
+ mbyte_blen
, pcc
);
6364 u8c
= arabic_shape(u8c
, &c
, &u8cc
[0], nc
, nc1
, pc
);
6373 if (ScreenLines
[off
] != c
6375 || (mbyte_cells
== 2
6376 && ScreenLines
[off
+ 1] != (enc_dbcs
? ptr
[1] : 0))
6377 || (enc_dbcs
== DBCS_JPNU
6379 && ScreenLines2
[off
] != ptr
[1])
6381 && (ScreenLinesUC
[off
] != (u8char_T
)u8c
6382 || screen_comp_differs(off
, u8cc
)))
6384 || ScreenAttrs
[off
] != attr
6388 #if defined(FEAT_GUI) || defined(UNIX)
6389 /* The bold trick makes a single row of pixels appear in the next
6390 * character. When a bold character is removed, the next
6391 * character should be redrawn too. This happens for our own GUI
6392 * and for some xterms.
6393 * Force the redraw by setting the attribute to a different value
6394 * than "attr", the contents of ScreenLines[] may be needed by
6395 * mb_off2cells() further on.
6396 * Don't do this for the last drawn character, because the next
6397 * character may not be redrawn. */
6402 # if defined(FEAT_GUI) && defined(UNIX)
6412 n
= ScreenAttrs
[off
];
6414 if (col
+ mbyte_cells
< screen_Columns
6415 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6416 && (len
< 0 ? ptr
[mbyte_blen
] != NUL
6417 : ptr
+ mbyte_blen
< text
+ len
))
6418 ScreenAttrs
[off
+ mbyte_cells
] = attr
+ 1;
6420 if (col
+ 1 < screen_Columns
6421 && (n
> HL_ALL
|| (n
& HL_BOLD
))
6422 && (len
< 0 ? ptr
[1] != NUL
: ptr
+ 1 < text
+ len
))
6423 ScreenLines
[off
+ 1] = 0;
6428 /* When at the end of the text and overwriting a two-cell
6429 * character with a one-cell character, need to clear the next
6430 * cell. Also when overwriting the left halve of a two-cell char
6431 * with the right halve of a two-cell char. Do this only once
6432 * (mb_off2cells() may return 2 on the right halve). */
6433 if (clear_next_cell
)
6434 clear_next_cell
= FALSE
;
6436 && (len
< 0 ? ptr
[mbyte_blen
] == NUL
6437 : ptr
+ mbyte_blen
>= text
+ len
)
6438 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6439 || (mbyte_cells
== 2
6440 && (*mb_off2cells
)(off
, max_off
) == 1
6441 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6442 clear_next_cell
= TRUE
;
6444 /* Make sure we never leave a second byte of a double-byte behind,
6445 * it confuses mb_off2cells(). */
6447 && ((mbyte_cells
== 1 && (*mb_off2cells
)(off
, max_off
) > 1)
6448 || (mbyte_cells
== 2
6449 && (*mb_off2cells
)(off
, max_off
) == 1
6450 && (*mb_off2cells
)(off
+ 1, max_off
) > 1)))
6451 ScreenLines
[off
+ mbyte_blen
] = 0;
6453 ScreenLines
[off
] = c
;
6454 ScreenAttrs
[off
] = attr
;
6458 if (c
< 0x80 && u8cc
[0] == 0)
6459 ScreenLinesUC
[off
] = 0;
6464 ScreenLinesUC
[off
] = u8c
;
6465 for (i
= 0; i
< Screen_mco
; ++i
)
6467 ScreenLinesC
[i
][off
] = u8cc
[i
];
6472 if (mbyte_cells
== 2)
6474 ScreenLines
[off
+ 1] = 0;
6475 ScreenAttrs
[off
+ 1] = attr
;
6477 screen_char(off
, row
, col
);
6479 else if (mbyte_cells
== 2)
6481 ScreenLines
[off
+ 1] = ptr
[1];
6482 ScreenAttrs
[off
+ 1] = attr
;
6483 screen_char_2(off
, row
, col
);
6485 else if (enc_dbcs
== DBCS_JPNU
&& c
== 0x8e)
6487 ScreenLines2
[off
] = ptr
[1];
6488 screen_char(off
, row
, col
);
6492 screen_char(off
, row
, col
);
6500 if (clear_next_cell
)
6501 ptr
= (char_u
*)" ";
6513 #ifdef FEAT_SEARCH_EXTRA
6515 * Prepare for 'hlsearch' highlighting.
6520 if (p_hls
&& !no_hlsearch
)
6522 last_pat_prog(&search_hl
.rm
);
6523 search_hl
.attr
= hl_attr(HLF_L
);
6524 # ifdef FEAT_RELTIME
6525 /* Set the time limit to 'redrawtime'. */
6526 profile_setlimit(p_rdt
, &search_hl
.tm
);
6532 * Clean up for 'hlsearch' highlighting.
6537 if (search_hl
.rm
.regprog
!= NULL
)
6539 vim_free(search_hl
.rm
.regprog
);
6540 search_hl
.rm
.regprog
= NULL
;
6545 * Advance to the match in window "wp" line "lnum" or past it.
6548 prepare_search_hl(wp
, lnum
)
6552 matchitem_T
*cur
; /* points to the match list */
6553 match_T
*shl
; /* points to search_hl or a match */
6554 int shl_flag
; /* flag to indicate whether search_hl
6555 has been processed or not */
6559 * When using a multi-line pattern, start searching at the top
6560 * of the window or just after a closed fold.
6561 * Do this both for search_hl and the match list.
6563 cur
= wp
->w_match_head
;
6565 while (cur
!= NULL
|| shl_flag
== FALSE
)
6567 if (shl_flag
== FALSE
)
6574 if (shl
->rm
.regprog
!= NULL
6576 && re_multiline(shl
->rm
.regprog
))
6578 if (shl
->first_lnum
== 0)
6580 # ifdef FEAT_FOLDING
6581 for (shl
->first_lnum
= lnum
;
6582 shl
->first_lnum
> wp
->w_topline
; --shl
->first_lnum
)
6583 if (hasFoldingWin(wp
, shl
->first_lnum
- 1,
6584 NULL
, NULL
, TRUE
, NULL
))
6587 shl
->first_lnum
= wp
->w_topline
;
6591 while (shl
->first_lnum
< lnum
&& shl
->rm
.regprog
!= NULL
)
6593 next_search_hl(wp
, shl
, shl
->first_lnum
, (colnr_T
)n
);
6596 shl
->first_lnum
= shl
->lnum
6597 + shl
->rm
.endpos
[0].lnum
6598 - shl
->rm
.startpos
[0].lnum
;
6599 n
= shl
->rm
.endpos
[0].col
;
6608 if (shl
!= &search_hl
&& cur
!= NULL
)
6614 * Search for a next 'hlsearch' or match.
6616 * Sets shl->lnum and shl->rm contents.
6617 * Note: Assumes a previous match is always before "lnum", unless
6618 * shl->lnum is zero.
6619 * Careful: Any pointers for buffer lines will become invalid.
6622 next_search_hl(win
, shl
, lnum
, mincol
)
6624 match_T
*shl
; /* points to search_hl or a match */
6626 colnr_T mincol
; /* minimal column for a match */
6634 /* Check for three situations:
6635 * 1. If the "lnum" is below a previous match, start a new search.
6636 * 2. If the previous match includes "mincol", use it.
6637 * 3. Continue after the previous match.
6639 l
= shl
->lnum
+ shl
->rm
.endpos
[0].lnum
- shl
->rm
.startpos
[0].lnum
;
6642 else if (lnum
< l
|| shl
->rm
.endpos
[0].col
> mincol
)
6647 * Repeat searching for a match until one is found that includes "mincol"
6648 * or none is found in this line.
6650 called_emsg
= FALSE
;
6654 /* Stop searching after passing the time limit. */
6655 if (profile_passed_limit(&(shl
->tm
)))
6657 shl
->lnum
= 0; /* no match found in time */
6661 /* Three situations:
6662 * 1. No useful previous match: search from start of line.
6663 * 2. Not Vi compatible or empty match: continue at next character.
6664 * Break the loop if this is beyond the end of the line.
6665 * 3. Vi compatible searching: continue at end of previous match.
6669 else if (vim_strchr(p_cpo
, CPO_SEARCH
) == NULL
6670 || (shl
->rm
.endpos
[0].lnum
== 0
6671 && shl
->rm
.endpos
[0].col
<= shl
->rm
.startpos
[0].col
))
6675 matchcol
= shl
->rm
.startpos
[0].col
;
6676 ml
= ml_get_buf(shl
->buf
, lnum
, FALSE
) + matchcol
;
6685 matchcol
+= mb_ptr2len(ml
);
6691 matchcol
= shl
->rm
.endpos
[0].col
;
6694 nmatched
= vim_regexec_multi(&shl
->rm
, win
, shl
->buf
, lnum
, matchcol
,
6703 /* Error while handling regexp: stop using this regexp. */
6704 if (shl
== &search_hl
)
6706 /* don't free regprog in the match list, it's a copy */
6707 vim_free(shl
->rm
.regprog
);
6710 shl
->rm
.regprog
= NULL
;
6712 got_int
= FALSE
; /* avoid the "Type :quit to exit Vim" message */
6717 shl
->lnum
= 0; /* no match found */
6720 if (shl
->rm
.startpos
[0].lnum
> 0
6721 || shl
->rm
.startpos
[0].col
>= mincol
6723 || shl
->rm
.endpos
[0].col
> mincol
)
6725 shl
->lnum
+= shl
->rm
.startpos
[0].lnum
;
6726 break; /* useful match found */
6733 screen_start_highlight(attr
)
6736 attrentry_T
*aep
= NULL
;
6750 /* The GUI handles this internally. */
6751 sprintf(buf
, IF_EB("\033|%dh", ESC_STR
"|%dh"), attr
);
6757 if (attr
> HL_ALL
) /* special HL attr. */
6760 aep
= syn_cterm_attr2entry(attr
);
6762 aep
= syn_term_attr2entry(attr
);
6763 if (aep
== NULL
) /* did ":syntax clear" */
6766 attr
= aep
->ae_attr
;
6768 if ((attr
& HL_BOLD
) && T_MD
!= NULL
) /* bold */
6770 else if (aep
!= NULL
&& t_colors
> 1 && aep
->ae_u
.cterm
.fg_color
6771 && cterm_normal_fg_bold
)
6772 /* If the Normal FG color has BOLD attribute and the new HL
6773 * has a FG color defined, clear BOLD. */
6775 if ((attr
& HL_STANDOUT
) && T_SO
!= NULL
) /* standout */
6777 if ((attr
& (HL_UNDERLINE
| HL_UNDERCURL
)) && T_US
!= NULL
)
6778 /* underline or undercurl */
6780 if ((attr
& HL_ITALIC
) && T_CZH
!= NULL
) /* italic */
6782 if ((attr
& HL_INVERSE
) && T_MR
!= NULL
) /* inverse (reverse) */
6786 * Output the color or start string after bold etc., in case the
6787 * bold etc. override the color setting.
6793 if (aep
->ae_u
.cterm
.fg_color
)
6794 term_fg_color(aep
->ae_u
.cterm
.fg_color
- 1);
6795 if (aep
->ae_u
.cterm
.bg_color
)
6796 term_bg_color(aep
->ae_u
.cterm
.bg_color
- 1);
6800 if (aep
->ae_u
.term
.start
!= NULL
)
6801 out_str(aep
->ae_u
.term
.start
);
6809 screen_stop_highlight()
6811 int do_ME
= FALSE
; /* output T_ME code */
6813 if (screen_attr
!= 0
6824 /* use internal GUI code */
6825 sprintf(buf
, IF_EB("\033|%dH", ESC_STR
"|%dH"), screen_attr
);
6831 if (screen_attr
> HL_ALL
) /* special HL attr. */
6838 * Assume that t_me restores the original colors!
6840 aep
= syn_cterm_attr2entry(screen_attr
);
6841 if (aep
!= NULL
&& (aep
->ae_u
.cterm
.fg_color
6842 || aep
->ae_u
.cterm
.bg_color
))
6847 aep
= syn_term_attr2entry(screen_attr
);
6848 if (aep
!= NULL
&& aep
->ae_u
.term
.stop
!= NULL
)
6850 if (STRCMP(aep
->ae_u
.term
.stop
, T_ME
) == 0)
6853 out_str(aep
->ae_u
.term
.stop
);
6856 if (aep
== NULL
) /* did ":syntax clear" */
6859 screen_attr
= aep
->ae_attr
;
6863 * Often all ending-codes are equal to T_ME. Avoid outputting the
6864 * same sequence several times.
6866 if (screen_attr
& HL_STANDOUT
)
6868 if (STRCMP(T_SE
, T_ME
) == 0)
6873 if (screen_attr
& (HL_UNDERLINE
| HL_UNDERCURL
))
6875 if (STRCMP(T_UE
, T_ME
) == 0)
6880 if (screen_attr
& HL_ITALIC
)
6882 if (STRCMP(T_CZR
, T_ME
) == 0)
6887 if (do_ME
|| (screen_attr
& (HL_BOLD
| HL_INVERSE
)))
6892 /* set Normal cterm colors */
6893 if (cterm_normal_fg_color
!= 0)
6894 term_fg_color(cterm_normal_fg_color
- 1);
6895 if (cterm_normal_bg_color
!= 0)
6896 term_bg_color(cterm_normal_bg_color
- 1);
6897 if (cterm_normal_fg_bold
)
6906 * Reset the colors for a cterm. Used when leaving Vim.
6907 * The machine specific code may override this again.
6910 reset_cterm_colors()
6914 /* set Normal cterm colors */
6915 if (cterm_normal_fg_color
> 0 || cterm_normal_bg_color
> 0)
6920 if (cterm_normal_fg_bold
)
6929 * Put character ScreenLines["off"] on the screen at position "row" and "col",
6930 * using the attributes from ScreenAttrs["off"].
6933 screen_char(off
, row
, col
)
6940 /* Check for illegal values, just in case (could happen just after
6942 if (row
>= screen_Rows
|| col
>= screen_Columns
)
6945 /* Outputting the last character on the screen may scrollup the screen.
6946 * Don't to it! Mark the character invalid (update it when scrolled up) */
6947 if (row
== screen_Rows
- 1 && col
== screen_Columns
- 1
6948 #ifdef FEAT_RIGHTLEFT
6949 /* account for first command-line character in rightleft mode */
6954 ScreenAttrs
[off
] = (sattr_T
)-1;
6959 * Stop highlighting first, so it's easier to move the cursor.
6961 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT)
6962 if (screen_char_attr
!= 0)
6963 attr
= screen_char_attr
;
6966 attr
= ScreenAttrs
[off
];
6967 if (screen_attr
!= attr
)
6968 screen_stop_highlight();
6972 if (screen_attr
!= attr
)
6973 screen_start_highlight(attr
);
6976 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
6978 char_u buf
[MB_MAXBYTES
+ 1];
6980 /* Convert UTF-8 character to bytes and write it. */
6982 buf
[utfc_char2bytes(off
, buf
)] = NUL
;
6985 if (utf_char2cells(ScreenLinesUC
[off
]) > 1)
6994 out_char(ScreenLines
[off
]);
6996 /* double-byte character in single-width cell */
6997 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
6998 out_char(ScreenLines2
[off
]);
7008 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"]
7009 * on the screen at position 'row' and 'col'.
7010 * The attributes of the first byte is used for all. This is required to
7011 * output the two bytes of a double-byte character with nothing in between.
7014 screen_char_2(off
, row
, col
)
7019 /* Check for illegal values (could be wrong when screen was resized). */
7020 if (off
+ 1 >= (unsigned)(screen_Rows
* screen_Columns
))
7023 /* Outputting the last character on the screen may scrollup the screen.
7024 * Don't to it! Mark the character invalid (update it when scrolled up) */
7025 if (row
== screen_Rows
- 1 && col
>= screen_Columns
- 2)
7027 ScreenAttrs
[off
] = (sattr_T
)-1;
7031 /* Output the first byte normally (positions the cursor), then write the
7032 * second byte directly. */
7033 screen_char(off
, row
, col
);
7034 out_char(ScreenLines
[off
+ 1]);
7039 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO)
7041 * Draw a rectangle of the screen, inverted when "invert" is TRUE.
7042 * This uses the contents of ScreenLines[] and doesn't change it.
7045 screen_draw_rectangle(row
, col
, height
, width
, invert
)
7058 /* Can't use ScreenLines unless initialized */
7059 if (ScreenLines
== NULL
)
7063 screen_char_attr
= HL_INVERSE
;
7064 for (r
= row
; r
< row
+ height
; ++r
)
7066 off
= LineOffset
[r
];
7068 max_off
= off
+ screen_Columns
;
7070 for (c
= col
; c
< col
+ width
; ++c
)
7073 if (enc_dbcs
!= 0 && dbcs_off2cells(off
+ c
, max_off
) > 1)
7075 screen_char_2(off
+ c
, r
, c
);
7081 screen_char(off
+ c
, r
, c
);
7083 if (utf_off2cells(off
+ c
, max_off
) > 1)
7089 screen_char_attr
= 0;
7093 #ifdef FEAT_VERTSPLIT
7095 * Redraw the characters for a vertically split window.
7098 redraw_block(row
, end
, wp
)
7106 # ifdef FEAT_CLIPBOARD
7107 clip_may_clear_selection(row
, end
- 1);
7118 width
= wp
->w_width
;
7120 screen_draw_rectangle(row
, col
, end
- row
, width
, FALSE
);
7125 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col'
7126 * with character 'c1' in first column followed by 'c2' in the other columns.
7127 * Use attributes 'attr'.
7130 screen_fill(start_row
, end_row
, start_col
, end_col
, c1
, c2
, attr
)
7131 int start_row
, end_row
;
7132 int start_col
, end_col
;
7143 #if defined(FEAT_GUI) || defined(UNIX)
7144 int force_next
= FALSE
;
7147 if (end_row
> screen_Rows
) /* safety check */
7148 end_row
= screen_Rows
;
7149 if (end_col
> screen_Columns
) /* safety check */
7150 end_col
= screen_Columns
;
7151 if (ScreenLines
== NULL
7152 || start_row
>= end_row
7153 || start_col
>= end_col
) /* nothing to do */
7156 /* it's a "normal" terminal when not in a GUI or cterm */
7162 for (row
= start_row
; row
< end_row
; ++row
)
7171 /* When drawing over the right halve of a double-wide char clear
7172 * out the left halve. When drawing over the left halve of a
7173 * double wide-char clear out the right halve. Only needed in a
7175 if (start_col
> 0 && mb_fix_col(start_col
, row
) != start_col
)
7176 screen_puts_len((char_u
*)" ", 1, row
, start_col
- 1, 0);
7177 if (end_col
< screen_Columns
&& mb_fix_col(end_col
, row
) != end_col
)
7178 screen_puts_len((char_u
*)" ", 1, row
, end_col
, 0);
7182 * Try to use delete-line termcap code, when no attributes or in a
7183 * "normal" terminal, where a bold/italic space is just a
7188 && end_col
== Columns
7193 && ((attr
& ~(HL_BOLD
| HL_ITALIC
)) == 0))))
7196 * check if we really need to clear something
7199 if (c1
!= ' ') /* don't clear first char */
7202 off
= LineOffset
[row
] + col
;
7203 end_off
= LineOffset
[row
] + end_col
;
7205 /* skip blanks (used often, keep it fast!) */
7208 while (off
< end_off
&& ScreenLines
[off
] == ' '
7209 && ScreenAttrs
[off
] == 0 && ScreenLinesUC
[off
] == 0)
7213 while (off
< end_off
&& ScreenLines
[off
] == ' '
7214 && ScreenAttrs
[off
] == 0)
7216 if (off
< end_off
) /* something to be cleared */
7218 col
= off
- LineOffset
[row
];
7219 screen_stop_highlight();
7220 term_windgoto(row
, col
);/* clear rest of this screen line */
7222 screen_start(); /* don't know where cursor is now */
7223 col
= end_col
- col
;
7224 while (col
--) /* clear chars in ScreenLines */
7226 ScreenLines
[off
] = ' ';
7229 ScreenLinesUC
[off
] = 0;
7231 ScreenAttrs
[off
] = 0;
7235 did_delete
= TRUE
; /* the chars are cleared now */
7238 off
= LineOffset
[row
] + start_col
;
7240 for (col
= start_col
; col
< end_col
; ++col
)
7242 if (ScreenLines
[off
] != c
7244 || (enc_utf8
&& (int)ScreenLinesUC
[off
]
7245 != (c
>= 0x80 ? c
: 0))
7247 || ScreenAttrs
[off
] != attr
7248 #if defined(FEAT_GUI) || defined(UNIX)
7253 #if defined(FEAT_GUI) || defined(UNIX)
7254 /* The bold trick may make a single row of pixels appear in
7255 * the next character. When a bold character is removed, the
7256 * next character should be redrawn too. This happens for our
7257 * own GUI and for some xterms. */
7262 # if defined(FEAT_GUI) && defined(UNIX)
7270 if (ScreenLines
[off
] != ' '
7271 && (ScreenAttrs
[off
] > HL_ALL
7272 || ScreenAttrs
[off
] & HL_BOLD
))
7278 ScreenLines
[off
] = c
;
7284 ScreenLinesUC
[off
] = c
;
7285 ScreenLinesC
[0][off
] = 0;
7288 ScreenLinesUC
[off
] = 0;
7291 ScreenAttrs
[off
] = attr
;
7292 if (!did_delete
|| c
!= ' ')
7293 screen_char(off
, row
, col
);
7296 if (col
== start_col
)
7303 if (end_col
== Columns
)
7304 LineWraps
[row
] = FALSE
;
7305 if (row
== Rows
- 1) /* overwritten the command line */
7307 redraw_cmdline
= TRUE
;
7308 if (c1
== ' ' && c2
== ' ')
7309 clear_cmdline
= FALSE
; /* command line has been cleared */
7311 mode_displayed
= FALSE
; /* mode cleared or overwritten */
7317 * Check if there should be a delay. Used before clearing or redrawing the
7318 * screen or the command line.
7321 check_for_delay(check_msg_scroll
)
7322 int check_msg_scroll
;
7324 if ((emsg_on_display
|| (check_msg_scroll
&& msg_scroll
))
7326 && emsg_silent
== 0)
7329 ui_delay(1000L, TRUE
);
7330 emsg_on_display
= FALSE
;
7331 if (check_msg_scroll
)
7337 * screen_valid - allocate screen buffers if size changed
7338 * If "clear" is TRUE: clear screen if it has been resized.
7339 * Returns TRUE if there is a valid screen to write to.
7340 * Returns FALSE when starting up and screen not initialized yet.
7346 screenalloc(clear
); /* allocate screen buffers if size changed */
7347 return (ScreenLines
!= NULL
);
7351 * Resize the shell to Rows and Columns.
7352 * Allocate ScreenLines[] and associated items.
7354 * There may be some time between setting Rows and Columns and (re)allocating
7355 * ScreenLines[]. This happens when starting up and when (manually) changing
7356 * the shell size. Always use screen_Rows and screen_Columns to access items
7357 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the
7358 * final size of the shell is needed.
7364 int new_row
, old_row
;
7369 int outofmem
= FALSE
;
7371 schar_T
*new_ScreenLines
;
7373 u8char_T
*new_ScreenLinesUC
= NULL
;
7374 u8char_T
*new_ScreenLinesC
[MAX_MCO
];
7375 schar_T
*new_ScreenLines2
= NULL
;
7378 sattr_T
*new_ScreenAttrs
;
7379 unsigned *new_LineOffset
;
7380 char_u
*new_LineWraps
;
7382 short *new_TabPageIdxs
;
7385 static int entered
= FALSE
; /* avoid recursiveness */
7386 static int done_outofmem_msg
= FALSE
; /* did outofmem message */
7389 * Allocation of the screen buffers is done only when the size changes and
7390 * when Rows and Columns have been set and we have started doing full
7393 if ((ScreenLines
!= NULL
7394 && Rows
== screen_Rows
7395 && Columns
== screen_Columns
7397 && enc_utf8
== (ScreenLinesUC
!= NULL
)
7398 && (enc_dbcs
== DBCS_JPNU
) == (ScreenLines2
!= NULL
)
7399 && p_mco
== Screen_mco
7404 || (!full_screen
&& ScreenLines
== NULL
))
7408 * It's possible that we produce an out-of-memory message below, which
7409 * will cause this function to be called again. To break the loop, just
7417 * Note that the window sizes are updated before reallocating the arrays,
7418 * thus we must not redraw here!
7420 ++RedrawingDisabled
;
7422 win_new_shellsize(); /* fit the windows in the new sized shell */
7424 comp_col(); /* recompute columns for shown command and ruler */
7427 * We're changing the size of the screen.
7428 * - Allocate new arrays for ScreenLines and ScreenAttrs.
7429 * - Move lines from the old arrays into the new arrays, clear extra
7430 * lines (unless the screen is going to be cleared).
7431 * - Free the old arrays.
7433 * If anything fails, make ScreenLines NULL, so we don't do anything!
7434 * Continuing with the old ScreenLines may result in a crash, because the
7437 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7440 new_ScreenLines
= (schar_T
*)lalloc((long_u
)(
7441 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7443 vim_memset(new_ScreenLinesC
, 0, sizeof(u8char_T
) * MAX_MCO
);
7446 new_ScreenLinesUC
= (u8char_T
*)lalloc((long_u
)(
7447 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7448 for (i
= 0; i
< p_mco
; ++i
)
7449 new_ScreenLinesC
[i
] = (u8char_T
*)lalloc((long_u
)(
7450 (Rows
+ 1) * Columns
* sizeof(u8char_T
)), FALSE
);
7452 if (enc_dbcs
== DBCS_JPNU
)
7453 new_ScreenLines2
= (schar_T
*)lalloc((long_u
)(
7454 (Rows
+ 1) * Columns
* sizeof(schar_T
)), FALSE
);
7456 new_ScreenAttrs
= (sattr_T
*)lalloc((long_u
)(
7457 (Rows
+ 1) * Columns
* sizeof(sattr_T
)), FALSE
);
7458 new_LineOffset
= (unsigned *)lalloc((long_u
)(
7459 Rows
* sizeof(unsigned)), FALSE
);
7460 new_LineWraps
= (char_u
*)lalloc((long_u
)(Rows
* sizeof(char_u
)), FALSE
);
7462 new_TabPageIdxs
= (short *)lalloc((long_u
)(Columns
* sizeof(short)), FALSE
);
7465 FOR_ALL_TAB_WINDOWS(tp
, wp
)
7467 if (win_alloc_lines(wp
) == FAIL
)
7477 for (i
= 0; i
< p_mco
; ++i
)
7478 if (new_ScreenLinesC
[i
] == NULL
)
7481 if (new_ScreenLines
== NULL
7483 || (enc_utf8
&& (new_ScreenLinesUC
== NULL
|| i
!= p_mco
))
7484 || (enc_dbcs
== DBCS_JPNU
&& new_ScreenLines2
== NULL
)
7486 || new_ScreenAttrs
== NULL
7487 || new_LineOffset
== NULL
7488 || new_LineWraps
== NULL
7490 || new_TabPageIdxs
== NULL
7494 if (ScreenLines
!= NULL
|| !done_outofmem_msg
)
7496 /* guess the size */
7497 do_outofmem_msg((long_u
)((Rows
+ 1) * Columns
));
7499 /* Remember we did this to avoid getting outofmem messages over
7500 * and over again. */
7501 done_outofmem_msg
= TRUE
;
7503 vim_free(new_ScreenLines
);
7504 new_ScreenLines
= NULL
;
7506 vim_free(new_ScreenLinesUC
);
7507 new_ScreenLinesUC
= NULL
;
7508 for (i
= 0; i
< p_mco
; ++i
)
7510 vim_free(new_ScreenLinesC
[i
]);
7511 new_ScreenLinesC
[i
] = NULL
;
7513 vim_free(new_ScreenLines2
);
7514 new_ScreenLines2
= NULL
;
7516 vim_free(new_ScreenAttrs
);
7517 new_ScreenAttrs
= NULL
;
7518 vim_free(new_LineOffset
);
7519 new_LineOffset
= NULL
;
7520 vim_free(new_LineWraps
);
7521 new_LineWraps
= NULL
;
7523 vim_free(new_TabPageIdxs
);
7524 new_TabPageIdxs
= NULL
;
7529 done_outofmem_msg
= FALSE
;
7531 for (new_row
= 0; new_row
< Rows
; ++new_row
)
7533 new_LineOffset
[new_row
] = new_row
* Columns
;
7534 new_LineWraps
[new_row
] = FALSE
;
7537 * If the screen is not going to be cleared, copy as much as
7538 * possible from the old screen to the new one and clear the rest
7539 * (used when resizing the window at the "--more--" prompt or when
7540 * executing an external command, for the GUI).
7544 (void)vim_memset(new_ScreenLines
+ new_row
* Columns
,
7545 ' ', (size_t)Columns
* sizeof(schar_T
));
7549 (void)vim_memset(new_ScreenLinesUC
+ new_row
* Columns
,
7550 0, (size_t)Columns
* sizeof(u8char_T
));
7551 for (i
= 0; i
< p_mco
; ++i
)
7552 (void)vim_memset(new_ScreenLinesC
[i
]
7553 + new_row
* Columns
,
7554 0, (size_t)Columns
* sizeof(u8char_T
));
7556 if (enc_dbcs
== DBCS_JPNU
)
7557 (void)vim_memset(new_ScreenLines2
+ new_row
* Columns
,
7558 0, (size_t)Columns
* sizeof(schar_T
));
7560 (void)vim_memset(new_ScreenAttrs
+ new_row
* Columns
,
7561 0, (size_t)Columns
* sizeof(sattr_T
));
7562 old_row
= new_row
+ (screen_Rows
- Rows
);
7563 if (old_row
>= 0 && ScreenLines
!= NULL
)
7565 if (screen_Columns
< Columns
)
7566 len
= screen_Columns
;
7570 /* When switching to utf-8 don't copy characters, they
7571 * may be invalid now. Also when p_mco changes. */
7572 if (!(enc_utf8
&& ScreenLinesUC
== NULL
)
7573 && p_mco
== Screen_mco
)
7575 mch_memmove(new_ScreenLines
+ new_LineOffset
[new_row
],
7576 ScreenLines
+ LineOffset
[old_row
],
7577 (size_t)len
* sizeof(schar_T
));
7579 if (enc_utf8
&& ScreenLinesUC
!= NULL
7580 && p_mco
== Screen_mco
)
7582 mch_memmove(new_ScreenLinesUC
+ new_LineOffset
[new_row
],
7583 ScreenLinesUC
+ LineOffset
[old_row
],
7584 (size_t)len
* sizeof(u8char_T
));
7585 for (i
= 0; i
< p_mco
; ++i
)
7586 mch_memmove(new_ScreenLinesC
[i
]
7587 + new_LineOffset
[new_row
],
7588 ScreenLinesC
[i
] + LineOffset
[old_row
],
7589 (size_t)len
* sizeof(u8char_T
));
7591 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines2
!= NULL
)
7592 mch_memmove(new_ScreenLines2
+ new_LineOffset
[new_row
],
7593 ScreenLines2
+ LineOffset
[old_row
],
7594 (size_t)len
* sizeof(schar_T
));
7596 mch_memmove(new_ScreenAttrs
+ new_LineOffset
[new_row
],
7597 ScreenAttrs
+ LineOffset
[old_row
],
7598 (size_t)len
* sizeof(sattr_T
));
7602 /* Use the last line of the screen for the current line. */
7603 current_ScreenLine
= new_ScreenLines
+ Rows
* Columns
;
7608 ScreenLines
= new_ScreenLines
;
7610 ScreenLinesUC
= new_ScreenLinesUC
;
7611 for (i
= 0; i
< p_mco
; ++i
)
7612 ScreenLinesC
[i
] = new_ScreenLinesC
[i
];
7614 ScreenLines2
= new_ScreenLines2
;
7616 ScreenAttrs
= new_ScreenAttrs
;
7617 LineOffset
= new_LineOffset
;
7618 LineWraps
= new_LineWraps
;
7620 TabPageIdxs
= new_TabPageIdxs
;
7623 /* It's important that screen_Rows and screen_Columns reflect the actual
7624 * size of ScreenLines[]. Set them before calling anything. */
7626 old_Rows
= screen_Rows
;
7629 screen_Columns
= Columns
;
7631 must_redraw
= CLEAR
; /* need to clear the screen later */
7638 && ScreenLines
!= NULL
7639 && old_Rows
!= Rows
)
7641 (void)gui_redraw_block(0, 0, (int)Rows
- 1, (int)Columns
- 1, 0);
7643 * Adjust the position of the cursor, for when executing an external
7646 if (msg_row
>= Rows
) /* Rows got smaller */
7647 msg_row
= Rows
- 1; /* put cursor at last row */
7648 else if (Rows
> old_Rows
) /* Rows got bigger */
7649 msg_row
+= Rows
- old_Rows
; /* put cursor in same place */
7650 if (msg_col
>= Columns
) /* Columns got smaller */
7651 msg_col
= Columns
- 1; /* put cursor at last column */
7656 --RedrawingDisabled
;
7660 apply_autocmds(EVENT_VIMRESIZED
, NULL
, NULL
, FALSE
, curbuf
);
7670 vim_free(ScreenLinesUC
);
7671 for (i
= 0; i
< Screen_mco
; ++i
)
7672 vim_free(ScreenLinesC
[i
]);
7673 vim_free(ScreenLines2
);
7675 vim_free(ScreenLines
);
7676 vim_free(ScreenAttrs
);
7677 vim_free(LineOffset
);
7678 vim_free(LineWraps
);
7680 vim_free(TabPageIdxs
);
7687 check_for_delay(FALSE
);
7688 screenalloc(FALSE
); /* allocate screen buffers if size changed */
7689 screenclear2(); /* clear the screen */
7697 if (starting
== NO_SCREEN
|| ScreenLines
== NULL
7699 || (gui
.in_use
&& gui
.starting
)
7707 screen_attr
= -1; /* force setting the Normal colors */
7708 screen_stop_highlight(); /* don't want highlighting here */
7710 #ifdef FEAT_CLIPBOARD
7711 /* disable selection without redrawing it */
7712 clip_scroll_selection(9999);
7715 /* blank out ScreenLines */
7716 for (i
= 0; i
< Rows
; ++i
)
7718 lineclear(LineOffset
[i
], (int)Columns
);
7719 LineWraps
[i
] = FALSE
;
7722 if (can_clear(T_CL
))
7724 out_str(T_CL
); /* clear the display */
7725 clear_cmdline
= FALSE
;
7726 mode_displayed
= FALSE
;
7730 /* can't clear the screen, mark all chars with invalid attributes */
7731 for (i
= 0; i
< Rows
; ++i
)
7732 lineinvalid(LineOffset
[i
], (int)Columns
);
7733 clear_cmdline
= TRUE
;
7736 screen_cleared
= TRUE
; /* can use contents of ScreenLines now */
7738 win_rest_invalid(firstwin
);
7739 redraw_cmdline
= TRUE
;
7741 redraw_tabline
= TRUE
;
7743 if (must_redraw
== CLEAR
) /* no need to clear again */
7744 must_redraw
= NOT_VALID
;
7746 msg_row
= cmdline_row
; /* put cursor on last line for messages */
7748 screen_start(); /* don't know where cursor is now */
7749 msg_scrolled
= 0; /* can't scroll back */
7755 * Clear one line in ScreenLines.
7758 lineclear(off
, width
)
7762 (void)vim_memset(ScreenLines
+ off
, ' ', (size_t)width
* sizeof(schar_T
));
7765 (void)vim_memset(ScreenLinesUC
+ off
, 0,
7766 (size_t)width
* sizeof(u8char_T
));
7768 (void)vim_memset(ScreenAttrs
+ off
, 0, (size_t)width
* sizeof(sattr_T
));
7772 * Mark one line in ScreenLines invalid by setting the attributes to an
7776 lineinvalid(off
, width
)
7780 (void)vim_memset(ScreenAttrs
+ off
, -1, (size_t)width
* sizeof(sattr_T
));
7783 #ifdef FEAT_VERTSPLIT
7785 * Copy part of a Screenline for vertically split window "wp".
7788 linecopy(to
, from
, wp
)
7793 unsigned off_to
= LineOffset
[to
] + wp
->w_wincol
;
7794 unsigned off_from
= LineOffset
[from
] + wp
->w_wincol
;
7796 mch_memmove(ScreenLines
+ off_to
, ScreenLines
+ off_from
,
7797 wp
->w_width
* sizeof(schar_T
));
7803 mch_memmove(ScreenLinesUC
+ off_to
, ScreenLinesUC
+ off_from
,
7804 wp
->w_width
* sizeof(u8char_T
));
7805 for (i
= 0; i
< p_mco
; ++i
)
7806 mch_memmove(ScreenLinesC
[i
] + off_to
, ScreenLinesC
[i
] + off_from
,
7807 wp
->w_width
* sizeof(u8char_T
));
7809 if (enc_dbcs
== DBCS_JPNU
)
7810 mch_memmove(ScreenLines2
+ off_to
, ScreenLines2
+ off_from
,
7811 wp
->w_width
* sizeof(schar_T
));
7813 mch_memmove(ScreenAttrs
+ off_to
, ScreenAttrs
+ off_from
,
7814 wp
->w_width
* sizeof(sattr_T
));
7819 * Return TRUE if clearing with term string "p" would work.
7820 * It can't work when the string is empty or it won't set the right background.
7826 return (*p
!= NUL
&& (t_colors
<= 1
7830 || cterm_normal_bg_color
== 0 || *T_UT
!= NUL
));
7834 * Reset cursor position. Use whenever cursor was moved because of outputting
7835 * something directly to the screen (shell commands) or a terminal control
7841 screen_cur_row
= screen_cur_col
= 9999;
7845 * Move the cursor to position "row","col" in the screen.
7846 * This tries to find the most efficient way to move, minimizing the number of
7847 * characters sent to the terminal.
7864 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */
7865 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
7870 #define PLAN_WRITE 4
7871 /* Can't use ScreenLines unless initialized */
7872 if (ScreenLines
== NULL
)
7875 if (col
!= screen_cur_col
|| row
!= screen_cur_row
)
7877 /* Check for valid position. */
7878 if (row
< 0) /* window without text lines? */
7880 if (row
>= screen_Rows
)
7881 row
= screen_Rows
- 1;
7882 if (col
>= screen_Columns
)
7883 col
= screen_Columns
- 1;
7885 /* check if no cursor movement is allowed in highlight mode */
7886 if (screen_attr
&& *T_MS
== NUL
)
7887 noinvcurs
= HIGHL_COST
;
7890 goto_cost
= GOTO_COST
+ noinvcurs
;
7893 * Plan how to do the positioning:
7894 * 1. Use CR to move it to column 0, same row.
7895 * 2. Use T_LE to move it a few columns to the left.
7896 * 3. Use NL to move a few lines down, column 0.
7897 * 4. Move a few columns to the right with T_ND or by writing chars.
7899 * Don't do this if the cursor went beyond the last column, the cursor
7900 * position is unknown then (some terminals wrap, some don't )
7902 * First check if the highlighting attributes allow us to write
7903 * characters to move the cursor to the right.
7905 if (row
>= screen_cur_row
&& screen_cur_col
< Columns
)
7908 * If the cursor is in the same row, bigger col, we can use CR
7911 bs
= NULL
; /* init for GCC */
7913 if (row
== screen_cur_row
&& col
< screen_cur_col
)
7915 /* "le" is preferred over "bc", because "bc" is obsolete */
7917 bs
= T_LE
; /* "cursor left" */
7919 bs
= T_BC
; /* "backspace character (old) */
7921 cost
= (screen_cur_col
- col
) * (int)STRLEN(bs
);
7924 if (col
+ 1 < cost
) /* using CR is less characters */
7928 cost
= 1; /* CR is just one character */
7935 if (noinvcurs
) /* will stop highlighting */
7943 * If the cursor is above where we want to be, we can use CR LF.
7945 else if (row
> screen_cur_row
)
7949 cost
= (row
- screen_cur_row
) * 2; /* CR LF */
7950 if (noinvcurs
) /* will stop highlighting */
7958 * If the cursor is in the same row, smaller col, just use write.
7963 wouldbe_col
= screen_cur_col
;
7968 * Check if any characters that need to be written have the
7969 * correct attributes. Also avoid UTF-8 characters.
7971 i
= col
- wouldbe_col
;
7974 if (cost
< goto_cost
&& i
> 0)
7977 * Check if the attributes are correct without additionally
7978 * stopping highlighting.
7980 p
= ScreenAttrs
+ LineOffset
[row
] + wouldbe_col
;
7981 while (i
&& *p
++ == attr
)
7986 * Try if it works when highlighting is stopped here.
7991 while (i
&& *p
++ == 0)
7995 cost
= 999; /* different attributes, don't do it */
8000 /* Don't use an UTF-8 char for positioning, it's slow. */
8001 for (i
= wouldbe_col
; i
< col
; ++i
)
8002 if (ScreenLinesUC
[LineOffset
[row
] + i
] != 0)
8012 * We can do it without term_windgoto()!
8014 if (cost
< goto_cost
)
8016 if (plan
== PLAN_LE
)
8019 screen_stop_highlight();
8020 while (screen_cur_col
> col
)
8026 else if (plan
== PLAN_CR
)
8029 screen_stop_highlight();
8033 else if (plan
== PLAN_NL
)
8036 screen_stop_highlight();
8037 while (screen_cur_row
< row
)
8045 i
= col
- screen_cur_col
;
8049 * Use cursor-right if it's one character only. Avoids
8050 * removing a line of pixels from the last bold char, when
8051 * using the bold trick in the GUI.
8053 if (T_ND
[0] != NUL
&& T_ND
[1] == NUL
)
8062 off
= LineOffset
[row
] + screen_cur_col
;
8065 if (ScreenAttrs
[off
] != screen_attr
)
8066 screen_stop_highlight();
8070 out_char(ScreenLines
[off
]);
8072 if (enc_dbcs
== DBCS_JPNU
8073 && ScreenLines
[off
] == 0x8e)
8074 out_char(ScreenLines2
[off
]);
8085 if (cost
>= goto_cost
)
8088 screen_stop_highlight();
8089 if (row
== screen_cur_row
&& (col
> screen_cur_col
) &&
8091 term_cursor_right(col
- screen_cur_col
);
8093 term_windgoto(row
, col
);
8095 screen_cur_row
= row
;
8096 screen_cur_col
= col
;
8101 * Set cursor to its position in the current window.
8109 windgoto(W_WINROW(curwin
) + curwin
->w_wrow
,
8110 W_WINCOL(curwin
) + (
8111 #ifdef FEAT_RIGHTLEFT
8112 /* With 'rightleft' set and the cursor on a double-wide
8113 * character, position it on the leftmost column. */
8114 curwin
->w_p_rl
? ((int)W_WIDTH(curwin
) - curwin
->w_wcol
- (
8117 && (*mb_ptr2cells
)(ml_get_cursor()) == 2
8118 && vim_isprintc(gchar_cursor())) ? 2 :
8128 * insert 'line_count' lines at 'row' in window 'wp'
8129 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated.
8130 * if 'mayclear' is TRUE the screen will be cleared if it is faster than
8132 * Returns FAIL if the lines are not inserted, OK for success.
8135 win_ins_lines(wp
, row
, line_count
, invalid
, mayclear
)
8148 wp
->w_lines_valid
= 0;
8150 if (wp
->w_height
< 5)
8153 if (line_count
> wp
->w_height
- row
)
8154 line_count
= wp
->w_height
- row
;
8156 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, FALSE
);
8157 if (retval
!= MAYBE
)
8161 * If there is a next window or a status line, we first try to delete the
8162 * lines at the bottom to avoid messing what is after the window.
8163 * If this fails and there are following windows, don't do anything to avoid
8164 * messing up those windows, better just redraw.
8168 if (wp
->w_next
!= NULL
|| wp
->w_status_height
)
8170 if (screen_del_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8171 line_count
, (int)Rows
, FALSE
, NULL
) == OK
)
8173 else if (wp
->w_next
)
8178 * if no lines deleted, blank the lines that will end up below the window
8183 wp
->w_redr_status
= TRUE
;
8185 redraw_cmdline
= TRUE
;
8186 nextrow
= W_WINROW(wp
) + wp
->w_height
+ W_STATUS_HEIGHT(wp
);
8187 lastrow
= nextrow
+ line_count
;
8190 screen_fill(nextrow
- line_count
, lastrow
- line_count
,
8191 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8195 if (screen_ins_lines(0, W_WINROW(wp
) + row
, line_count
, (int)Rows
, NULL
)
8198 /* deletion will have messed up other windows */
8202 wp
->w_redr_status
= TRUE
;
8204 win_rest_invalid(W_NEXT(wp
));
8213 * delete "line_count" window lines at "row" in window "wp"
8214 * If "invalid" is TRUE curwin->w_lines[] is invalidated.
8215 * If "mayclear" is TRUE the screen will be cleared if it is faster than
8217 * Return OK for success, FAIL if the lines are not deleted.
8220 win_del_lines(wp
, row
, line_count
, invalid
, mayclear
)
8230 wp
->w_lines_valid
= 0;
8232 if (line_count
> wp
->w_height
- row
)
8233 line_count
= wp
->w_height
- row
;
8235 retval
= win_do_lines(wp
, row
, line_count
, mayclear
, TRUE
);
8236 if (retval
!= MAYBE
)
8239 if (screen_del_lines(0, W_WINROW(wp
) + row
, line_count
,
8240 (int)Rows
, FALSE
, NULL
) == FAIL
)
8245 * If there are windows or status lines below, try to put them at the
8246 * correct place. If we can't do that, they have to be redrawn.
8248 if (wp
->w_next
|| wp
->w_status_height
|| cmdline_row
< Rows
- 1)
8250 if (screen_ins_lines(0, W_WINROW(wp
) + wp
->w_height
- line_count
,
8251 line_count
, (int)Rows
, NULL
) == FAIL
)
8253 wp
->w_redr_status
= TRUE
;
8254 win_rest_invalid(wp
->w_next
);
8258 * If this is the last window and there is no status line, redraw the
8259 * command line later.
8263 redraw_cmdline
= TRUE
;
8268 * Common code for win_ins_lines() and win_del_lines().
8269 * Returns OK or FAIL when the work has been done.
8270 * Returns MAYBE when not finished yet.
8273 win_do_lines(wp
, row
, line_count
, mayclear
, del
)
8282 if (!redrawing() || line_count
<= 0)
8285 /* only a few lines left: redraw is faster */
8286 if (mayclear
&& Rows
- line_count
< 5
8287 #ifdef FEAT_VERTSPLIT
8288 && wp
->w_width
== Columns
8292 screenclear(); /* will set wp->w_lines_valid to 0 */
8297 * Delete all remaining lines
8299 if (row
+ line_count
>= wp
->w_height
)
8301 screen_fill(W_WINROW(wp
) + row
, W_WINROW(wp
) + wp
->w_height
,
8302 W_WINCOL(wp
), (int)W_ENDCOL(wp
),
8308 * when scrolling, the message on the command line should be cleared,
8309 * otherwise it will stay there forever.
8311 clear_cmdline
= TRUE
;
8314 * If the terminal can set a scroll region, use that.
8315 * Always do this in a vertically split window. This will redraw from
8316 * ScreenLines[] when t_CV isn't defined. That's faster than using
8318 * Don't use a scroll region when we are going to redraw the text, writing
8319 * a character in the lower right corner of the scroll region causes a
8320 * scroll-up in the DJGPP version.
8323 #ifdef FEAT_VERTSPLIT
8324 || W_WIDTH(wp
) != Columns
8328 #ifdef FEAT_VERTSPLIT
8329 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8331 scroll_region_set(wp
, row
);
8333 retval
= screen_del_lines(W_WINROW(wp
) + row
, 0, line_count
,
8334 wp
->w_height
- row
, FALSE
, wp
);
8336 retval
= screen_ins_lines(W_WINROW(wp
) + row
, 0, line_count
,
8337 wp
->w_height
- row
, wp
);
8338 #ifdef FEAT_VERTSPLIT
8339 if (scroll_region
&& (wp
->w_width
== Columns
|| *T_CSV
!= NUL
))
8341 scroll_region_reset();
8346 if (wp
->w_next
!= NULL
&& p_tf
) /* don't delete/insert on fast terminal */
8354 * window 'wp' and everything after it is messed up, mark it for redraw
8357 win_rest_invalid(wp
)
8366 redraw_win_later(wp
, NOT_VALID
);
8368 wp
->w_redr_status
= TRUE
;
8372 redraw_cmdline
= TRUE
;
8376 * The rest of the routines in this file perform screen manipulations. The
8377 * given operation is performed physically on the screen. The corresponding
8378 * change is also made to the internal screen image. In this way, the editor
8379 * anticipates the effect of editing changes on the appearance of the screen.
8380 * That way, when we call screenupdate a complete redraw isn't usually
8381 * necessary. Another advantage is that we can keep adding code to anticipate
8382 * screen changes, and in the meantime, everything still works.
8386 * types for inserting or deleting lines
8396 #define USE_REDRAW 9
8399 * insert lines on the screen and update ScreenLines[]
8400 * 'end' is the line after the scrolled part. Normally it is Rows.
8401 * When scrolling region used 'off' is the offset from the top for the region.
8402 * 'row' and 'end' are relative to the start of the region.
8404 * return FAIL for failure, OK for success.
8407 screen_ins_lines(off
, row
, line_count
, end
, wp
)
8412 win_T
*wp
; /* NULL or window to use width from */
8420 int can_ce
= can_clear(T_CE
);
8424 * - there is no valid screen
8425 * - the screen has to be redrawn completely
8426 * - the line count is less than one
8427 * - the line count is more than 'ttyscroll'
8429 if (!screen_valid(TRUE
) || line_count
<= 0 || line_count
> p_ttyscroll
)
8433 * There are seven ways to insert lines:
8434 * 0. When in a vertically split window and t_CV isn't set, redraw the
8435 * characters from ScreenLines[].
8436 * 1. Use T_CD (clear to end of display) if it exists and the result of
8437 * the insert is just empty lines
8438 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
8439 * present or line_count > 1. It looks better if we do all the inserts
8441 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
8442 * insert is just empty lines and T_CE is not present or line_count >
8444 * 4. Use T_AL (insert line) if it exists.
8445 * 5. Use T_CE (erase line) if it exists and the result of the insert is
8447 * 6. Use T_DL (delete line) if it exists and the result of the insert is
8449 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
8450 * the 'da' flag is not set or we have clear line capability.
8451 * 8. redraw the characters from ScreenLines[].
8453 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
8454 * the scrollbar for the window. It does have insert line, use that if it
8457 result_empty
= (row
+ line_count
>= end
);
8458 #ifdef FEAT_VERTSPLIT
8459 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8463 if (can_clear(T_CD
) && result_empty
)
8465 else if (*T_CAL
!= NUL
&& (line_count
> 1 || *T_AL
== NUL
))
8467 else if (*T_CDL
!= NUL
&& result_empty
&& (line_count
> 1 || !can_ce
))
8469 else if (*T_AL
!= NUL
)
8471 else if (can_ce
&& result_empty
)
8473 else if (*T_DL
!= NUL
&& result_empty
)
8475 else if (*T_SR
!= NUL
&& row
== 0 && (*T_DA
== NUL
|| can_ce
))
8481 * For clearing the lines screen_del_lines() is used. This will also take
8482 * care of t_db if necessary.
8484 if (type
== USE_T_CD
|| type
== USE_T_CDL
||
8485 type
== USE_T_CE
|| type
== USE_T_DL
)
8486 return screen_del_lines(off
, row
, line_count
, end
, FALSE
, wp
);
8489 * If text is retained below the screen, first clear or delete as many
8490 * lines at the bottom of the window as are about to be inserted so that
8491 * the deleted lines won't later surface during a screen_del_lines.
8494 screen_del_lines(off
, end
- line_count
, line_count
, end
, FALSE
, wp
);
8496 #ifdef FEAT_CLIPBOARD
8497 /* Remove a modeless selection when inserting lines halfway the screen
8498 * or not the full width of the screen. */
8500 # ifdef FEAT_VERTSPLIT
8501 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8504 clip_clear_selection();
8506 clip_scroll_selection(-line_count
);
8510 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8511 * scrolling is actually carried out. */
8512 gui_dont_update_cursor();
8515 if (*T_CCS
!= NUL
) /* cursor relative to region */
8518 cursor_row
= row
+ off
;
8521 * Shift LineOffset[] line_count down to reflect the inserted lines.
8522 * Clear the inserted lines in ScreenLines[].
8526 for (i
= 0; i
< line_count
; ++i
)
8528 #ifdef FEAT_VERTSPLIT
8529 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8531 /* need to copy part of a line */
8533 while ((j
-= line_count
) >= row
)
8534 linecopy(j
+ line_count
, j
, wp
);
8536 if (can_clear((char_u
*)" "))
8537 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8539 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8540 LineWraps
[j
] = FALSE
;
8546 temp
= LineOffset
[j
];
8547 while ((j
-= line_count
) >= row
)
8549 LineOffset
[j
+ line_count
] = LineOffset
[j
];
8550 LineWraps
[j
+ line_count
] = LineWraps
[j
];
8552 LineOffset
[j
+ line_count
] = temp
;
8553 LineWraps
[j
+ line_count
] = FALSE
;
8554 if (can_clear((char_u
*)" "))
8555 lineclear(temp
, (int)Columns
);
8557 lineinvalid(temp
, (int)Columns
);
8561 screen_stop_highlight();
8562 windgoto(cursor_row
, 0);
8564 #ifdef FEAT_VERTSPLIT
8565 /* redraw the characters */
8566 if (type
== USE_REDRAW
)
8567 redraw_block(row
, end
, wp
);
8570 if (type
== USE_T_CAL
)
8572 term_append_lines(line_count
);
8573 screen_start(); /* don't know where cursor is now */
8577 for (i
= 0; i
< line_count
; i
++)
8579 if (type
== USE_T_AL
)
8581 if (i
&& cursor_row
!= 0)
8582 windgoto(cursor_row
, 0);
8585 else /* type == USE_T_SR */
8587 screen_start(); /* don't know where cursor is now */
8592 * With scroll-reverse and 'da' flag set we need to clear the lines that
8593 * have been scrolled down into the region.
8595 if (type
== USE_T_SR
&& *T_DA
)
8597 for (i
= 0; i
< line_count
; ++i
)
8599 windgoto(off
+ i
, 0);
8601 screen_start(); /* don't know where cursor is now */
8606 gui_can_update_cursor();
8608 out_flush(); /* always flush after a scroll */
8614 * delete lines on the screen and update ScreenLines[]
8615 * 'end' is the line after the scrolled part. Normally it is Rows.
8616 * When scrolling region used 'off' is the offset from the top for the region.
8617 * 'row' and 'end' are relative to the start of the region.
8619 * Return OK for success, FAIL if the lines are not deleted.
8623 screen_del_lines(off
, row
, line_count
, end
, force
, wp
)
8628 int force
; /* even when line_count > p_ttyscroll */
8629 win_T
*wp
; /* NULL or window to use width from */
8636 int result_empty
; /* result is empty until end of region */
8637 int can_delete
; /* deleting line codes can be used */
8642 * - there is no valid screen
8643 * - the screen has to be redrawn completely
8644 * - the line count is less than one
8645 * - the line count is more than 'ttyscroll'
8647 if (!screen_valid(TRUE
) || line_count
<= 0 ||
8648 (!force
&& line_count
> p_ttyscroll
))
8652 * Check if the rest of the current region will become empty.
8654 result_empty
= row
+ line_count
>= end
;
8657 * We can delete lines only when 'db' flag not set or when 'ce' option
8660 can_delete
= (*T_DB
== NUL
|| can_clear(T_CE
));
8663 * There are six ways to delete lines:
8664 * 0. When in a vertically split window and t_CV isn't set, redraw the
8665 * characters from ScreenLines[].
8666 * 1. Use T_CD if it exists and the result is empty.
8667 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
8668 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
8669 * none of the other ways work.
8670 * 4. Use T_CE (erase line) if the result is empty.
8671 * 5. Use T_DL (delete line) if it exists.
8672 * 6. redraw the characters from ScreenLines[].
8674 #ifdef FEAT_VERTSPLIT
8675 if (wp
!= NULL
&& wp
->w_width
!= Columns
&& *T_CSV
== NUL
)
8679 if (can_clear(T_CD
) && result_empty
)
8681 #if defined(__BEOS__) && defined(BEOS_DR8)
8683 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
8684 * its internal termcap... this works okay for tests which test *T_DB !=
8685 * NUL. It has the disadvantage that the user cannot use any :set t_*
8686 * command to get T_DB (back) to empty_option, only :set term=... will do
8688 * Anyway, this hack will hopefully go away with the next OS release.
8691 else if (row
== 0 && T_DB
== empty_option
8692 && (line_count
== 1 || *T_CDL
== NUL
))
8694 else if (row
== 0 && (
8696 /* On the Amiga, somehow '\n' on the last line doesn't always scroll
8697 * up, so use delete-line command */
8703 else if (*T_CDL
!= NUL
&& line_count
> 1 && can_delete
)
8705 else if (can_clear(T_CE
) && result_empty
8706 #ifdef FEAT_VERTSPLIT
8707 && (wp
== NULL
|| wp
->w_width
== Columns
)
8711 else if (*T_DL
!= NUL
&& can_delete
)
8713 else if (*T_CDL
!= NUL
&& can_delete
)
8718 #ifdef FEAT_CLIPBOARD
8719 /* Remove a modeless selection when deleting lines halfway the screen or
8720 * not the full width of the screen. */
8722 # ifdef FEAT_VERTSPLIT
8723 || (wp
!= NULL
&& wp
->w_width
!= Columns
)
8726 clip_clear_selection();
8728 clip_scroll_selection(line_count
);
8732 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the
8733 * scrolling is actually carried out. */
8734 gui_dont_update_cursor();
8737 if (*T_CCS
!= NUL
) /* cursor relative to region */
8744 cursor_row
= row
+ off
;
8745 cursor_end
= end
+ off
;
8749 * Now shift LineOffset[] line_count up to reflect the deleted lines.
8750 * Clear the inserted lines in ScreenLines[].
8754 for (i
= 0; i
< line_count
; ++i
)
8756 #ifdef FEAT_VERTSPLIT
8757 if (wp
!= NULL
&& wp
->w_width
!= Columns
)
8759 /* need to copy part of a line */
8761 while ((j
+= line_count
) <= end
- 1)
8762 linecopy(j
- line_count
, j
, wp
);
8764 if (can_clear((char_u
*)" "))
8765 lineclear(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8767 lineinvalid(LineOffset
[j
] + wp
->w_wincol
, wp
->w_width
);
8768 LineWraps
[j
] = FALSE
;
8773 /* whole width, moving the line pointers is faster */
8775 temp
= LineOffset
[j
];
8776 while ((j
+= line_count
) <= end
- 1)
8778 LineOffset
[j
- line_count
] = LineOffset
[j
];
8779 LineWraps
[j
- line_count
] = LineWraps
[j
];
8781 LineOffset
[j
- line_count
] = temp
;
8782 LineWraps
[j
- line_count
] = FALSE
;
8783 if (can_clear((char_u
*)" "))
8784 lineclear(temp
, (int)Columns
);
8786 lineinvalid(temp
, (int)Columns
);
8790 screen_stop_highlight();
8792 #ifdef FEAT_VERTSPLIT
8793 /* redraw the characters */
8794 if (type
== USE_REDRAW
)
8795 redraw_block(row
, end
, wp
);
8798 if (type
== USE_T_CD
) /* delete the lines */
8800 windgoto(cursor_row
, 0);
8802 screen_start(); /* don't know where cursor is now */
8804 else if (type
== USE_T_CDL
)
8806 windgoto(cursor_row
, 0);
8807 term_delete_lines(line_count
);
8808 screen_start(); /* don't know where cursor is now */
8811 * Deleting lines at top of the screen or scroll region: Just scroll
8812 * the whole screen (scroll region) up by outputting newlines on the
8815 else if (type
== USE_NL
)
8817 windgoto(cursor_end
- 1, 0);
8818 for (i
= line_count
; --i
>= 0; )
8819 out_char('\n'); /* cursor will remain on same line */
8823 for (i
= line_count
; --i
>= 0; )
8825 if (type
== USE_T_DL
)
8827 windgoto(cursor_row
, 0);
8828 out_str(T_DL
); /* delete a line */
8830 else /* type == USE_T_CE */
8832 windgoto(cursor_row
+ i
, 0);
8833 out_str(T_CE
); /* erase a line */
8835 screen_start(); /* don't know where cursor is now */
8840 * If the 'db' flag is set, we need to clear the lines that have been
8841 * scrolled up at the bottom of the region.
8843 if (*T_DB
&& (type
== USE_T_DL
|| type
== USE_T_CDL
))
8845 for (i
= line_count
; i
> 0; --i
)
8847 windgoto(cursor_end
- i
, 0);
8848 out_str(T_CE
); /* erase a line */
8849 screen_start(); /* don't know where cursor is now */
8854 gui_can_update_cursor();
8856 out_flush(); /* always flush after a scroll */
8863 * show the current mode and ruler
8865 * If clear_cmdline is TRUE, clear the rest of the cmdline.
8866 * If clear_cmdline is FALSE there may be a message there that needs to be
8867 * cleared only if a mode is shown.
8868 * Return the length of the message (0 if no message).
8878 #ifdef FEAT_INS_EXPAND
8882 do_mode
= ((p_smd
&& msg_silent
== 0)
8883 && ((State
& INSERT
)
8889 if (do_mode
|| Recording
)
8892 * Don't show mode right now, when not redrawing or inside a mapping.
8893 * Call char_avail() only when we are going to show something, because
8894 * it takes a bit of time.
8896 if (!redrawing() || (char_avail() && !KeyTyped
) || msg_silent
!= 0)
8898 redraw_cmdline
= TRUE
; /* show mode later */
8902 nwr_save
= need_wait_return
;
8904 /* wait a bit before overwriting an important message */
8905 check_for_delay(FALSE
);
8907 /* if the cmdline is more than one line high, erase top lines */
8908 need_clear
= clear_cmdline
;
8909 if (clear_cmdline
&& cmdline_row
< Rows
- 1)
8910 msg_clr_cmdline(); /* will reset clear_cmdline */
8912 /* Position on the last line in the window, column 0 */
8915 attr
= hl_attr(HLF_CM
); /* Highlight mode */
8918 MSG_PUTS_ATTR("--", attr
);
8919 #if defined(FEAT_XIM)
8920 # if 0 /* old version, changed by SungHyun Nam July 2008 */
8921 if (xic
!= NULL
&& im_get_status() && !p_imdisable
8922 && curbuf
->b_p_iminsert
== B_IMODE_IM
)
8926 preedit_get_status()
8932 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */
8933 MSG_PUTS_ATTR(" IM", attr
);
8935 MSG_PUTS_ATTR(" XIM", attr
);
8938 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
8941 if (hangul_input_state_get())
8942 MSG_PUTS_ATTR(" \307\321\261\333", attr
); /* HANGUL */
8945 #ifdef FEAT_INS_EXPAND
8946 if (edit_submode
!= NULL
) /* CTRL-X in Insert mode */
8948 /* These messages can get long, avoid a wrap in a narrow
8949 * window. Prefer showing edit_submode_extra. */
8950 length
= (Rows
- msg_row
) * Columns
- 3;
8951 if (edit_submode_extra
!= NULL
)
8952 length
-= vim_strsize(edit_submode_extra
);
8955 if (edit_submode_pre
!= NULL
)
8956 length
-= vim_strsize(edit_submode_pre
);
8957 if (length
- vim_strsize(edit_submode
) > 0)
8959 if (edit_submode_pre
!= NULL
)
8960 msg_puts_attr(edit_submode_pre
, attr
);
8961 msg_puts_attr(edit_submode
, attr
);
8963 if (edit_submode_extra
!= NULL
)
8965 MSG_PUTS_ATTR(" ", attr
); /* add a space in between */
8966 if ((int)edit_submode_highl
< (int)HLF_COUNT
)
8967 sub_attr
= hl_attr(edit_submode_highl
);
8970 msg_puts_attr(edit_submode_extra
, sub_attr
);
8978 #ifdef FEAT_VREPLACE
8979 if (State
& VREPLACE_FLAG
)
8980 MSG_PUTS_ATTR(_(" VREPLACE"), attr
);
8983 if (State
& REPLACE_FLAG
)
8984 MSG_PUTS_ATTR(_(" REPLACE"), attr
);
8985 else if (State
& INSERT
)
8987 #ifdef FEAT_RIGHTLEFT
8989 MSG_PUTS_ATTR(_(" REVERSE"), attr
);
8991 MSG_PUTS_ATTR(_(" INSERT"), attr
);
8993 else if (restart_edit
== 'I')
8994 MSG_PUTS_ATTR(_(" (insert)"), attr
);
8995 else if (restart_edit
== 'R')
8996 MSG_PUTS_ATTR(_(" (replace)"), attr
);
8997 else if (restart_edit
== 'V')
8998 MSG_PUTS_ATTR(_(" (vreplace)"), attr
);
8999 #ifdef FEAT_RIGHTLEFT
9001 MSG_PUTS_ATTR(_(" Hebrew"), attr
);
9004 MSG_PUTS_ATTR(farsi_text_5
, attr
);
9008 if (State
& LANGMAP
)
9011 if (curwin
->w_p_arab
)
9012 MSG_PUTS_ATTR(_(" Arabic"), attr
);
9015 MSG_PUTS_ATTR(_(" (lang)"), attr
);
9018 if ((State
& INSERT
) && p_paste
)
9019 MSG_PUTS_ATTR(_(" (paste)"), attr
);
9026 /* Don't concatenate separate words to avoid translation
9028 switch ((VIsual_select
? 4 : 0)
9029 + (VIsual_mode
== Ctrl_V
) * 2
9030 + (VIsual_mode
== 'V'))
9032 case 0: p
= N_(" VISUAL"); break;
9033 case 1: p
= N_(" VISUAL LINE"); break;
9034 case 2: p
= N_(" VISUAL BLOCK"); break;
9035 case 4: p
= N_(" SELECT"); break;
9036 case 5: p
= N_(" SELECT LINE"); break;
9037 default: p
= N_(" SELECT BLOCK"); break;
9039 MSG_PUTS_ATTR(_(p
), attr
);
9042 MSG_PUTS_ATTR(" --", attr
);
9048 #ifdef FEAT_INS_EXPAND
9049 && edit_submode
== NULL
/* otherwise it gets too long */
9053 MSG_PUTS_ATTR(_("recording"), attr
);
9057 mode_displayed
= TRUE
;
9058 if (need_clear
|| clear_cmdline
)
9060 msg_didout
= FALSE
; /* overwrite this message */
9063 need_wait_return
= nwr_save
; /* never ask for hit-return for this */
9065 else if (clear_cmdline
&& msg_silent
== 0)
9066 /* Clear the whole command line. Will reset "clear_cmdline". */
9069 #ifdef FEAT_CMDL_INFO
9071 /* In Visual mode the size of the selected area must be redrawn. */
9076 /* If the last window has no status line, the ruler is after the mode
9077 * message and must be redrawn */
9079 # ifdef FEAT_WINDOWS
9080 && lastwin
->w_status_height
== 0
9083 win_redr_ruler(lastwin
, TRUE
);
9085 redraw_cmdline
= FALSE
;
9086 clear_cmdline
= FALSE
;
9092 * Position for a mode message.
9102 * Delete mode message. Used when ESC is typed which is expected to end
9103 * Insert mode (but Insert mode didn't end yet!).
9104 * Caller should check "mode_displayed".
9111 * Don't delete it right now, when not redrawing or insided a mapping.
9113 if (!redrawing() || (!force
&& char_avail() && !KeyTyped
))
9114 redraw_cmdline
= TRUE
; /* delete mode later */
9119 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM
));
9124 #if defined(FEAT_WINDOWS)
9126 * Draw the tab pages line at the top of the Vim window.
9143 int attr_sel
= hl_attr(HLF_TPS
);
9144 int attr_nosel
= hl_attr(HLF_TP
);
9145 int attr_fill
= hl_attr(HLF_TPF
);
9148 int use_sep_chars
= (t_colors
< 8
9154 redraw_tabline
= FALSE
;
9156 #ifdef FEAT_GUI_TABLINE
9157 /* Take care of a GUI tabline. */
9158 if (gui_use_tabline())
9160 gui_update_tabline();
9165 if (tabline_height() < 1)
9168 #if defined(FEAT_STL_OPT)
9170 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */
9171 for (scol
= 0; scol
< Columns
; ++scol
)
9172 TabPageIdxs
[scol
] = 0;
9174 /* Use the 'tabline' option if it's set. */
9177 int save_called_emsg
= called_emsg
;
9179 /* Check for an error. If there is one we would loop in redrawing the
9180 * screen. Avoid that by making 'tabline' empty. */
9181 called_emsg
= FALSE
;
9182 win_redr_custom(NULL
, FALSE
);
9184 set_string_option_direct((char_u
*)"tabline", -1,
9185 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9186 called_emsg
|= save_called_emsg
;
9191 for (tp
= first_tabpage
; tp
!= NULL
; tp
= tp
->tp_next
)
9194 tabwidth
= (Columns
- 1 + tabcount
/ 2) / tabcount
;
9201 for (tp
= first_tabpage
; tp
!= NULL
&& col
< Columns
- 4;
9206 if (tp
->tp_topframe
== topframe
)
9208 if (use_sep_chars
&& col
> 0)
9209 screen_putchar('|', 0, col
++, attr
);
9211 if (tp
->tp_topframe
!= topframe
)
9214 screen_putchar(' ', 0, col
++, attr
);
9223 cwp
= tp
->tp_curwin
;
9224 wp
= tp
->tp_firstwin
;
9228 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
9229 if (bufIsChanged(wp
->w_buffer
))
9231 if (modified
|| wincount
> 1)
9235 vim_snprintf((char *)NameBuff
, MAXPATHL
, "%d", wincount
);
9236 len
= (int)STRLEN(NameBuff
);
9237 if (col
+ len
>= Columns
- 3)
9239 screen_puts_len(NameBuff
, len
, 0, col
,
9240 #if defined(FEAT_SYN_HL)
9241 hl_combine_attr(attr
, hl_attr(HLF_T
))
9249 screen_puts_len((char_u
*)"+", 1, 0, col
++, attr
);
9250 screen_putchar(' ', 0, col
++, attr
);
9253 room
= scol
- col
+ tabwidth
- 1;
9256 /* Get buffer name in NameBuff[] */
9257 get_trans_bufname(cwp
->w_buffer
);
9258 shorten_dir(NameBuff
);
9259 len
= vim_strsize(NameBuff
);
9265 len
-= ptr2cells(p
);
9275 if (len
> Columns
- col
- 1)
9276 len
= Columns
- col
- 1;
9278 screen_puts_len(p
, (int)STRLEN(p
), 0, col
, attr
);
9281 screen_putchar(' ', 0, col
++, attr
);
9283 /* Store the tab page number in TabPageIdxs[], so that
9284 * jump_to_mouse() knows where each one is. */
9287 TabPageIdxs
[scol
++] = tabcount
;
9294 screen_fill(0, 1, col
, (int)Columns
, c
, c
, attr_fill
);
9296 /* Put an "X" for closing the current tab if there are several. */
9297 if (first_tabpage
->tp_next
!= NULL
)
9299 screen_putchar('X', 0, (int)Columns
- 1, attr_nosel
);
9300 TabPageIdxs
[Columns
- 1] = -999;
9304 /* Reset the flag here again, in case evaluating 'tabline' causes it to be
9306 redraw_tabline
= FALSE
;
9310 * Get buffer name for "buf" into NameBuff[].
9311 * Takes care of special buffer names and translates special characters.
9314 get_trans_bufname(buf
)
9317 if (buf_spname(buf
) != NULL
)
9318 STRCPY(NameBuff
, buf_spname(buf
));
9320 home_replace(buf
, buf
->b_fname
, NameBuff
, MAXPATHL
, TRUE
);
9321 trans_characters(NameBuff
, MAXPATHL
);
9325 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
9327 * Get the character to use in a status line. Get its attributes in "*attr".
9330 fillchar_status(attr
, is_curwin
)
9337 *attr
= hl_attr(HLF_S
);
9342 *attr
= hl_attr(HLF_SNC
);
9345 /* Use fill when there is highlighting, and highlighting of current
9346 * window differs, or the fillchars differ, or this is not the
9348 if (*attr
!= 0 && ((hl_attr(HLF_S
) != hl_attr(HLF_SNC
)
9349 || !is_curwin
|| firstwin
== lastwin
)
9350 || (fill_stl
!= fill_stlnc
)))
9358 #ifdef FEAT_VERTSPLIT
9360 * Get the character to use in a separator between vertically split windows.
9361 * Get its attributes in "*attr".
9367 *attr
= hl_attr(HLF_C
);
9368 if (*attr
== 0 && fill_vert
== ' ')
9376 * Return TRUE if redrawing should currently be done.
9381 return (!RedrawingDisabled
9382 && !(p_lz
&& char_avail() && !KeyTyped
&& !do_redraw
));
9386 * Return TRUE if printing messages should currently be done.
9391 return (!(p_lz
&& char_avail() && !KeyTyped
));
9395 * Show current status info in ruler and various other places
9396 * If always is FALSE, only show ruler if position has changed.
9402 if (!always
&& !redrawing())
9404 #ifdef FEAT_INS_EXPAND
9407 # ifdef FEAT_WINDOWS
9408 /* Don't redraw right now, do it later. */
9409 curwin
->w_redr_status
= TRUE
;
9414 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS)
9415 if ((*p_stl
!= NUL
|| *curwin
->w_p_stl
!= NUL
) && curwin
->w_status_height
)
9417 redraw_custum_statusline(curwin
);
9421 #ifdef FEAT_CMDL_INFO
9422 win_redr_ruler(curwin
, always
);
9427 # ifdef FEAT_STL_OPT
9428 || (p_icon
&& (stl_syntax
& STL_IN_ICON
))
9429 || (p_title
&& (stl_syntax
& STL_IN_TITLE
))
9435 /* Redraw the tab pages line if needed. */
9441 #ifdef FEAT_CMDL_INFO
9443 win_redr_ruler(wp
, always
)
9451 int empty_line
= FALSE
;
9455 #ifdef FEAT_VERTSPLIT
9458 int width
= Columns
;
9459 # define WITH_OFF(x) x
9460 # define WITH_WIDTH(x) x
9462 # define WITH_OFF(x) 0
9463 # define WITH_WIDTH(x) Columns
9464 # define this_ru_col ru_col
9467 /* If 'ruler' off or redrawing disabled, don't do anything */
9472 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
9473 * after deleting lines, before cursor.lnum is corrected.
9475 if (wp
->w_cursor
.lnum
> wp
->w_buffer
->b_ml
.ml_line_count
)
9478 #ifdef FEAT_INS_EXPAND
9479 /* Don't draw the ruler while doing insert-completion, it might overwrite
9480 * the (long) mode message. */
9481 # ifdef FEAT_WINDOWS
9482 if (wp
== lastwin
&& lastwin
->w_status_height
== 0)
9484 if (edit_submode
!= NULL
)
9486 /* Don't draw the ruler when the popup menu is visible, it may overlap. */
9494 int save_called_emsg
= called_emsg
;
9496 called_emsg
= FALSE
;
9497 win_redr_custom(wp
, TRUE
);
9499 set_string_option_direct((char_u
*)"rulerformat", -1,
9500 (char_u
*)"", OPT_FREE
, SID_ERROR
);
9501 called_emsg
|= save_called_emsg
;
9507 * Check if not in Insert mode and the line is empty (will show "0-1").
9509 if (!(State
& INSERT
)
9510 && *ml_get_buf(wp
->w_buffer
, wp
->w_cursor
.lnum
, FALSE
) == NUL
)
9514 * Only draw the ruler when something changed.
9516 validate_virtcol_win(wp
);
9519 || wp
->w_cursor
.lnum
!= wp
->w_ru_cursor
.lnum
9520 || wp
->w_cursor
.col
!= wp
->w_ru_cursor
.col
9521 || wp
->w_virtcol
!= wp
->w_ru_virtcol
9522 #ifdef FEAT_VIRTUALEDIT
9523 || wp
->w_cursor
.coladd
!= wp
->w_ru_cursor
.coladd
9525 || wp
->w_topline
!= wp
->w_ru_topline
9526 || wp
->w_buffer
->b_ml
.ml_line_count
!= wp
->w_ru_line_count
9528 || wp
->w_topfill
!= wp
->w_ru_topfill
9530 || empty_line
!= wp
->w_ru_empty
)
9534 if (wp
->w_status_height
)
9536 row
= W_WINROW(wp
) + wp
->w_height
;
9537 fillchar
= fillchar_status(&attr
, wp
== curwin
);
9538 # ifdef FEAT_VERTSPLIT
9540 width
= W_WIDTH(wp
);
9549 #ifdef FEAT_VERTSPLIT
9555 /* In list mode virtcol needs to be recomputed */
9556 virtcol
= wp
->w_virtcol
;
9557 if (wp
->w_p_list
&& lcs_tab1
== NUL
)
9559 wp
->w_p_list
= FALSE
;
9560 getvvcol(wp
, &wp
->w_cursor
, NULL
, &virtcol
, NULL
);
9561 wp
->w_p_list
= TRUE
;
9565 * Some sprintfs return the length, some return a pointer.
9566 * To avoid portability problems we use strlen() here.
9568 sprintf((char *)buffer
, "%ld,",
9569 (wp
->w_buffer
->b_ml
.ml_flags
& ML_EMPTY
)
9571 : (long)(wp
->w_cursor
.lnum
));
9572 col_print(buffer
+ STRLEN(buffer
),
9573 empty_line
? 0 : (int)wp
->w_cursor
.col
+ 1,
9577 * Add a "50%" if there is room for it.
9578 * On the last line, don't print in the last column (scrolls the
9579 * screen up on some terminals).
9581 i
= (int)STRLEN(buffer
);
9582 get_rel_pos(wp
, buffer
+ i
+ 1);
9583 o
= i
+ vim_strsize(buffer
+ i
+ 1);
9585 if (wp
->w_status_height
== 0) /* can't use last char of screen */
9588 #ifdef FEAT_VERTSPLIT
9589 this_ru_col
= ru_col
- (Columns
- width
);
9590 if (this_ru_col
< 0)
9593 /* Never use more than half the window/screen width, leave the other
9594 * half for the filename. */
9595 if (this_ru_col
< (WITH_WIDTH(width
) + 1) / 2)
9596 this_ru_col
= (WITH_WIDTH(width
) + 1) / 2;
9597 if (this_ru_col
+ o
< WITH_WIDTH(width
))
9599 while (this_ru_col
+ o
< WITH_WIDTH(width
))
9603 i
+= (*mb_char2bytes
)(fillchar
, buffer
+ i
);
9606 buffer
[i
++] = fillchar
;
9609 get_rel_pos(wp
, buffer
+ i
);
9611 /* Truncate at window boundary. */
9616 for (i
= 0; buffer
[i
] != NUL
; i
+= (*mb_ptr2len
)(buffer
+ i
))
9618 o
+= (*mb_ptr2cells
)(buffer
+ i
);
9619 if (this_ru_col
+ o
> WITH_WIDTH(width
))
9628 if (this_ru_col
+ (int)STRLEN(buffer
) > WITH_WIDTH(width
))
9629 buffer
[WITH_WIDTH(width
) - this_ru_col
] = NUL
;
9631 screen_puts(buffer
, row
, this_ru_col
+ WITH_OFF(off
), attr
);
9633 screen_fill(row
, row
+ 1,
9634 this_ru_col
+ WITH_OFF(off
) + (int)STRLEN(buffer
),
9635 (int)(WITH_OFF(off
) + WITH_WIDTH(width
)),
9636 fillchar
, fillchar
, attr
);
9637 /* don't redraw the cmdline because of showing the ruler */
9639 wp
->w_ru_cursor
= wp
->w_cursor
;
9640 wp
->w_ru_virtcol
= wp
->w_virtcol
;
9641 wp
->w_ru_empty
= empty_line
;
9642 wp
->w_ru_topline
= wp
->w_topline
;
9643 wp
->w_ru_line_count
= wp
->w_buffer
->b_ml
.ml_line_count
;
9645 wp
->w_ru_topfill
= wp
->w_topfill
;
9651 #if defined(FEAT_LINEBREAK) || defined(PROTO)
9653 * Return the width of the 'number' column.
9654 * Caller may need to check if 'number' is set.
9655 * Otherwise it depends on 'numberwidth' and the line count.
9664 lnum
= wp
->w_buffer
->b_ml
.ml_line_count
;
9665 if (lnum
== wp
->w_nrwidth_line_count
)
9666 return wp
->w_nrwidth_width
;
9667 wp
->w_nrwidth_line_count
= lnum
;
9676 /* 'numberwidth' gives the minimal width plus one */
9677 if (n
< wp
->w_p_nuw
- 1)
9678 n
= wp
->w_p_nuw
- 1;
9680 wp
->w_nrwidth_width
= n
;