aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-10-04 09:38:26 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-10-26 10:52:01 -0300
commit82bb8c887c5625a77969c70a38ce94fce803301e (patch)
tree9faae13de562f1aeee839fa43a368debc8172120 /src
parentdae006a942213f1c37ecfd20ac79d2f7fc462696 (diff)
downloadrneovim-82bb8c887c5625a77969c70a38ce94fce803301e.tar.gz
rneovim-82bb8c887c5625a77969c70a38ce94fce803301e.tar.bz2
rneovim-82bb8c887c5625a77969c70a38ce94fce803301e.zip
normal: Extract most `normal_cmd` logic into two functions
The new functions are `normal_prepare` and `normal_execute` which contain code executed before and after input is received in normal mode.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/normal.c78
1 files changed, 46 insertions, 32 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index fe1eb5b4a0..d2d734a677 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -69,6 +69,7 @@ typedef struct normal_state {
linenr_T conceal_old_cursor_line;
linenr_T conceal_new_cursor_line;
bool conceal_update_lines;
+ bool set_prevcount;
bool previous_got_int; // `got_int` was true
bool cmdwin; // command-line window normal mode
bool noexmode; // true if the normal mode was pushed from
@@ -76,6 +77,7 @@ typedef struct normal_state {
bool toplevel; // top-level normal mode
oparg_T oa; // operator arguments
cmdarg_T ca; // command arguments
+ int mapped_len;
} NormalState;
/*
@@ -465,26 +467,11 @@ void normal_enter(bool cmdwin, bool noexmode)
}
}
-/*
- * Execute a command in Normal mode.
- */
-void
-normal_cmd (
- oparg_T *oap,
- bool toplevel /* true when called from main() */
-)
+static void normal_prepare(NormalState *s)
{
cmdarg_T ca; /* command arguments */
int c;
- bool ctrl_w = false; /* got CTRL-W command */
- int old_col = curwin->w_curswant;
- bool need_flushbuf; /* need to call ui_flush() */
- pos_T old_pos; /* cursor position before command */
- int mapped_len;
- static int old_mapped_len = 0;
- int idx;
- bool set_prevcount = false;
-
+ oparg_T *oap = &s->oa;
memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */
ca.oap = oap;
@@ -509,7 +496,7 @@ normal_cmd (
* count. */
if (!finish_op && !oap->regname) {
ca.opcount = 0;
- set_prevcount = true;
+ s->set_prevcount = true;
}
/* Restore counts from before receiving K_CURSORHOLD. This means after
@@ -522,27 +509,31 @@ normal_cmd (
oap->prev_count0 = 0;
}
- mapped_len = typebuf_maplen();
+ s->mapped_len = typebuf_maplen();
State = NORMAL_BUSY;
/* Set v:count here, when called from main() and not a stuffed
* command, so that v:count can be used in an expression mapping
* when there is no count. Do set it for redo. */
- if (toplevel && readbuf1_empty())
- set_vcount_ca(&ca, &set_prevcount);
-
- /*
- * Get the command character from the user.
- */
- input_enable_events();
- c = safe_vgetc();
- input_disable_events();
+ if (s->toplevel && readbuf1_empty())
+ set_vcount_ca(&ca, &s->set_prevcount);
+ s->ca = ca;
+}
- if (c == K_EVENT) {
- queue_process_events(loop.events);
- return;
- }
+static int normal_execute(NormalState *s, int c)
+{
+ cmdarg_T ca = s->ca;
+ bool ctrl_w = false; /* got CTRL-W command */
+ int old_col = curwin->w_curswant;
+ bool need_flushbuf; /* need to call ui_flush() */
+ pos_T old_pos; /* cursor position before command */
+ int mapped_len = s->mapped_len;
+ static int old_mapped_len = 0;
+ int idx;
+ bool set_prevcount = s->set_prevcount;
+ bool toplevel = s->toplevel;
+ oparg_T *oap = &s->oa;
LANGMAP_ADJUST(c, true);
@@ -1109,6 +1100,7 @@ normal_end:
/* Save count before an operator for next time. */
opcount = ca.opcount;
+ return 1;
}
// Function executed before each iteration of normal mode.
@@ -7627,3 +7619,25 @@ static int mouse_model_popup(void)
return p_mousem[0] == 'p';
}
+void normal_cmd(oparg_T *oap, bool toplevel)
+{
+ NormalState s;
+ normal_state_init(&s);
+ s.toplevel = toplevel;
+ s.oa = *oap;
+ normal_prepare(&s);
+
+ input_enable_events();
+ int c = safe_vgetc();
+ input_disable_events();
+
+ if (c == K_EVENT) {
+ queue_process_events(loop.events);
+ goto end;
+ }
+
+ (void)normal_execute(&s, c);
+
+end:
+ *oap = s.oa;
+}