lint: makemap

* if braces
* spaces
* post increments
* comment style
This commit is contained in:
Ihor Antonov 2019-07-28 21:10:49 -04:00
parent ed5f891e83
commit 1c74c7c446

View File

@ -3954,10 +3954,10 @@ void vim_unescape_csi(char_u *p)
* Write map commands for the current mappings to an .exrc file. * Write map commands for the current mappings to an .exrc file.
* Return FAIL on error, OK otherwise. * Return FAIL on error, OK otherwise.
*/ */
int int
makemap ( makemap(
FILE *fd, FILE *fd,
buf_T *buf /* buffer for local mappings or NULL */ buf_T *buf // buffer for local mappings or NULL
) )
{ {
mapblock_T *mp; mapblock_T *mp;
@ -3970,50 +3970,56 @@ makemap (
validate_maphash(); validate_maphash();
/* // Do the loop twice: Once for mappings, once for abbreviations.
* Do the loop twice: Once for mappings, once for abbreviations. // Then loop over all map hash lists.
* Then loop over all map hash lists. for (abbr = 0; abbr < 2; abbr++) {
*/ for (hash = 0; hash < 256; hash++) {
for (abbr = 0; abbr < 2; ++abbr)
for (hash = 0; hash < 256; ++hash) {
if (abbr) { if (abbr) {
if (hash > 0) /* there is only one abbr list */ if (hash > 0) { // there is only one abbr list
break; break;
if (buf != NULL) }
if (buf != NULL) {
mp = buf->b_first_abbr; mp = buf->b_first_abbr;
else } else {
mp = first_abbr; mp = first_abbr;
}
} else { } else {
if (buf != NULL) if (buf != NULL) {
mp = buf->b_maphash[hash]; mp = buf->b_maphash[hash];
else } else {
mp = maphash[hash]; mp = maphash[hash];
}
} }
for (; mp; mp = mp->m_next) { for (; mp; mp = mp->m_next) {
/* skip script-local mappings */ // skip script-local mappings
if (mp->m_noremap == REMAP_SCRIPT) if (mp->m_noremap == REMAP_SCRIPT) {
continue; continue;
}
/* skip mappings that contain a <SNR> (script-local thing), // skip mappings that contain a <SNR> (script-local thing),
* they probably don't work when loaded again */ // they probably don't work when loaded again
for (p = mp->m_str; *p != NUL; ++p) for (p = mp->m_str; *p != NUL; p++) {
if (p[0] == K_SPECIAL && p[1] == KS_EXTRA if (p[0] == K_SPECIAL && p[1] == KS_EXTRA
&& p[2] == (int)KE_SNR) && p[2] == (int)KE_SNR) {
break; break;
if (*p != NUL) }
}
if (*p != NUL) {
continue; continue;
}
/* It's possible to create a mapping and then ":unmap" certain // It's possible to create a mapping and then ":unmap" certain
* modes. We recreate this here by mapping the individual // modes. We recreate this here by mapping the individual
* modes, which requires up to three of them. */ // modes, which requires up to three of them.
c1 = NUL; c1 = NUL;
c2 = NUL; c2 = NUL;
c3 = NUL; c3 = NUL;
if (abbr) if (abbr) {
cmd = "abbr"; cmd = "abbr";
else } else {
cmd = "map"; cmd = "map";
}
switch (mp->m_mode) { switch (mp->m_mode) {
case NORMAL + VISUAL + SELECTMODE + OP_PENDING: case NORMAL + VISUAL + SELECTMODE + OP_PENDING:
break; break;
@ -4071,8 +4077,9 @@ makemap (
c2 = 'o'; c2 = 'o';
break; break;
case CMDLINE + INSERT: case CMDLINE + INSERT:
if (!abbr) if (!abbr) {
cmd = "map!"; cmd = "map!";
}
break; break;
case CMDLINE: case CMDLINE:
c1 = 'c'; c1 = 'c';
@ -4090,9 +4097,10 @@ makemap (
IEMSG(_("E228: makemap: Illegal mode")); IEMSG(_("E228: makemap: Illegal mode"));
return FAIL; return FAIL;
} }
do { /* do this twice if c2 is set, 3 times with c3 */ do {
/* When outputting <> form, need to make sure that 'cpo' // do this twice if c2 is set, 3 times with c3 */
* is set to the Vim default. */ // When outputting <> form, need to make sure that 'cpo'
// is set to the Vim default.
if (!did_cpo) { if (!did_cpo) {
if (*mp->m_str == NUL) { // Will use <Nop>. if (*mp->m_str == NUL) { // Will use <Nop>.
did_cpo = true; did_cpo = true;
@ -4107,60 +4115,69 @@ makemap (
if (fprintf(fd, "let s:cpo_save=&cpo") < 0 if (fprintf(fd, "let s:cpo_save=&cpo") < 0
|| put_eol(fd) < 0 || put_eol(fd) < 0
|| fprintf(fd, "set cpo&vim") < 0 || fprintf(fd, "set cpo&vim") < 0
|| put_eol(fd) < 0) || put_eol(fd) < 0) {
return FAIL; return FAIL;
}
} }
} }
if (c1 && putc(c1, fd) < 0) if (c1 && putc(c1, fd) < 0) {
return FAIL; return FAIL;
if (mp->m_noremap != REMAP_YES && fprintf(fd, "nore") < 0) }
if (mp->m_noremap != REMAP_YES && fprintf(fd, "nore") < 0) {
return FAIL; return FAIL;
if (fputs(cmd, fd) < 0) }
if (fputs(cmd, fd) < 0) {
return FAIL; return FAIL;
if (buf != NULL && fputs(" <buffer>", fd) < 0) }
if (buf != NULL && fputs(" <buffer>", fd) < 0) {
return FAIL; return FAIL;
if (mp->m_nowait && fputs(" <nowait>", fd) < 0) }
if (mp->m_nowait && fputs(" <nowait>", fd) < 0) {
return FAIL; return FAIL;
if (mp->m_silent && fputs(" <silent>", fd) < 0) }
if (mp->m_silent && fputs(" <silent>", fd) < 0) {
return FAIL; return FAIL;
if (mp->m_expr && fputs(" <expr>", fd) < 0) }
if (mp->m_expr && fputs(" <expr>", fd) < 0) {
return FAIL; return FAIL;
}
if ( putc(' ', fd) < 0 if (putc(' ', fd) < 0
|| put_escstr(fd, mp->m_keys, 0) == FAIL || put_escstr(fd, mp->m_keys, 0) == FAIL
|| putc(' ', fd) < 0 || putc(' ', fd) < 0
|| put_escstr(fd, mp->m_str, 1) == FAIL || put_escstr(fd, mp->m_str, 1) == FAIL
|| put_eol(fd) < 0) || put_eol(fd) < 0) {
return FAIL; return FAIL;
}
c1 = c2; c1 = c2;
c2 = c3; c2 = c3;
c3 = NUL; c3 = NUL;
} while (c1 != NUL); } while (c1 != NUL);
} }
} }
}
if (did_cpo) if (did_cpo) {
if (fprintf(fd, "let &cpo=s:cpo_save") < 0 if (fprintf(fd, "let &cpo=s:cpo_save") < 0
|| put_eol(fd) < 0 || put_eol(fd) < 0
|| fprintf(fd, "unlet s:cpo_save") < 0 || fprintf(fd, "unlet s:cpo_save") < 0
|| put_eol(fd) < 0) || put_eol(fd) < 0) {
return FAIL; return FAIL;
}
}
return OK; return OK;
} }
/* // write escape string to file
* write escape string to file // "what": 0 for :map lhs, 1 for :map rhs, 2 for :set
* "what": 0 for :map lhs, 1 for :map rhs, 2 for :set //
* // return FAIL for failure, OK otherwise
* return FAIL for failure, OK otherwise
*/
int put_escstr(FILE *fd, char_u *strstart, int what) int put_escstr(FILE *fd, char_u *strstart, int what)
{ {
char_u *str = strstart; char_u *str = strstart;
int c; int c;
int modifiers; int modifiers;
/* :map xx <Nop> */ // :map xx <Nop>
if (*str == NUL && what == 1) { if (*str == NUL && what == 1) {
if (fprintf(fd, "<Nop>") < 0) if (fprintf(fd, "<Nop>") < 0)
return FAIL; return FAIL;