vim-patch:8.1.2047: cannot check the current state

Problem:    Cannot check the current state.
Solution:   Add the state() function.

0e57dd859e

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-08-21 11:22:25 +08:00
parent 4956f26744
commit 64ccfdaafe
7 changed files with 161 additions and 8 deletions

View File

@@ -482,6 +482,20 @@ bool check_text_or_curbuf_locked(oparg_T *oap)
return true;
}
static oparg_T *current_oap = NULL;
/// Check if an operator was started but not finished yet.
/// Includes typing a count or a register name.
bool op_pending(void)
{
return !(current_oap != NULL
&& !finish_op
&& current_oap->prev_opcount == 0
&& current_oap->prev_count0 == 0
&& current_oap->op_type == OP_NOP
&& current_oap->regname == NUL);
}
/// Normal state entry point. This is called on:
///
/// - Startup, In this case the function never returns.
@@ -490,15 +504,18 @@ bool check_text_or_curbuf_locked(oparg_T *oap)
/// for example. Returns when re-entering ex mode(because ex mode recursion is
/// not allowed)
///
/// This used to be called main_loop on main.c
/// This used to be called main_loop() on main.c
void normal_enter(bool cmdwin, bool noexmode)
{
NormalState state;
normal_state_init(&state);
oparg_T *prev_oap = current_oap;
current_oap = &state.oa;
state.cmdwin = cmdwin;
state.noexmode = noexmode;
state.toplevel = (!cmdwin || cmdwin_result == 0) && !noexmode;
state_enter(&state.state);
current_oap = prev_oap;
}
static void normal_prepare(NormalState *s)
@@ -1299,12 +1316,7 @@ static void normal_check_buffer_modified(NormalState *s)
/// type a character, trigger SafeState.
static void normal_check_safe_state(NormalState *s)
{
may_trigger_safestate(!finish_op
&& s->oa.prev_opcount > 0
&& s->oa.prev_count0 == 0
&& s->oa.op_type == OP_NOP
&& s->oa.regname == NUL
&& restart_edit == 0);
may_trigger_safestate(!op_pending() && restart_edit == 0);
}
static void normal_check_folds(NormalState *s)