refactor: Remove allow_keys global (#6346)

* The allow_keys global is unused in nvim, remove it

* clint
This commit is contained in:
Matthew Malcomson
2017-03-25 14:43:19 +00:00
committed by Justin M. Keyes
parent 0cd829161a
commit 098e91400e
11 changed files with 74 additions and 117 deletions

View File

@@ -1448,10 +1448,8 @@ int get_digraph(int cmdline)
{ {
int cc; int cc;
no_mapping++; no_mapping++;
allow_keys++;
int c = plain_vgetc(); int c = plain_vgetc();
no_mapping--; no_mapping--;
allow_keys--;
if (c != ESC) { if (c != ESC) {
// ESC cancels CTRL-K // ESC cancels CTRL-K
@@ -1468,10 +1466,8 @@ int get_digraph(int cmdline)
add_to_showcmd(c); add_to_showcmd(c);
} }
no_mapping++; no_mapping++;
allow_keys++;
cc = plain_vgetc(); cc = plain_vgetc();
no_mapping--; no_mapping--;
allow_keys--;
if (cc != ESC) { if (cc != ESC) {
// ESC cancels CTRL-K // ESC cancels CTRL-K

View File

@@ -689,11 +689,9 @@ static int insert_execute(VimState *state, int key)
if (s->c == Ctrl_BSL) { if (s->c == Ctrl_BSL) {
// may need to redraw when no more chars available now // may need to redraw when no more chars available now
ins_redraw(false); ins_redraw(false);
++no_mapping; no_mapping++;
++allow_keys;
s->c = plain_vgetc(); s->c = plain_vgetc();
--no_mapping; no_mapping--;
--allow_keys;
if (s->c != Ctrl_N && s->c != Ctrl_G && s->c != Ctrl_O) { if (s->c != Ctrl_N && s->c != Ctrl_G && s->c != Ctrl_O) {
// it's something else // it's something else
vungetc(s->c); vungetc(s->c);
@@ -8303,17 +8301,16 @@ static int ins_digraph(void)
} }
/* don't map the digraph chars. This also prevents the // don't map the digraph chars. This also prevents the
* mode message to be deleted when ESC is hit */ // mode message to be deleted when ESC is hit
++no_mapping; no_mapping++;
++allow_keys;
c = plain_vgetc(); c = plain_vgetc();
--no_mapping; no_mapping--;
--allow_keys; if (did_putchar) {
if (did_putchar) // when the line fits in 'columns' the '?' is at the start of the next
/* when the line fits in 'columns' the '?' is at the start of the next // line and will not be removed by the redraw
* line and will not be removed by the redraw */
edit_unputchar(); edit_unputchar();
}
if (IS_SPECIAL(c) || mod_mask) { /* special key */ if (IS_SPECIAL(c) || mod_mask) { /* special key */
clear_showcmd(); clear_showcmd();
@@ -8333,15 +8330,14 @@ static int ins_digraph(void)
} }
add_to_showcmd_c(c); add_to_showcmd_c(c);
} }
++no_mapping; no_mapping++;
++allow_keys;
cc = plain_vgetc(); cc = plain_vgetc();
--no_mapping; no_mapping--;
--allow_keys; if (did_putchar) {
if (did_putchar) // when the line fits in 'columns' the '?' is at the start of the
/* when the line fits in 'columns' the '?' is at the start of the // next line and will not be removed by a redraw
* next line and will not be removed by a redraw */
edit_unputchar(); edit_unputchar();
}
if (cc != ESC) { if (cc != ESC) {
AppendToRedobuff((char_u *)CTRL_V_STR); AppendToRedobuff((char_u *)CTRL_V_STR);
c = getdigraph(c, cc, TRUE); c = getdigraph(c, cc, TRUE);

View File

@@ -10596,8 +10596,7 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
varnumber_T n; varnumber_T n;
int error = FALSE; int error = FALSE;
++no_mapping; no_mapping++;
++allow_keys;
for (;; ) { for (;; ) {
// Position the cursor. Needed after a message that ends in a space, // Position the cursor. Needed after a message that ends in a space,
// or if event processing caused a redraw. // or if event processing caused a redraw.
@@ -10630,8 +10629,7 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
continue; continue;
break; break;
} }
--no_mapping; no_mapping--;
--allow_keys;
vimvars[VV_MOUSE_WIN].vv_nr = 0; vimvars[VV_MOUSE_WIN].vv_nr = 0;
vimvars[VV_MOUSE_WINID].vv_nr = 0; vimvars[VV_MOUSE_WINID].vv_nr = 0;

View File

@@ -3577,11 +3577,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout)
ui_cursor_goto(msg_row, msg_col); ui_cursor_goto(msg_row, msg_col);
RedrawingDisabled = temp; RedrawingDisabled = temp;
++no_mapping; /* don't map this key */ no_mapping++; // don't map this key
++allow_keys; /* allow special keys */
typed = plain_vgetc(); typed = plain_vgetc();
--allow_keys; no_mapping--;
--no_mapping;
/* clear the question */ /* clear the question */
msg_didout = FALSE; /* don't scroll up */ msg_didout = FALSE; /* don't scroll up */

View File

@@ -621,11 +621,9 @@ static int command_line_execute(VimState *state, int key)
// CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert // CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert
// mode when 'insertmode' is set, CTRL-\ e prompts for an expression. // mode when 'insertmode' is set, CTRL-\ e prompts for an expression.
if (s->c == Ctrl_BSL) { if (s->c == Ctrl_BSL) {
++no_mapping; no_mapping++;
++allow_keys;
s->c = plain_vgetc(); s->c = plain_vgetc();
--no_mapping; no_mapping--;
--allow_keys;
// CTRL-\ e doesn't work when obtaining an expression, unless it // CTRL-\ e doesn't work when obtaining an expression, unless it
// is in a mapping. // is in a mapping.
if (s->c != Ctrl_N && s->c != Ctrl_G && (s->c != 'e' if (s->c != Ctrl_N && s->c != Ctrl_G && (s->c != 'e'
@@ -1887,8 +1885,7 @@ getexmodeline (
msg_putchar(' '); msg_putchar(' ');
} }
} }
++no_mapping; no_mapping++;
++allow_keys;
/* /*
* Get the line, one character at a time. * Get the line, one character at a time.
@@ -2078,8 +2075,7 @@ redraw:
} }
} }
--no_mapping; no_mapping--;
--allow_keys;
/* make following messages go to the next line */ /* make following messages go to the next line */
msg_didout = FALSE; msg_didout = FALSE;

View File

@@ -1389,27 +1389,20 @@ int vgetc(void)
for (;; ) { // this is done twice if there are modifiers for (;; ) { // this is done twice if there are modifiers
bool did_inc = false; bool did_inc = false;
if (mod_mask) { // no mapping after modifier has been read if (mod_mask) { // no mapping after modifier has been read
++no_mapping; no_mapping++;
++allow_keys;
did_inc = true; // mod_mask may change value did_inc = true; // mod_mask may change value
} }
c = vgetorpeek(true); c = vgetorpeek(true);
if (did_inc) { if (did_inc) {
--no_mapping; no_mapping--;
--allow_keys;
} }
/* Get two extra bytes for special keys */ // Get two extra bytes for special keys
if (c == K_SPECIAL if (c == K_SPECIAL) {
) { no_mapping++;
int save_allow_keys = allow_keys; c2 = vgetorpeek(true); // no mapping for these chars
c = vgetorpeek(true);
++no_mapping; no_mapping--;
allow_keys = 0; /* make sure BS is not found */
c2 = vgetorpeek(TRUE); /* no mapping for these chars */
c = vgetorpeek(TRUE);
--no_mapping;
allow_keys = save_allow_keys;
if (c2 == KS_MODIFIER) { if (c2 == KS_MODIFIER) {
mod_mask = c; mod_mask = c;
continue; continue;
@@ -1487,7 +1480,7 @@ int vgetc(void)
buf[i] = CSI; buf[i] = CSI;
} }
} }
--no_mapping; no_mapping--;
c = (*mb_ptr2char)(buf); c = (*mb_ptr2char)(buf);
} }
@@ -1570,7 +1563,7 @@ int char_avail(void)
no_mapping++; no_mapping++;
retval = vpeekc(); retval = vpeekc();
--no_mapping; no_mapping--;
return retval != NUL; return retval != NUL;
} }

View File

@@ -832,13 +832,11 @@ EXTERN int ex_no_reprint INIT(= FALSE); /* no need to print after z or p */
EXTERN int Recording INIT(= FALSE); /* TRUE when recording into a reg. */ EXTERN int Recording INIT(= FALSE); /* TRUE when recording into a reg. */
EXTERN int Exec_reg INIT(= FALSE); /* TRUE when executing a register */ EXTERN int Exec_reg INIT(= FALSE); /* TRUE when executing a register */
EXTERN int no_mapping INIT(= FALSE); /* currently no mapping allowed */ EXTERN int no_mapping INIT(= false); // currently no mapping allowed
EXTERN int no_zero_mapping INIT(= 0); /* mapping zero not allowed */ EXTERN int no_zero_mapping INIT(= 0); // mapping zero not allowed
EXTERN int allow_keys INIT(= FALSE); /* allow key codes when no_mapping EXTERN int no_u_sync INIT(= 0); // Don't call u_sync()
* is set */ EXTERN int u_sync_once INIT(= 0); // Call u_sync() once when evaluating
EXTERN int no_u_sync INIT(= 0); /* Don't call u_sync() */ // an expression.
EXTERN int u_sync_once INIT(= 0); /* Call u_sync() once when evaluating
an expression. */
EXTERN bool force_restart_edit INIT(= false); // force restart_edit after EXTERN bool force_restart_edit INIT(= false); // force restart_edit after
// ex_normal returns // ex_normal returns

View File

@@ -847,23 +847,22 @@ void wait_return(int redraw)
* CTRL-C, but we need to loop then. */ * CTRL-C, but we need to loop then. */
had_got_int = got_int; had_got_int = got_int;
/* Don't do mappings here, we put the character back in the // Don't do mappings here, we put the character back in the
* typeahead buffer. */ // typeahead buffer.
++no_mapping; no_mapping++;
++allow_keys;
/* Temporarily disable Recording. If Recording is active, the // Temporarily disable Recording. If Recording is active, the
* character will be recorded later, since it will be added to the // character will be recorded later, since it will be added to the
* typebuf after the loop */ // typebuf after the loop
save_Recording = Recording; save_Recording = Recording;
save_scriptout = scriptout; save_scriptout = scriptout;
Recording = FALSE; Recording = FALSE;
scriptout = NULL; scriptout = NULL;
c = safe_vgetc(); c = safe_vgetc();
if (had_got_int && !global_busy) if (had_got_int && !global_busy) {
got_int = FALSE; got_int = false;
--no_mapping; }
--allow_keys; no_mapping--;
Recording = save_Recording; Recording = save_Recording;
scriptout = save_scriptout; scriptout = save_scriptout;

View File

@@ -2225,11 +2225,10 @@ int ask_yesno(const char *str, bool direct)
int r = ' '; int r = ' ';
int save_State = State; int save_State = State;
++no_wait_return; no_wait_return++;
State = CONFIRM; /* mouse behaves like with :confirm */ State = CONFIRM; // mouse behaves like with :confirm
setmouse(); /* disables mouse for xterm */ setmouse(); // disables mouse for xterm
++no_mapping; no_mapping++;
++allow_keys; /* no mapping here, but recognize keys */
while (r != 'y' && r != 'n') { while (r != 'y' && r != 'n') {
/* same highlighting as for wait_return */ /* same highlighting as for wait_return */
@@ -2247,8 +2246,7 @@ int ask_yesno(const char *str, bool direct)
--no_wait_return; --no_wait_return;
State = save_State; State = save_State;
setmouse(); setmouse();
--no_mapping; no_mapping--;
--allow_keys;
return r; return r;
} }
@@ -2398,8 +2396,7 @@ get_number (
if (msg_silent != 0) if (msg_silent != 0)
return 0; return 0;
++no_mapping; no_mapping++;
++allow_keys; /* no mapping here, but recognize keys */
for (;; ) { for (;; ) {
ui_cursor_goto(msg_row, msg_col); ui_cursor_goto(msg_row, msg_col);
c = safe_vgetc(); c = safe_vgetc();
@@ -2427,8 +2424,7 @@ get_number (
} else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) } else if (c == CAR || c == NL || c == Ctrl_C || c == ESC)
break; break;
} }
--no_mapping; no_mapping--;
--allow_keys;
return n; return n;
} }

View File

@@ -642,8 +642,7 @@ static void normal_get_additional_char(NormalState *s)
bool langmap_active = false; // using :lmap mappings bool langmap_active = false; // using :lmap mappings
int lang; // getting a text character int lang; // getting a text character
++no_mapping; no_mapping++;
++allow_keys; // no mapping for nchar, but allow key codes
// Don't generate a CursorHold event here, most commands can't handle // Don't generate a CursorHold event here, most commands can't handle
// it, e.g., nv_replace(), nv_csearch(). // it, e.g., nv_replace(), nv_csearch().
did_cursorhold = true; did_cursorhold = true;
@@ -681,8 +680,7 @@ static void normal_get_additional_char(NormalState *s)
} }
if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) {
// Allow mappings defined with ":lmap". // Allow mappings defined with ":lmap".
--no_mapping; no_mapping--;
--allow_keys;
if (repl) { if (repl) {
State = LREPLACE; State = LREPLACE;
} else { } else {
@@ -695,8 +693,7 @@ static void normal_get_additional_char(NormalState *s)
if (langmap_active) { if (langmap_active) {
// Undo the decrement done above // Undo the decrement done above
++no_mapping; no_mapping++;
++allow_keys;
State = NORMAL_BUSY; State = NORMAL_BUSY;
} }
State = NORMAL_BUSY; State = NORMAL_BUSY;
@@ -781,8 +778,7 @@ static void normal_get_additional_char(NormalState *s)
} }
no_mapping++; no_mapping++;
} }
--no_mapping; no_mapping--;
--allow_keys;
} }
static void normal_invert_horizontal(NormalState *s) static void normal_invert_horizontal(NormalState *s)
@@ -832,8 +828,7 @@ static bool normal_get_command_count(NormalState *s)
} }
if (s->ctrl_w) { if (s->ctrl_w) {
++no_mapping; no_mapping++;
++allow_keys; // no mapping for nchar, but keys
} }
++no_zero_mapping; // don't map zero here ++no_zero_mapping; // don't map zero here
@@ -841,8 +836,7 @@ static bool normal_get_command_count(NormalState *s)
LANGMAP_ADJUST(s->c, true); LANGMAP_ADJUST(s->c, true);
--no_zero_mapping; --no_zero_mapping;
if (s->ctrl_w) { if (s->ctrl_w) {
--no_mapping; no_mapping--;
--allow_keys;
} }
s->need_flushbuf |= add_to_showcmd(s->c); s->need_flushbuf |= add_to_showcmd(s->c);
} }
@@ -852,12 +846,10 @@ static bool normal_get_command_count(NormalState *s)
s->ctrl_w = true; s->ctrl_w = true;
s->ca.opcount = s->ca.count0; // remember first count s->ca.opcount = s->ca.count0; // remember first count
s->ca.count0 = 0; s->ca.count0 = 0;
++no_mapping; no_mapping++;
++allow_keys; // no mapping for nchar, but keys
s->c = plain_vgetc(); // get next character s->c = plain_vgetc(); // get next character
LANGMAP_ADJUST(s->c, true); LANGMAP_ADJUST(s->c, true);
--no_mapping; no_mapping--;
--allow_keys;
s->need_flushbuf |= add_to_showcmd(s->c); s->need_flushbuf |= add_to_showcmd(s->c);
return true; return true;
} }
@@ -4043,12 +4035,10 @@ static void nv_zet(cmdarg_T *cap)
return; return;
n = nchar - '0'; n = nchar - '0';
for (;; ) { for (;; ) {
++no_mapping; no_mapping++;
++allow_keys; /* no mapping for nchar, but allow key codes */
nchar = plain_vgetc(); nchar = plain_vgetc();
LANGMAP_ADJUST(nchar, true); LANGMAP_ADJUST(nchar, true);
--no_mapping; no_mapping--;
--allow_keys;
(void)add_to_showcmd(nchar); (void)add_to_showcmd(nchar);
if (nchar == K_DEL || nchar == K_KDEL) if (nchar == K_DEL || nchar == K_KDEL)
n /= 10; n /= 10;
@@ -4376,13 +4366,11 @@ dozet:
break; break;
case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ case 'u': // "zug" and "zuw": undo "zg" and "zw"
++no_mapping; no_mapping++;
++allow_keys; /* no mapping for nchar, but allow key codes */
nchar = plain_vgetc(); nchar = plain_vgetc();
LANGMAP_ADJUST(nchar, true); LANGMAP_ADJUST(nchar, true);
--no_mapping; no_mapping--;
--allow_keys;
(void)add_to_showcmd(nchar); (void)add_to_showcmd(nchar);
if (vim_strchr((char_u *)"gGwW", nchar) == NULL) { if (vim_strchr((char_u *)"gGwW", nchar) == NULL) {
clearopbeep(cap->oap); clearopbeep(cap->oap);

View File

@@ -447,13 +447,12 @@ wingotofile:
case 'g': case 'g':
case Ctrl_G: case Ctrl_G:
CHECK_CMDWIN CHECK_CMDWIN
++ no_mapping; no_mapping++;
++allow_keys; /* no mapping for xchar, but allow key codes */ if (xchar == NUL) {
if (xchar == NUL)
xchar = plain_vgetc(); xchar = plain_vgetc();
LANGMAP_ADJUST(xchar, TRUE); }
--no_mapping; LANGMAP_ADJUST(xchar, true);
--allow_keys; no_mapping--;
(void)add_to_showcmd(xchar); (void)add_to_showcmd(xchar);
switch (xchar) { switch (xchar) {
case '}': case '}':