normal: Split normal_check into multiple functions

Split most code in `normal_check` in:

- `normal_check_stuff_buffer`
- `normal_check_interrupt`
- `normal_check_cursor_moved`
- `normal_check_text_changed`
- `normal_check_folds`
- `normal_redraw`
This commit is contained in:
Thiago de Arruda
2015-10-06 08:30:09 -03:00
parent 8d93621c63
commit fa83b03fea

View File

@@ -1067,14 +1067,8 @@ normal_end:
return 1; return 1;
} }
// Function executed before each iteration of normal mode. static void normal_check_stuff_buffer(NormalState *s)
// Return:
// 1 if the iteration should continue normally
// -1 if the iteration should be skipped
// 0 if the main loop must exit
static int normal_check(VimState *state)
{ {
NormalState *s = (NormalState *)state;
if (stuff_empty()) { if (stuff_empty()) {
did_check_timestamps = false; did_check_timestamps = false;
@@ -1095,7 +1089,10 @@ static int normal_check(VimState *state)
need_fileinfo = false; need_fileinfo = false;
} }
} }
}
static void normal_check_interrupt(NormalState *s)
{
// Reset "got_int" now that we got back to the main loop. Except when // Reset "got_int" now that we got back to the main loop. Except when
// inside a ":g/pat/cmd" command, then the "got_int" needs to abort // inside a ":g/pat/cmd" command, then the "got_int" needs to abort
// the ":g" command. // the ":g" command.
@@ -1119,18 +1116,10 @@ static int normal_check(VimState *state)
} else { } else {
s->previous_got_int = false; s->previous_got_int = false;
} }
}
if (!exmode_active) { static void normal_check_cursor_moved(NormalState *s)
msg_scroll = false; {
}
quit_more = false;
// If skip redraw is set (for ":" in wait_return()), don't redraw now.
// If there is nothing in the stuff_buffer or do_redraw is TRUE,
// update cursor and redraw.
if (skip_redraw || exmode_active) {
skip_redraw = false;
} else if (do_redraw || stuff_empty()) {
// Trigger CursorMoved if the cursor moved. // Trigger CursorMoved if the cursor moved.
if (!finish_op && (has_cursormoved() || curwin->w_p_cole > 0) if (!finish_op && (has_cursormoved() || curwin->w_p_cole > 0)
&& !equalpos(last_cursormoved, curwin->w_cursor)) { && !equalpos(last_cursormoved, curwin->w_cursor)) {
@@ -1146,7 +1135,10 @@ static int normal_check(VimState *state)
last_cursormoved = curwin->w_cursor; last_cursormoved = curwin->w_cursor;
} }
}
static void normal_check_text_changed(NormalState *s)
{
// Trigger TextChanged if b_changedtick differs. // Trigger TextChanged if b_changedtick differs.
if (!finish_op && has_textchanged() if (!finish_op && has_textchanged()
&& last_changedtick != curbuf->b_changedtick) { && last_changedtick != curbuf->b_changedtick) {
@@ -1157,14 +1149,10 @@ static int normal_check(VimState *state)
last_changedtick_buf = curbuf; last_changedtick_buf = curbuf;
last_changedtick = curbuf->b_changedtick; last_changedtick = curbuf->b_changedtick;
} }
}
// Scroll-binding for diff mode may have been postponed until static void normal_check_folds(NormalState *s)
// here. Avoids doing it for every change. {
if (diff_need_scrollbind) {
check_scrollbind((linenr_T)0, 0L);
diff_need_scrollbind = false;
}
// Include a closed fold completely in the Visual area. // Include a closed fold completely in the Visual area.
foldAdjustVisual(); foldAdjustVisual();
@@ -1179,7 +1167,10 @@ static int normal_check(VimState *state)
foldOpenCursor(); foldOpenCursor();
} }
} }
}
static void normal_redraw(NormalState *s)
{
// Before redrawing, make sure w_topline is correct, and w_leftcol // Before redrawing, make sure w_topline is correct, and w_leftcol
// if lines don't wrap, and w_skipcol if lines wrap. // if lines don't wrap, and w_skipcol if lines wrap.
update_topline(); update_topline();
@@ -1236,7 +1227,42 @@ static int normal_check(VimState *state)
} }
setcursor(); setcursor();
}
// Function executed before each iteration of normal mode.
// Return:
// 1 if the iteration should continue normally
// -1 if the iteration should be skipped
// 0 if the main loop must exit
static int normal_check(VimState *state)
{
NormalState *s = (NormalState *)state;
normal_check_stuff_buffer(s);
normal_check_interrupt(s);
if (!exmode_active) {
msg_scroll = false;
}
quit_more = false;
// If skip redraw is set (for ":" in wait_return()), don't redraw now.
// If there is nothing in the stuff_buffer or do_redraw is TRUE,
// update cursor and redraw.
if (skip_redraw || exmode_active) {
skip_redraw = false;
} else if (do_redraw || stuff_empty()) {
normal_check_cursor_moved(s);
normal_check_text_changed(s);
// Scroll-binding for diff mode may have been postponed until
// here. Avoids doing it for every change.
if (diff_need_scrollbind) {
check_scrollbind((linenr_T)0, 0L);
diff_need_scrollbind = false;
}
normal_check_folds(s);
normal_redraw(s);
do_redraw = false; do_redraw = false;
// Now that we have drawn the first screen all the startup stuff // Now that we have drawn the first screen all the startup stuff