Define special key for asynchronous events

K_EVENT/KE_EVENT are used to signal any loop that reads user input(scattered
across normal.c edit.c , ex_getln.c and message.c) of asynchronous events that
were not initiated by the user.

Representing non-user asynchronous events as special keys has the following
advantages:

- We reuse the normal vim redrawing code. As far as the rest of the code in
  edit.c/normal.c is concerned, it's just the user pressing another key.
- Assume less about vim tolerance for "out-of-band" modifications to its
  internal state.
- We still have a very complex codebase and it's hard to predict what bugs may
  be introduced by these changes. With this we implement asynchronicity in a way
  that will be more "natural" to the editor and has less chance of causing
  unpredictable behavior.

As the code is refactored, we will be able to treat user input as an 'event
type' and not the other way around(With this we are treating arbitrary events as
a special case of user input).
This commit is contained in:
Thiago de Arruda
2014-04-07 16:37:14 -03:00
parent 1fc7d6a0c5
commit fe38baed38
10 changed files with 86 additions and 78 deletions

View File

@@ -54,6 +54,7 @@
#include "ui.h"
#include "undo.h"
#include "window.h"
#include "os/event.h"
/*
* The Visual area is remembered for reselection.
@@ -177,6 +178,7 @@ static void nv_join(cmdarg_T *cap);
static void nv_put(cmdarg_T *cap);
static void nv_open(cmdarg_T *cap);
static void nv_cursorhold(cmdarg_T *cap);
static void nv_event(cmdarg_T *cap);
static char *e_noident = N_("E349: No identifier under cursor");
@@ -409,6 +411,7 @@ static const struct nv_cmd {
{K_F8, farsi_fkey, 0, 0},
{K_F9, farsi_fkey, 0, 0},
{K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0},
{K_EVENT, nv_event, NV_KEEPREG, 0},
};
/* Number of commands in nv_cmds[]. */
@@ -7485,3 +7488,8 @@ static void nv_cursorhold(cmdarg_T *cap)
did_cursorhold = TRUE;
cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
}
static void nv_event(cmdarg_T *cap)
{
event_process();
}