-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.c
11159 lines (10447 loc) · 270 KB
/
screen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* screen.c: code for displaying on the screen
*
* Output to the screen (console, terminal emulator or GUI window) is minimized
* by remembering what is already on the screen, and only updating the parts
* that changed.
*
* ScreenLines[off] Contains a copy of the whole screen, as it is currently
* displayed (excluding text written by external commands).
* ScreenAttrs[off] Contains the associated attributes.
* LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[]
* for each line.
* LineWraps[row] Flag for each line whether it wraps to the next line.
*
* For double-byte characters, two consecutive bytes in ScreenLines[] can form
* one character which occupies two display cells.
* For UTF-8 a multi-byte character is converted to Unicode and stored in
* ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII
* character without composing chars ScreenLinesUC[] will be 0 and
* ScreenLinesC[][] is not used. When the character occupies two display
* cells the next byte in ScreenLines[] is 0.
* ScreenLinesC[][] contain up to 'maxcombine' composing characters
* (drawn on top of the first character). There is 0 after the last one used.
* ScreenLines2[] is only used for euc-jp to store the second byte if the
* first byte is 0x8e (single-width character).
*
* The screen_*() functions write to the screen and handle updating
* ScreenLines[].
*
* update_screen() is the function that updates all windows and status lines.
* It is called form the main loop when must_redraw is non-zero. It may be
* called from other places when an immediate screen update is needed.
*
* The part of the buffer that is displayed in a window is set with:
* - w_topline (first buffer line in window)
* - w_topfill (filler lines above the first line)
* - w_leftcol (leftmost window cell in window),
* - w_skipcol (skipped window cells of first line)
*
* Commands that only move the cursor around in a window, do not need to take
* action to update the display. The main loop will check if w_topline is
* valid and update it (scroll the window) when needed.
*
* Commands that scroll a window change w_topline and must call
* check_cursor() to move the cursor into the visible part of the window, and
* call redraw_later(VALID) to have the window displayed by update_screen()
* later.
*
* Commands that change text in the buffer must call changed_bytes() or
* changed_lines() to mark the area that changed and will require updating
* later. The main loop will call update_screen(), which will update each
* window that shows the changed buffer. This assumes text above the change
* can remain displayed as it is. Text after the change may need updating for
* scrolling, folding and syntax highlighting.
*
* Commands that change how a window is displayed (e.g., setting 'list') or
* invalidate the contents of a window in another way (e.g., change fold
* settings), must call redraw_later(NOT_VALID) to have the whole window
* redisplayed by update_screen() later.
*
* Commands that change how a buffer is displayed (e.g., setting 'tabstop')
* must call redraw_curbuf_later(NOT_VALID) to have all the windows for the
* buffer redisplayed by update_screen() later.
*
* Commands that change highlighting and possibly cause a scroll too must call
* redraw_later(SOME_VALID) to update the whole window but still use scrolling
* to avoid redrawing everything. But the length of displayed lines must not
* change, use NOT_VALID then.
*
* Commands that move the window position must call redraw_later(NOT_VALID).
* TODO: should minimize redrawing by scrolling when possible.
*
* Commands that change everything (e.g., resizing the screen) must call
* redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR).
*
* Things that are handled indirectly:
* - When messages scroll the screen up, msg_scrolled will be set and
* update_screen() called to redraw.
*/
#include "vim.h"
#define MB_FILLER_CHAR '<' /* character used when a double-width character
* doesn't fit. */
/*
* The attributes that are actually active for writing to the screen.
*/
static int screen_attr = 0;
/*
* Positioning the cursor is reduced by remembering the last position.
* Mostly used by windgoto() and screen_char().
*/
static int screen_cur_row, screen_cur_col; /* last known cursor position */
#ifdef FEAT_SEARCH_EXTRA
static match_T search_hl; /* used for 'hlsearch' highlight matching */
#endif
#ifdef FEAT_FOLDING
static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */
static int compute_foldcolumn(win_T *wp, int col);
#endif
/* Flag that is set when drawing for a callback, not from the main command
* loop. */
static int redrawing_for_callback = 0;
/*
* Buffer for one screen line (characters and attributes).
*/
static schar_T *current_ScreenLine;
static void win_update(win_T *wp);
static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl);
#ifdef FEAT_FOLDING
static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row);
static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum);
static void copy_text_attr(int off, char_u *buf, int len, int attr);
#endif
static int win_line(win_T *, linenr_T, int, int, int nochange, proftime_T *syntax_tm);
static int char_needs_redraw(int off_from, int off_to, int cols);
#ifdef FEAT_WINDOWS
static void draw_vsep_win(win_T *wp, int row);
#endif
#ifdef FEAT_STL_OPT
static void redraw_custom_statusline(win_T *wp);
#endif
#ifdef FEAT_SEARCH_EXTRA
# define SEARCH_HL_PRIORITY 0
static void start_search_hl(void);
static void end_search_hl(void);
static void init_search_hl(win_T *wp);
static void prepare_search_hl(win_T *wp, linenr_T lnum);
static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur);
static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol);
#endif
static void screen_start_highlight(int attr);
static void screen_char(unsigned off, int row, int col);
#ifdef FEAT_MBYTE
static void screen_char_2(unsigned off, int row, int col);
#endif
static void screenclear2(void);
static void lineclear(unsigned off, int width, int attr);
static void lineinvalid(unsigned off, int width);
#ifdef FEAT_WINDOWS
static void linecopy(int to, int from, win_T *wp);
static void redraw_block(int row, int end, win_T *wp);
#endif
static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del, int clear_attr);
static void win_rest_invalid(win_T *wp);
static void msg_pos_mode(void);
static void recording_mode(int attr);
#if defined(FEAT_WINDOWS)
static void draw_tabline(void);
#endif
#if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT)
static int fillchar_status(int *attr, win_T *wp);
#endif
#ifdef FEAT_WINDOWS
static int fillchar_vsep(int *attr);
#endif
#ifdef FEAT_STL_OPT
static void win_redr_custom(win_T *wp, int draw_ruler);
#endif
#ifdef FEAT_CMDL_INFO
static void win_redr_ruler(win_T *wp, int always);
#endif
#if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS)
/* Ugly global: overrule attribute used by screen_char() */
static int screen_char_attr = 0;
#endif
#if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME)
/* Can limit syntax highlight time to 'redrawtime'. */
# define SYN_TIME_LIMIT 1
#endif
#ifdef FEAT_RIGHTLEFT
# define HAS_RIGHTLEFT(x) x
#else
# define HAS_RIGHTLEFT(x) FALSE
#endif
/*
* Redraw the current window later, with update_screen(type).
* Set must_redraw only if not already set to a higher value.
* e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
*/
void
redraw_later(int type)
{
redraw_win_later(curwin, type);
}
void
redraw_win_later(
win_T *wp,
int type)
{
if (wp->w_redr_type < type)
{
wp->w_redr_type = type;
if (type >= NOT_VALID)
wp->w_lines_valid = 0;
if (must_redraw < type) /* must_redraw is the maximum of all windows */
must_redraw = type;
}
}
/*
* Force a complete redraw later. Also resets the highlighting. To be used
* after executing a shell command that messes up the screen.
*/
void
redraw_later_clear(void)
{
redraw_all_later(CLEAR);
#ifdef FEAT_GUI
if (gui.in_use)
/* Use a code that will reset gui.highlight_mask in
* gui_stop_highlight(). */
screen_attr = HL_ALL + 1;
else
#endif
/* Use attributes that is very unlikely to appear in text. */
screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE | HL_STRIKETHROUGH;
}
/*
* Mark all windows to be redrawn later.
*/
void
redraw_all_later(int type)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
{
redraw_win_later(wp, type);
}
}
/*
* Mark all windows that are editing the current buffer to be updated later.
*/
void
redraw_curbuf_later(int type)
{
redraw_buf_later(curbuf, type);
}
void
redraw_buf_later(buf_T *buf, int type)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer == buf)
redraw_win_later(wp, type);
}
}
void
redraw_buf_and_status_later(buf_T *buf, int type)
{
win_T *wp;
#ifdef FEAT_WILDMENU
if (wild_menu_showing != 0)
/* Don't redraw while the command line completion is displayed, it
* would disappear. */
return;
#endif
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer == buf)
{
redraw_win_later(wp, type);
#ifdef FEAT_WINDOWS
wp->w_redr_status = TRUE;
#endif
}
}
}
/*
* Redraw as soon as possible. When the command line is not scrolled redraw
* right away and restore what was on the command line.
* Return a code indicating what happened.
*/
int
redraw_asap(int type)
{
int rows;
int cols = screen_Columns;
int r;
int ret = 0;
schar_T *screenline; /* copy from ScreenLines[] */
sattr_T *screenattr; /* copy from ScreenAttrs[] */
#ifdef FEAT_MBYTE
int i;
u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */
u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */
schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */
#endif
redraw_later(type);
if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting)
return ret;
/* Allocate space to save the text displayed in the command line area. */
rows = screen_Rows - cmdline_row;
screenline = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
screenattr = (sattr_T *)lalloc(
(long_u)(rows * cols * sizeof(sattr_T)), FALSE);
if (screenline == NULL || screenattr == NULL)
ret = 2;
#ifdef FEAT_MBYTE
if (enc_utf8)
{
screenlineUC = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
if (screenlineUC == NULL)
ret = 2;
for (i = 0; i < p_mco; ++i)
{
screenlineC[i] = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
if (screenlineC[i] == NULL)
ret = 2;
}
}
if (enc_dbcs == DBCS_JPNU)
{
screenline2 = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
if (screenline2 == NULL)
ret = 2;
}
#endif
if (ret != 2)
{
/* Save the text displayed in the command line area. */
for (r = 0; r < rows; ++r)
{
mch_memmove(screenline + r * cols,
ScreenLines + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(schar_T));
mch_memmove(screenattr + r * cols,
ScreenAttrs + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(sattr_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
mch_memmove(screenlineUC + r * cols,
ScreenLinesUC + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(screenlineC[i] + r * cols,
ScreenLinesC[i] + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
mch_memmove(screenline2 + r * cols,
ScreenLines2 + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(schar_T));
#endif
}
update_screen(0);
ret = 3;
if (must_redraw == 0)
{
int off = (int)(current_ScreenLine - ScreenLines);
/* Restore the text displayed in the command line area. */
for (r = 0; r < rows; ++r)
{
mch_memmove(current_ScreenLine,
screenline + r * cols,
(size_t)cols * sizeof(schar_T));
mch_memmove(ScreenAttrs + off,
screenattr + r * cols,
(size_t)cols * sizeof(sattr_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
mch_memmove(ScreenLinesUC + off,
screenlineUC + r * cols,
(size_t)cols * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(ScreenLinesC[i] + off,
screenlineC[i] + r * cols,
(size_t)cols * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
mch_memmove(ScreenLines2 + off,
screenline2 + r * cols,
(size_t)cols * sizeof(schar_T));
#endif
screen_line(cmdline_row + r, 0, cols, cols, FALSE);
}
ret = 4;
}
}
vim_free(screenline);
vim_free(screenattr);
#ifdef FEAT_MBYTE
if (enc_utf8)
{
vim_free(screenlineUC);
for (i = 0; i < p_mco; ++i)
vim_free(screenlineC[i]);
}
if (enc_dbcs == DBCS_JPNU)
vim_free(screenline2);
#endif
/* Show the intro message when appropriate. */
maybe_intro_message();
setcursor();
return ret;
}
/*
* Invoked after an asynchronous callback is called.
* If an echo command was used the cursor needs to be put back where
* it belongs. If highlighting was changed a redraw is needed.
* If "call_update_screen" is FALSE don't call update_screen() when at the
* command line.
*/
void
redraw_after_callback(int call_update_screen)
{
++redrawing_for_callback;
if (State == HITRETURN || State == ASKMORE)
; /* do nothing */
else if (State & CMDLINE)
{
/* Redrawing only works when the screen didn't scroll. Don't clear
* wildmenu entries. */
if (msg_scrolled == 0
#ifdef FEAT_WILDMENU
&& wild_menu_showing == 0
#endif
&& call_update_screen)
update_screen(0);
/* Redraw in the same position, so that the user can continue
* editing the command. */
redrawcmdline_ex(FALSE);
}
else if (State & (NORMAL | INSERT))
{
/* keep the command line if possible */
update_screen(VALID_NO_UPDATE);
setcursor();
}
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
/* Don't update the cursor when it is blinking and off to avoid
* flicker. */
if (!gui_mch_is_blink_off())
gui_update_cursor(FALSE, FALSE);
gui_mch_flush();
}
#endif
--redrawing_for_callback;
}
/*
* Changed something in the current window, at buffer line "lnum", that
* requires that line and possibly other lines to be redrawn.
* Used when entering/leaving Insert mode with the cursor on a folded line.
* Used to remove the "$" from a change command.
* Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
* may become invalid and the whole window will have to be redrawn.
*/
void
redrawWinline(
linenr_T lnum,
int invalid UNUSED) /* window line height is invalid now */
{
#ifdef FEAT_FOLDING
int i;
#endif
if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum)
curwin->w_redraw_top = lnum;
if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum)
curwin->w_redraw_bot = lnum;
redraw_later(VALID);
#ifdef FEAT_FOLDING
if (invalid)
{
/* A w_lines[] entry for this lnum has become invalid. */
i = find_wl_entry(curwin, lnum);
if (i >= 0)
curwin->w_lines[i].wl_valid = FALSE;
}
#endif
}
/*
* Update all windows that are editing the current buffer.
*/
void
update_curbuf(int type)
{
redraw_curbuf_later(type);
update_screen(type);
}
/*
* Based on the current value of curwin->w_topline, transfer a screenfull
* of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
*/
void
update_screen(int type_arg)
{
int type = type_arg;
win_T *wp;
static int did_intro = FALSE;
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
int did_one;
#endif
#ifdef FEAT_GUI
int did_undraw = FALSE;
int gui_cursor_col;
int gui_cursor_row;
#endif
int no_update = FALSE;
/* Don't do anything if the screen structures are (not yet) valid. */
if (!screen_valid(TRUE))
return;
if (type == VALID_NO_UPDATE)
{
no_update = TRUE;
type = 0;
}
if (must_redraw)
{
if (type < must_redraw) /* use maximal type */
type = must_redraw;
/* must_redraw is reset here, so that when we run into some weird
* reason to redraw while busy redrawing (e.g., asynchronous
* scrolling), or update_topline() in win_update() will cause a
* scroll, the screen will be redrawn later or in win_update(). */
must_redraw = 0;
}
/* Need to update w_lines[]. */
if (curwin->w_lines_valid == 0 && type < NOT_VALID)
type = NOT_VALID;
/* Postpone the redrawing when it's not needed and when being called
* recursively. */
if (!redrawing() || updating_screen)
{
redraw_later(type); /* remember type for next time */
must_redraw = type;
if (type > INVERTED_ALL)
curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */
return;
}
updating_screen = TRUE;
#ifdef FEAT_SYN_HL
++display_tick; /* let syntax code know we're in a next round of
* display updating */
#endif
if (no_update)
++no_win_do_lines_ins;
/*
* if the screen was scrolled up when displaying a message, scroll it down
*/
if (msg_scrolled)
{
clear_cmdline = TRUE;
if (msg_scrolled > Rows - 5) /* clearing is faster */
type = CLEAR;
else if (type != CLEAR)
{
check_for_delay(FALSE);
if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL)
== FAIL)
type = CLEAR;
FOR_ALL_WINDOWS(wp)
{
if (W_WINROW(wp) < msg_scrolled)
{
if (W_WINROW(wp) + wp->w_height > msg_scrolled
&& wp->w_redr_type < REDRAW_TOP
&& wp->w_lines_valid > 0
&& wp->w_topline == wp->w_lines[0].wl_lnum)
{
wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
wp->w_redr_type = REDRAW_TOP;
}
else
{
wp->w_redr_type = NOT_VALID;
#ifdef FEAT_WINDOWS
if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp)
<= msg_scrolled)
wp->w_redr_status = TRUE;
#endif
}
}
}
if (!no_update)
redraw_cmdline = TRUE;
#ifdef FEAT_WINDOWS
redraw_tabline = TRUE;
#endif
}
msg_scrolled = 0;
need_wait_return = FALSE;
}
/* reset cmdline_row now (may have been changed temporarily) */
compute_cmdrow();
/* Check for changed highlighting */
if (need_highlight_changed)
highlight_changed();
if (type == CLEAR) /* first clear screen */
{
screenclear(); /* will reset clear_cmdline */
type = NOT_VALID;
/* must_redraw may be set indirectly, avoid another redraw later */
must_redraw = 0;
}
if (clear_cmdline) /* going to clear cmdline (done below) */
check_for_delay(FALSE);
#ifdef FEAT_LINEBREAK
/* Force redraw when width of 'number' or 'relativenumber' column
* changes. */
if (curwin->w_redr_type < NOT_VALID
&& curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
? number_width(curwin) : 0))
curwin->w_redr_type = NOT_VALID;
#endif
/*
* Only start redrawing if there is really something to do.
*/
if (type == INVERTED)
update_curswant();
if (curwin->w_redr_type < type
&& !((type == VALID
&& curwin->w_lines[0].wl_valid
#ifdef FEAT_DIFF
&& curwin->w_topfill == curwin->w_old_topfill
&& curwin->w_botfill == curwin->w_old_botfill
#endif
&& curwin->w_topline == curwin->w_lines[0].wl_lnum)
|| (type == INVERTED
&& VIsual_active
&& curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
&& curwin->w_old_visual_mode == VIsual_mode
&& (curwin->w_valid & VALID_VIRTCOL)
&& curwin->w_old_curswant == curwin->w_curswant)
))
curwin->w_redr_type = type;
#ifdef FEAT_WINDOWS
/* Redraw the tab pages line if needed. */
if (redraw_tabline || type >= NOT_VALID)
draw_tabline();
#endif
#ifdef FEAT_SYN_HL
/*
* Correct stored syntax highlighting info for changes in each displayed
* buffer. Each buffer must only be done once.
*/
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer->b_mod_set)
{
# ifdef FEAT_WINDOWS
win_T *wwp;
/* Check if we already did this buffer. */
for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
if (wwp->w_buffer == wp->w_buffer)
break;
# endif
if (
# ifdef FEAT_WINDOWS
wwp == wp &&
# endif
syntax_present(wp))
syn_stack_apply_changes(wp->w_buffer);
}
}
#endif
/*
* Go from top to bottom through the windows, redrawing the ones that need
* it.
*/
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
did_one = FALSE;
#endif
#ifdef FEAT_SEARCH_EXTRA
search_hl.rm.regprog = NULL;
#endif
FOR_ALL_WINDOWS(wp)
{
if (wp->w_redr_type != 0)
{
cursor_off();
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
if (!did_one)
{
did_one = TRUE;
# ifdef FEAT_SEARCH_EXTRA
start_search_hl();
# endif
# ifdef FEAT_CLIPBOARD
/* When Visual area changed, may have to update selection. */
if (clip_star.available && clip_isautosel_star())
clip_update_selection(&clip_star);
if (clip_plus.available && clip_isautosel_plus())
clip_update_selection(&clip_plus);
# endif
#ifdef FEAT_GUI
/* Remove the cursor before starting to do anything, because
* scrolling may make it difficult to redraw the text under
* it. */
if (gui.in_use && wp == curwin)
{
gui_cursor_col = gui.cursor_col;
gui_cursor_row = gui.cursor_row;
gui_undraw_cursor();
did_undraw = TRUE;
}
#endif
}
#endif
win_update(wp);
}
#ifdef FEAT_WINDOWS
/* redraw status line after the window to minimize cursor movement */
if (wp->w_redr_status)
{
cursor_off();
win_redr_status(wp);
}
#endif
}
#if defined(FEAT_SEARCH_EXTRA)
end_search_hl();
#endif
#ifdef FEAT_INS_EXPAND
/* May need to redraw the popup menu. */
if (pum_visible())
pum_redraw();
#endif
#ifdef FEAT_WINDOWS
/* Reset b_mod_set flags. Going through all windows is probably faster
* than going through all buffers (there could be many buffers). */
FOR_ALL_WINDOWS(wp)
wp->w_buffer->b_mod_set = FALSE;
#else
curbuf->b_mod_set = FALSE;
#endif
updating_screen = FALSE;
#ifdef FEAT_GUI
gui_may_resize_shell();
#endif
/* Clear or redraw the command line. Done last, because scrolling may
* mess up the command line. */
if (clear_cmdline || redraw_cmdline)
showmode();
if (no_update)
--no_win_do_lines_ins;
/* May put up an introductory message when not editing a file */
if (!did_intro)
maybe_intro_message();
did_intro = TRUE;
#ifdef FEAT_GUI
/* Redraw the cursor and update the scrollbars when all screen updating is
* done. */
if (gui.in_use)
{
out_flush(); /* required before updating the cursor */
if (did_undraw && !gui_mch_is_blink_off())
{
/* Put the GUI position where the cursor was, gui_update_cursor()
* uses that. */
gui.col = gui_cursor_col;
gui.row = gui_cursor_row;
# ifdef FEAT_MBYTE
gui.col = mb_fix_col(gui.col, gui.row);
# endif
gui_update_cursor(FALSE, FALSE);
screen_cur_col = gui.col;
screen_cur_row = gui.row;
}
gui_update_scrollbars(FALSE);
}
#endif
}
#if defined(FEAT_SIGNS) || defined(FEAT_GUI) || defined(FEAT_CONCEAL)
/*
* Prepare for updating one or more windows.
* Caller must check for "updating_screen" already set to avoid recursiveness.
*/
static void
update_prepare(void)
{
cursor_off();
updating_screen = TRUE;
#ifdef FEAT_GUI
/* Remove the cursor before starting to do anything, because scrolling may
* make it difficult to redraw the text under it. */
if (gui.in_use)
gui_undraw_cursor();
#endif
#ifdef FEAT_SEARCH_EXTRA
start_search_hl();
#endif
}
/*
* Finish updating one or more windows.
*/
static void
update_finish(void)
{
if (redraw_cmdline)
showmode();
# ifdef FEAT_SEARCH_EXTRA
end_search_hl();
# endif
updating_screen = FALSE;
# ifdef FEAT_GUI
gui_may_resize_shell();
/* Redraw the cursor and update the scrollbars when all screen updating is
* done. */
if (gui.in_use)
{
out_flush(); /* required before updating the cursor */
gui_update_cursor(FALSE, FALSE);
gui_update_scrollbars(FALSE);
}
# endif
}
#endif
#if defined(FEAT_CONCEAL) || defined(PROTO)
/*
* Return TRUE if the cursor line in window "wp" may be concealed, according
* to the 'concealcursor' option.
*/
int
conceal_cursor_line(win_T *wp)
{
int c;
if (*wp->w_p_cocu == NUL)
return FALSE;
if (get_real_state() & VISUAL)
c = 'v';
else if (State & INSERT)
c = 'i';
else if (State & NORMAL)
c = 'n';
else if (State & CMDLINE)
c = 'c';
else
return FALSE;
return vim_strchr(wp->w_p_cocu, c) != NULL;
}
/*
* Check if the cursor line needs to be redrawn because of 'concealcursor'.
*/
void
conceal_check_cursur_line(void)
{
if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin))
{
need_cursor_line_redraw = TRUE;
/* Need to recompute cursor column, e.g., when starting Visual mode
* without concealing. */
curs_columns(TRUE);
}
}
void
update_single_line(win_T *wp, linenr_T lnum)
{
int row;
int j;
#ifdef SYN_TIME_LIMIT
proftime_T syntax_tm;
#endif
/* Don't do anything if the screen structures are (not yet) valid. */
if (!screen_valid(TRUE) || updating_screen)
return;
if (lnum >= wp->w_topline && lnum < wp->w_botline
&& foldedCount(wp, lnum, &win_foldinfo) == 0)
{
#ifdef SYN_TIME_LIMIT
/* Set the time limit to 'redrawtime'. */
profile_setlimit(p_rdt, &syntax_tm);
#endif
update_prepare();
row = 0;
for (j = 0; j < wp->w_lines_valid; ++j)
{
if (lnum == wp->w_lines[j].wl_lnum)
{
screen_start(); /* not sure of screen cursor */
# ifdef FEAT_SEARCH_EXTRA
init_search_hl(wp);
start_search_hl();
prepare_search_hl(wp, lnum);
# endif
win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE,
#ifdef SYN_TIME_LIMIT
&syntax_tm
#else
NULL
#endif
);
# if defined(FEAT_SEARCH_EXTRA)
end_search_hl();
# endif
break;
}
row += wp->w_lines[j].wl_size;
}
update_finish();
}
need_cursor_line_redraw = FALSE;
}
#endif
#if defined(FEAT_SIGNS) || defined(PROTO)
void
update_debug_sign(buf_T *buf, linenr_T lnum)
{
win_T *wp;
int doit = FALSE;
# ifdef FEAT_FOLDING
win_foldinfo.fi_level = 0;