vim-patch:8.1.1798: warning for unused variable in tiny version

Problem:    Warning for unused variable in tiny version. (Tony Mechelynck)
Solution:   Move inside #ifdef.  Reformat code.
eda35f7127
This commit is contained in:
zeertzjq 2021-12-07 06:47:33 +08:00
parent 95a5912158
commit 296eb7203c

View File

@ -1689,7 +1689,7 @@ typedef enum {
/// Handle mappings in the typeahead buffer. /// Handle mappings in the typeahead buffer.
/// - When something was mapped, return map_result_retry for recursive mappings. /// - When something was mapped, return map_result_retry for recursive mappings.
/// - When nothing mapped and typeahead has a character return map_result_get. /// - When nothing mapped and typeahead has a character: return map_result_get.
/// - When there is no match yet, return map_result_nomatch, need to get more /// - When there is no match yet, return map_result_nomatch, need to get more
/// typeahead. /// typeahead.
static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
@ -1707,16 +1707,14 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
int local_State = get_real_state(); int local_State = get_real_state();
// Check for a mappable key sequence. // Check for a mappable key sequence.
// Walk through one maphash[] list until we find an // Walk through one maphash[] list until we find an entry that matches.
// entry that matches.
// //
// Don't look for mappings if: // Don't look for mappings if:
// - no_mapping set: mapping disabled (e.g. for CTRL-V) // - no_mapping set: mapping disabled (e.g. for CTRL-V)
// - maphash_valid not set: no mappings present. // - maphash_valid not set: no mappings present.
// - typebuf.tb_buf[typebuf.tb_off] should not be remapped // - typebuf.tb_buf[typebuf.tb_off] should not be remapped
// - in insert or cmdline mode and 'paste' option set // - in insert or cmdline mode and 'paste' option set
// - waiting for "hit return to continue" and CR or SPACE // - waiting for "hit return to continue" and CR or SPACE typed
// typed
// - waiting for a char with --more-- // - waiting for a char with --more--
// - in Ctrl-X mode, and we get a valid char for that mode // - in Ctrl-X mode, and we get a valid char for that mode
tb_c1 = typebuf.tb_buf[typebuf.tb_off]; tb_c1 = typebuf.tb_buf[typebuf.tb_off];
@ -1724,21 +1722,18 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
&& (no_zero_mapping == 0 || tb_c1 != '0') && (no_zero_mapping == 0 || tb_c1 != '0')
&& (typebuf.tb_maplen == 0 && (typebuf.tb_maplen == 0
|| (p_remap || (p_remap
&& (typebuf.tb_noremap[typebuf.tb_off] && !(typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR))))
& (RM_NONE|RM_ABBR)) == 0))
&& !(p_paste && (State & (INSERT + CMDLINE))) && !(p_paste && (State & (INSERT + CMDLINE)))
&& !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' '))
&& State != ASKMORE && State != ASKMORE
&& State != CONFIRM && State != CONFIRM
&& !((ctrl_x_mode_not_default() && vim_is_ctrl_x_key(tb_c1)) && !((ctrl_x_mode_not_default() && vim_is_ctrl_x_key(tb_c1))
|| ((compl_cont_status & CONT_LOCAL) || ((compl_cont_status & CONT_LOCAL)
&& (tb_c1 == Ctrl_N && (tb_c1 == Ctrl_N || tb_c1 == Ctrl_P)))) {
|| tb_c1 == Ctrl_P)))) {
if (tb_c1 == K_SPECIAL) { if (tb_c1 == K_SPECIAL) {
nolmaplen = 2; nolmaplen = 2;
} else { } else {
LANGMAP_ADJUST(tb_c1, (State & (CMDLINE | INSERT)) == 0 LANGMAP_ADJUST(tb_c1, !(State & (CMDLINE | INSERT)) && get_real_state() != SELECTMODE);
&& get_real_state() != SELECTMODE);
nolmaplen = 0; nolmaplen = 0;
} }
// First try buffer-local mappings. // First try buffer-local mappings.
@ -1749,23 +1744,19 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
mp = mp2; mp = mp2;
mp2 = NULL; mp2 = NULL;
} }
// Loop until a partly matching mapping is found or // Loop until a partly matching mapping is found or all (local)
// all (local) mappings have been checked. // mappings have been checked.
// The longest full match is remembered in "mp_match". // The longest full match is remembered in "mp_match".
// A full match is only accepted if there is no partly // A full match is only accepted if there is no partly match, so "aa"
// match, so "aa" and "aaa" can both be mapped. // and "aaa" can both be mapped.
mp_match = NULL; mp_match = NULL;
mp_match_len = 0; mp_match_len = 0;
for (; mp != NULL; for (; mp != NULL; mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : (mp = mp->m_next)) {
mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : // Only consider an entry if the first character matches and it is
(mp = mp->m_next)) { // for the current state.
// Only consider an entry if the first character
// matches and it is for the current state.
// Skip ":lmap" mappings if keys were mapped. // Skip ":lmap" mappings if keys were mapped.
if (mp->m_keys[0] == tb_c1 if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
&& (mp->m_mode & local_State) && ((mp->m_mode & LANGMAP) == 0 || typebuf.tb_maplen == 0)) {
&& ((mp->m_mode & LANGMAP) == 0
|| typebuf.tb_maplen == 0)) {
int nomap = nolmaplen; int nomap = nolmaplen;
int c2; int c2;
// find the match length of this mapping // find the match length of this mapping
@ -1783,10 +1774,9 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} }
} }
// Don't allow mapping the first byte(s) of a // Don't allow mapping the first byte(s) of a multi-byte char.
// multi-byte char. Happens when mapping // Happens when mapping <M-a> and then changing 'encoding'.
// <M-a> and then changing 'encoding'. Beware // Beware that 0x80 is escaped.
// that 0x80 is escaped.
char_u *p1 = mp->m_keys; char_u *p1 = mp->m_keys;
char_u *p2 = (char_u *)mb_unescape((const char **)&p1); char_u *p2 = (char_u *)mb_unescape((const char **)&p1);
@ -1798,26 +1788,21 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// - Full match: mlen == keylen // - Full match: mlen == keylen
// - Partly match: mlen == typebuf.tb_len // - Partly match: mlen == typebuf.tb_len
keylen = mp->m_keylen; keylen = mp->m_keylen;
if (mlen == keylen if (mlen == keylen || (mlen == typebuf.tb_len && typebuf.tb_len < keylen)) {
|| (mlen == typebuf.tb_len
&& typebuf.tb_len < keylen)) {
char_u *s; char_u *s;
int n; int n;
// If only script-local mappings are // If only script-local mappings are allowed, check if the
// allowed, check if the mapping starts // mapping starts with K_SNR.
// with K_SNR.
s = typebuf.tb_noremap + typebuf.tb_off; s = typebuf.tb_noremap + typebuf.tb_off;
if (*s == RM_SCRIPT if (*s == RM_SCRIPT
&& (mp->m_keys[0] != K_SPECIAL && (mp->m_keys[0] != K_SPECIAL
|| mp->m_keys[1] != KS_EXTRA || mp->m_keys[1] != KS_EXTRA
|| mp->m_keys[2] || mp->m_keys[2] != KE_SNR)) {
!= KE_SNR)) {
continue; continue;
} }
// If one of the typed keys cannot be // If one of the typed keys cannot be remapped, skip the entry.
// remapped, skip the entry.
for (n = mlen; --n >= 0;) { for (n = mlen; --n >= 0;) {
if (*s++ & (RM_NONE|RM_ABBR)) { if (*s++ & (RM_NONE|RM_ABBR)) {
break; break;
@ -1828,8 +1813,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} }
if (keylen > typebuf.tb_len) { if (keylen > typebuf.tb_len) {
if (!*timedout && !(mp_match != NULL if (!*timedout && !(mp_match != NULL && mp_match->m_nowait)) {
&& mp_match->m_nowait)) {
// break at a partly match // break at a partly match
keylen = KEYLEN_PART_MAP; keylen = KEYLEN_PART_MAP;
break; break;
@ -1892,8 +1876,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} }
} }
if ((mp == NULL || max_mlen >= mp_match_len) if ((mp == NULL || max_mlen >= mp_match_len) && keylen != KEYLEN_PART_MAP) {
&& keylen != KEYLEN_PART_MAP) {
// No matching mapping found or found a non-matching mapping that // No matching mapping found or found a non-matching mapping that
// matches at least what the matching mapping matched // matches at least what the matching mapping matched
keylen = 0; keylen = 0;
@ -1940,30 +1923,25 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
return map_result_fail; return map_result_fail;
} }
// In Select mode and a Visual mode mapping is used: // In Select mode and a Visual mode mapping is used: Switch to Visual
// Switch to Visual mode temporarily. Append K_SELECT // mode temporarily. Append K_SELECT to switch back to Select mode.
// to switch back to Select mode. if (VIsual_active && VIsual_select && (mp->m_mode & VISUAL)) {
if (VIsual_active && VIsual_select
&& (mp->m_mode & VISUAL)) {
VIsual_select = false; VIsual_select = false;
(void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false); (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false);
} }
// Copy the values from *mp that are used, because // Copy the values from *mp that are used, because evaluating the
// evaluating the expression may invoke a function // expression may invoke a function that redefines the mapping, thereby
// that redefines the mapping, thereby making *mp // making *mp invalid.
// invalid.
save_m_expr = mp->m_expr; save_m_expr = mp->m_expr;
save_m_noremap = mp->m_noremap; save_m_noremap = mp->m_noremap;
save_m_silent = mp->m_silent; save_m_silent = mp->m_silent;
char_u *save_m_keys = NULL; // only saved when needed char_u *save_m_keys = NULL; // only saved when needed
char_u *save_m_str = NULL; // only saved when needed char_u *save_m_str = NULL; // only saved when needed
/* // Handle ":map <expr>": evaluate the {rhs} as an
* Handle ":map <expr>": evaluate the {rhs} as an // expression. Also save and restore the command line
* expression. Also save and restore the command line // for "normal :".
* for "normal :".
*/
if (mp->m_expr) { if (mp->m_expr) {
int save_vgetc_busy = vgetc_busy; int save_vgetc_busy = vgetc_busy;
const bool save_may_garbage_collect = may_garbage_collect; const bool save_may_garbage_collect = may_garbage_collect;
@ -1981,9 +1959,8 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} }
// Insert the 'to' part in the typebuf.tb_buf. // Insert the 'to' part in the typebuf.tb_buf.
// If 'from' field is the same as the start of the // If 'from' field is the same as the start of the 'to' field, don't
// 'to' field, don't remap the first character (but do // remap the first character (but do allow abbreviations).
// allow abbreviations).
// If m_noremap is set, don't remap the whole 'to' part. // If m_noremap is set, don't remap the whole 'to' part.
if (map_str == NULL) { if (map_str == NULL) {
i = FAIL; i = FAIL;
@ -2060,7 +2037,6 @@ static int vgetorpeek(bool advance)
bool timedout = false; // waited for more than 1 second for mapping to complete bool timedout = false; // waited for more than 1 second for mapping to complete
int mapdepth = 0; // check for recursive mapping int mapdepth = 0; // check for recursive mapping
bool mode_deleted = false; // set when mode has been deleted bool mode_deleted = false; // set when mode has been deleted
int i;
int new_wcol, new_wrow; int new_wcol, new_wrow;
int n; int n;
int old_wcol, old_wrow; int old_wcol, old_wrow;
@ -2205,10 +2181,8 @@ static int vgetorpeek(bool advance)
&& ex_normal_busy == 0 && ex_normal_busy == 0
&& typebuf.tb_maplen == 0 && typebuf.tb_maplen == 0
&& (State & INSERT) && (State & INSERT)
&& (p_timeout && (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout))
|| (keylen == KEYLEN_PART_KEY && p_ttimeout)) && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) {
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
3, 25L)) == 0) {
colnr_T col = 0, vcol; colnr_T col = 0, vcol;
char_u *ptr; char_u *ptr;
@ -2326,24 +2300,21 @@ static int vgetorpeek(bool advance)
if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0
&& advance && must_redraw != 0 && !need_wait_return) { && advance && must_redraw != 0 && !need_wait_return) {
update_screen(0); update_screen(0);
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
} }
// If we have a partial match (and are going to wait for more // If we have a partial match (and are going to wait for more
// input from the user), show the partially matched characters // input from the user), show the partially matched characters
// to the user with showcmd. // to the user with showcmd.
i = 0; int showcmd_idx = 0;
c1 = 0; c1 = 0;
if (typebuf.tb_len > 0 && advance && !exmode_active) { if (typebuf.tb_len > 0 && advance && !exmode_active) {
if (((State & (NORMAL | INSERT)) || State == LANGMAP) if (((State & (NORMAL | INSERT)) || State == LANGMAP) && State != HITRETURN) {
&& State != HITRETURN) {
// this looks nice when typing a dead character map // this looks nice when typing a dead character map
if (State & INSERT if (State & INSERT
&& ptr2cells(typebuf.tb_buf + typebuf.tb_off && ptr2cells(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1) == 1) {
+ typebuf.tb_len - 1) == 1) { edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], false);
edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], setcursor(); // put cursor back where it belongs
false);
setcursor(); // put cursor back where it belongs
c1 = 1; c1 = 1;
} }
// need to use the col and row from above here // need to use the col and row from above here
@ -2353,10 +2324,10 @@ static int vgetorpeek(bool advance)
curwin->w_wrow = new_wrow; curwin->w_wrow = new_wrow;
push_showcmd(); push_showcmd();
if (typebuf.tb_len > SHOWCMD_COLS) { if (typebuf.tb_len > SHOWCMD_COLS) {
i = typebuf.tb_len - SHOWCMD_COLS; showcmd_idx = typebuf.tb_len - SHOWCMD_COLS;
} }
while (i < typebuf.tb_len) { while (showcmd_idx < typebuf.tb_len) {
(void)add_to_showcmd(typebuf.tb_buf[typebuf.tb_off + i++]); (void)add_to_showcmd(typebuf.tb_buf[typebuf.tb_off + showcmd_idx++]);
} }
curwin->w_wcol = old_wcol; curwin->w_wcol = old_wcol;
curwin->w_wrow = old_wrow; curwin->w_wrow = old_wrow;
@ -2382,8 +2353,7 @@ static int vgetorpeek(bool advance)
long wait_time = 0; long wait_time = 0;
if (advance) { if (advance) {
if (typebuf.tb_len == 0 if (typebuf.tb_len == 0 || !(p_timeout || (p_ttimeout && keylen == KEYLEN_PART_KEY))) {
|| !(p_timeout || (p_ttimeout && keylen == KEYLEN_PART_KEY))) {
// blocking wait // blocking wait
wait_time = -1L; wait_time = -1L;
} else if (keylen == KEYLEN_PART_KEY && p_ttm >= 0) { } else if (keylen == KEYLEN_PART_KEY && p_ttm >= 0) {
@ -2398,7 +2368,7 @@ static int vgetorpeek(bool advance)
typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1, typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1,
wait_time); wait_time);
if (i != 0) { if (showcmd_idx != 0) {
pop_showcmd(); pop_showcmd();
} }
if (c1 == 1) { if (c1 == 1) {
@ -2408,28 +2378,28 @@ static int vgetorpeek(bool advance)
if (State & CMDLINE) { if (State & CMDLINE) {
unputcmdline(); unputcmdline();
} else { } else {
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
} }
} }
if (c < 0) { if (c < 0) {
continue; // end of input script reached continue; // end of input script reached
} }
if (c == NUL) { // no character available if (c == NUL) { // no character available
if (!advance) { if (!advance) {
break; break;
} }
if (wait_tb_len > 0) { // timed out if (wait_tb_len > 0) { // timed out
timedout = true; timedout = true;
continue; continue;
} }
} else { // allow mapping for just typed characters } else { // allow mapping for just typed characters
while (typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] != NUL) { while (typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] != NUL) {
typebuf.tb_noremap[typebuf.tb_off + typebuf.tb_len++] = RM_YES; typebuf.tb_noremap[typebuf.tb_off + typebuf.tb_len++] = RM_YES;
} }
} }
} // for (;;) } // for (;;)
} // if (!character from stuffbuf) } // if (!character from stuffbuf)
// if advance is false don't loop on NULs // if advance is false don't loop on NULs
} while (c < 0 || (advance && c == NUL)); } while (c < 0 || (advance && c == NUL));
@ -2440,13 +2410,13 @@ static int vgetorpeek(bool advance)
if (advance && p_smd && msg_silent == 0 && (State & INSERT)) { if (advance && p_smd && msg_silent == 0 && (State & INSERT)) {
if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) { if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) {
if (typebuf.tb_len && !KeyTyped) { if (typebuf.tb_len && !KeyTyped) {
redraw_cmdline = true; // delete mode later redraw_cmdline = true; // delete mode later
} else { } else {
unshowmode(false); unshowmode(false);
} }
} else if (c != ESC && mode_deleted) { } else if (c != ESC && mode_deleted) {
if (typebuf.tb_len && !KeyTyped) { if (typebuf.tb_len && !KeyTyped) {
redraw_cmdline = true; // show mode later redraw_cmdline = true; // show mode later
} else { } else {
showmode(); showmode();
} }