diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-03-29 20:25:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 20:25:09 -0400 |
commit | 3c497e214f48ee1433d759f5a56c028df5186f24 (patch) | |
tree | 8256f108b6f411df484062617d733e8f1217b4af | |
parent | aa6adacd77e59b2cf2ca7bdeae9a24c062b2a9c0 (diff) | |
parent | af2f0ffdf4261bf1167f044ca771fa225f2ae977 (diff) | |
download | rneovim-3c497e214f48ee1433d759f5a56c028df5186f24.tar.gz rneovim-3c497e214f48ee1433d759f5a56c028df5186f24.tar.bz2 rneovim-3c497e214f48ee1433d759f5a56c028df5186f24.zip |
Merge pull request #14238 from janlazo/vim-8.1.0958
vim-patch:8.1.{874,958,989,2380},8.2.{1621,2674}
-rw-r--r-- | src/nvim/buffer.c | 8 | ||||
-rw-r--r-- | src/nvim/edit.c | 6 | ||||
-rw-r--r-- | src/nvim/eval.c | 63 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 502 | ||||
-rw-r--r-- | src/nvim/globals.h | 2 | ||||
-rw-r--r-- | src/nvim/indent.c | 8 | ||||
-rw-r--r-- | src/nvim/indent_c.c | 628 | ||||
-rw-r--r-- | src/nvim/ops.c | 39 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 4 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 8 | ||||
-rw-r--r-- | src/nvim/popupmnu.c | 14 | ||||
-rw-r--r-- | src/nvim/regexp.c | 3 | ||||
-rw-r--r-- | src/nvim/regexp_nfa.c | 4 | ||||
-rw-r--r-- | src/nvim/testdir/Makefile | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_alot_latin.vim | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_assert.vim | 31 | ||||
-rw-r--r-- | src/nvim/testdir/test_regexp_latin.vim | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_substitute.vim | 9 |
20 files changed, 739 insertions, 620 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index cc9f130bfc..c7ec3a456c 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1947,13 +1947,9 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_flp); clear_string_option(&buf->b_p_isk); clear_string_option(&buf->b_p_vsts); - if (buf->b_p_vsts_nopaste) { - xfree(buf->b_p_vsts_nopaste); - } + xfree(buf->b_p_vsts_nopaste); buf->b_p_vsts_nopaste = NULL; - if (buf->b_p_vsts_array) { - xfree(buf->b_p_vsts_array); - } + xfree(buf->b_p_vsts_array); buf->b_p_vsts_array = NULL; clear_string_option(&buf->b_p_vts); XFREE_CLEAR(buf->b_p_vts_array); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 20f31a478d..49bd170bcd 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7269,7 +7269,6 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) char_u *p; char_u *line; int icase; - int i; if (keytyped == NUL) { // Can happen with CTRL-Y and CTRL-E on a short line. @@ -7354,8 +7353,9 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) && p[curwin->w_cursor.col - 1] == ':' && p[curwin->w_cursor.col - 2] == ':') { p[curwin->w_cursor.col - 1] = ' '; - i = (cin_iscase(p, FALSE) || cin_isscopedecl(p) - || cin_islabel()); + const bool i = cin_iscase(p, false) + || cin_isscopedecl(p) + || cin_islabel(); p = get_cursor_line_ptr(); p[curwin->w_cursor.col - 1] = ':'; if (i) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e1fcbdce25..b4f0c86f24 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5867,26 +5867,53 @@ int assert_inrange(typval_T *argvars) FUNC_ATTR_NONNULL_ALL { bool error = false; - const varnumber_T lower = tv_get_number_chk(&argvars[0], &error); - const varnumber_T upper = tv_get_number_chk(&argvars[1], &error); - const varnumber_T actual = tv_get_number_chk(&argvars[2], &error); - if (error) { - return 0; - } - if (actual < lower || actual > upper) { - garray_T ga; - prepare_assert_error(&ga); + if (argvars[0].v_type == VAR_FLOAT + || argvars[1].v_type == VAR_FLOAT + || argvars[2].v_type == VAR_FLOAT) { + const float_T flower = tv_get_float(&argvars[0]); + const float_T fupper = tv_get_float(&argvars[1]); + const float_T factual = tv_get_float(&argvars[2]); - char msg[55]; - vim_snprintf(msg, sizeof(msg), - "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", - lower, upper); - fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], - ASSERT_INRANGE); - assert_error(&ga); - ga_clear(&ga); - return 1; + if (factual < flower || factual > fupper) { + garray_T ga; + prepare_assert_error(&ga); + if (argvars[3].v_type != VAR_UNKNOWN) { + char_u *const tofree = (char_u *)encode_tv2string(&argvars[3], NULL); + ga_concat(&ga, tofree); + xfree(tofree); + } else { + char msg[80]; + vim_snprintf(msg, sizeof(msg), "Expected range %g - %g, but got %g", + flower, fupper, factual); + ga_concat(&ga, (char_u *)msg); + } + assert_error(&ga); + ga_clear(&ga); + return 1; + } + } else { + const varnumber_T lower = tv_get_number_chk(&argvars[0], &error); + const varnumber_T upper = tv_get_number_chk(&argvars[1], &error); + const varnumber_T actual = tv_get_number_chk(&argvars[2], &error); + + if (error) { + return 0; + } + if (actual < lower || actual > upper) { + garray_T ga; + prepare_assert_error(&ga); + + char msg[55]; + vim_snprintf(msg, sizeof(msg), + "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", + lower, upper); + fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], + ASSERT_INRANGE); + assert_error(&ga); + ga_clear(&ga); + return 1; + } } return 0; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 0f2e904b1b..deeda28571 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -9002,7 +9002,7 @@ static void f_sign_jump(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->vval.v_number = -1; - // Sign identifer + // Sign identifier sign_id = (int)tv_get_number_chk(&argvars[0], ¬anum); if (notanum) { return; @@ -9050,7 +9050,7 @@ static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->vval.v_number = -1; - // Sign identifer + // Sign identifier sign_id = (int)tv_get_number_chk(&argvars[0], ¬anum); if (notanum) { return; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index bc3d29a03f..3aaf171b2c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7494,7 +7494,7 @@ static void ex_syncbind(exarg_T *eap) ctrl_o[0] = Ctrl_O; ctrl_o[1] = 0; - ins_typebuf(ctrl_o, REMAP_NONE, 0, TRUE, FALSE); + ins_typebuf(ctrl_o, REMAP_NONE, 0, true, false); } } } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 2e2993ed26..9afce6e9d5 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -78,7 +78,7 @@ FileDescriptor *scriptin[NSCRIPT] = { NULL }; * Un-escaping is done by vgetc(). */ -#define MINIMAL_SIZE 20 /* minimal size for b_str */ +#define MINIMAL_SIZE 20 // minimal size for b_str static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 }; static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 }; @@ -90,7 +90,7 @@ static buffheader_T readbuf1 = { { NULL, { NUL } }, NULL, 0, 0 }; // Second read ahead buffer. Used for redo. static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 }; -static int typeahead_char = 0; /* typeahead char that's not flushed */ +static int typeahead_char = 0; // typeahead char that's not flushed /* * when block_redo is TRUE redo buffer will not be changed @@ -116,9 +116,9 @@ static bool maphash_valid = false; /* * List used for abbreviations. */ -static mapblock_T *first_abbr = NULL; /* first entry in abbrlist */ +static mapblock_T *first_abbr = NULL; // first entry in abbrlist -static int KeyNoremap = 0; /* remapping flags */ +static int KeyNoremap = 0; // remapping flags /* * Variables used by vgetorpeek() and flush_buffers() @@ -139,18 +139,18 @@ static int KeyNoremap = 0; /* remapping flags */ * typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. * (typebuf has been put in globals.h, because check_termcode() needs it). */ -#define RM_YES 0 /* tb_noremap: remap */ -#define RM_NONE 1 /* tb_noremap: don't remap */ -#define RM_SCRIPT 2 /* tb_noremap: remap local script mappings */ -#define RM_ABBR 4 /* tb_noremap: don't remap, do abbrev. */ +#define RM_YES 0 // tb_noremap: remap +#define RM_NONE 1 // tb_noremap: don't remap +#define RM_SCRIPT 2 // tb_noremap: remap local script mappings +#define RM_ABBR 4 // tb_noremap: don't remap, do abbrev. /* typebuf.tb_buf has three parts: room in front (for result of mappings), the * middle for typeahead and room for new characters (which needs to be 3 * * MAXMAPLEN) for the Amiga). */ #define TYPELEN_INIT (5 * (MAXMAPLEN + 3)) -static char_u typebuf_init[TYPELEN_INIT]; /* initial typebuf.tb_buf */ -static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */ +static char_u typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf +static char_u noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap static size_t last_recorded_len = 0; // number of last recorded chars @@ -707,8 +707,9 @@ static int read_redo(bool init, bool old_redo) break; } c = *p; - if (c == NUL) /* cannot happen? */ + if (c == NUL) { // cannot happen? break; + } } return c; @@ -744,14 +745,15 @@ int start_redo(long count, bool old_redo) c = read_redo(false, old_redo); - /* copy the buffer name, if present */ + // copy the buffer name, if present if (c == '"') { add_buff(&readbuf2, "\"", 1L); c = read_redo(false, old_redo); - /* if a numbered buffer is used, increment the number */ - if (c >= '1' && c < '9') - ++c; + // if a numbered buffer is used, increment the number + if (c >= '1' && c < '9') { + c++; + } add_char_buff(&readbuf2, c); // the expression register should be re-evaluated @@ -763,7 +765,7 @@ int start_redo(long count, bool old_redo) c = read_redo(false, old_redo); } - if (c == 'v') { /* redo Visual */ + if (c == 'v') { // redo Visual VIsual = curwin->w_cursor; VIsual_active = true; VIsual_select = false; @@ -780,7 +782,7 @@ int start_redo(long count, bool old_redo) add_num_buff(&readbuf2, count); } - /* copy from the redo buffer into the stuff buffer */ + // copy from the redo buffer into the stuff buffer add_char_buff(&readbuf2, c); copy_redo(old_redo); return OK; @@ -838,26 +840,25 @@ static void init_typebuf(void) } } -/* - * insert a string in position 'offset' in the typeahead buffer (for "@r" - * and ":normal" command, vgetorpeek() and check_termcode()) - * - * If noremap is REMAP_YES, new string can be mapped again. - * If noremap is REMAP_NONE, new string cannot be mapped again. - * If noremap is REMAP_SKIP, fist char of new string cannot be mapped again, - * but abbreviations are allowed. - * If noremap is REMAP_SCRIPT, new string cannot be mapped again, except for - * script-local mappings. - * If noremap is > 0, that many characters of the new string cannot be mapped. - * - * If nottyped is TRUE, the string does not return KeyTyped (don't use when - * offset is non-zero!). - * - * If silent is true, cmd_silent is set when the characters are obtained. - * - * return FAIL for failure, OK otherwise - */ -int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) +// Insert a string in position 'offset' in the typeahead buffer (for "@r" +// and ":normal" command, vgetorpeek() and check_termcode()) +// +// If noremap is REMAP_YES, new string can be mapped again. +// If noremap is REMAP_NONE, new string cannot be mapped again. +// If noremap is REMAP_SKIP, fist char of new string cannot be mapped again, +// but abbreviations are allowed. +// If noremap is REMAP_SCRIPT, new string cannot be mapped again, except for +// script-local mappings. +// If noremap is > 0, that many characters of the new string cannot be mapped. +// +// If nottyped is true, the string does not return KeyTyped (don't use when +// offset is non-zero!). +// +// If silent is true, cmd_silent is set when the characters are obtained. +// +// return FAIL for failure, OK otherwise +int ins_typebuf(char_u *str, int noremap, int offset, + bool nottyped, bool silent) { char_u *s1, *s2; int newlen; @@ -890,8 +891,8 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) // often. newoff = MAXMAPLEN + 4; newlen = typebuf.tb_len + addlen + newoff + 4 * (MAXMAPLEN + 4); - if (newlen < 0) { /* string is getting too long */ - EMSG(_(e_toocompl)); /* also calls flush_buffers */ + if (newlen < 0) { // string is getting too long + EMSG(_(e_toocompl)); // also calls flush_buffers setcursor(); return FAIL; } @@ -927,13 +928,14 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) } typebuf.tb_len += addlen; - /* If noremap == REMAP_SCRIPT: do remap script-local mappings. */ - if (noremap == REMAP_SCRIPT) + // If noremap == REMAP_SCRIPT: do remap script-local mappings. + if (noremap == REMAP_SCRIPT) { val = RM_SCRIPT; - else if (noremap == REMAP_SKIP) + } else if (noremap == REMAP_SKIP) { val = RM_ABBR; - else + } else { val = RM_NONE; + } /* * Adjust typebuf.tb_noremap[] for the new characters: @@ -962,8 +964,9 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) typebuf.tb_silent += addlen; cmd_silent = true; } - if (typebuf.tb_no_abbr_cnt && offset == 0) /* and not used for abbrev.s */ + if (typebuf.tb_no_abbr_cnt && offset == 0) { // and not used for abbrev.s typebuf.tb_no_abbr_cnt += addlen; + } return OK; } @@ -997,9 +1000,8 @@ void ins_char_typebuf(int c) * Or "typebuf.tb_off" may have been changed and we would overwrite characters * that was just added. */ -int -typebuf_changed ( - int tb_change_cnt /* old value of typebuf.tb_change_cnt */ +bool typebuf_changed( + int tb_change_cnt // old value of typebuf.tb_change_cnt ) { return tb_change_cnt != 0 && (typebuf.tb_change_cnt != tb_change_cnt @@ -1031,8 +1033,9 @@ void del_typebuf(int len, int offset) { int i; - if (len == 0) - return; /* nothing to do */ + if (len == 0) { + return; // nothing to do + } typebuf.tb_len -= len; @@ -1068,23 +1071,26 @@ void del_typebuf(int len, int offset) (size_t)(typebuf.tb_len - offset)); } - if (typebuf.tb_maplen > offset) { /* adjust tb_maplen */ - if (typebuf.tb_maplen < offset + len) + if (typebuf.tb_maplen > offset) { // adjust tb_maplen + if (typebuf.tb_maplen < offset + len) { typebuf.tb_maplen = offset; - else + } else { typebuf.tb_maplen -= len; + } } - if (typebuf.tb_silent > offset) { /* adjust tb_silent */ - if (typebuf.tb_silent < offset + len) + if (typebuf.tb_silent > offset) { // adjust tb_silent + if (typebuf.tb_silent < offset + len) { typebuf.tb_silent = offset; - else + } else { typebuf.tb_silent -= len; + } } - if (typebuf.tb_no_abbr_cnt > offset) { /* adjust tb_no_abbr_cnt */ - if (typebuf.tb_no_abbr_cnt < offset + len) + if (typebuf.tb_no_abbr_cnt > offset) { // adjust tb_no_abbr_cnt + if (typebuf.tb_no_abbr_cnt < offset + len) { typebuf.tb_no_abbr_cnt = offset; - else + } else { typebuf.tb_no_abbr_cnt -= len; + } } /* Reset the flag that text received from a client or from feedkeys() @@ -1135,8 +1141,8 @@ static void gotchars(const char_u *chars, size_t len) may_sync_undo(); - /* output "debug mode" message next time in debug mode */ - debug_did_msg = FALSE; + // output "debug mode" message next time in debug mode + debug_did_msg = false; /* Since characters have been typed, consider the following to be in * another mapping. Search string will be kept in history. */ @@ -1253,10 +1259,9 @@ void restore_typeahead(tasave_T *tp) /* * Open a new script file for the ":source!" command. */ -void -openscript ( +void openscript( char_u *name, - int directly /* when TRUE execute directly */ + bool directly // when true execute directly ) { if (curscript + 1 == NSCRIPT) { @@ -1275,9 +1280,10 @@ openscript ( return; } - if (scriptin[curscript] != NULL) /* already reading script */ - ++curscript; - /* use NameBuff for expanded name */ + if (scriptin[curscript] != NULL) { // already reading script + curscript++; + } + // use NameBuff for expanded name expand_env(name, NameBuff, MAXPATHL); int error; if ((scriptin[curscript] = file_open_new(&error, (char *)NameBuff, @@ -1306,11 +1312,11 @@ openscript ( int save_msg_scroll = msg_scroll; State = NORMAL; - msg_scroll = FALSE; /* no msg scrolling in Normal mode */ - restart_edit = 0; /* don't go to Insert mode */ - p_im = FALSE; /* don't use 'insertmode' */ + msg_scroll = false; // no msg scrolling in Normal mode + restart_edit = 0; // don't go to Insert mode + p_im = false; // don't use 'insertmode' clear_oparg(&oa); - finish_op = FALSE; + finish_op = false; oldcurscript = curscript; do { @@ -1626,10 +1632,8 @@ int char_avail(void) return retval != NUL; } -void -vungetc ( /* unget one character (can only be done once!) */ - int c -) +// unget one character (can only be done once!) +void vungetc(int c) { old_char = c; old_mod_mask = mod_mask; @@ -1669,10 +1673,10 @@ static int vgetorpeek(bool advance) mapblock_T *mp2; mapblock_T *mp_match; int mp_match_len = 0; - int timedout = FALSE; /* waited for more than 1 second - for mapping to complete */ - int mapdepth = 0; /* check for recursive mapping */ - int mode_deleted = FALSE; /* set when mode has been deleted */ + bool timedout = false; // waited for more than 1 second + // for mapping to complete + int mapdepth = 0; // check for recursive mapping + bool mode_deleted = false; // set when mode has been deleted int local_State; int mlen; int max_mlen; @@ -1729,8 +1733,9 @@ static int vgetorpeek(bool advance) // needed for CTRL-W CTRL-] to open a fold, for example. KeyStuffed = true; } - if (typebuf.tb_no_abbr_cnt == 0) - typebuf.tb_no_abbr_cnt = 1; /* no abbreviations now */ + if (typebuf.tb_no_abbr_cnt == 0) { + typebuf.tb_no_abbr_cnt = 1; // no abbreviations now + } } else { /* * Loop until we either find a matching mapped key, or we @@ -1744,10 +1749,11 @@ static int vgetorpeek(bool advance) * inside a mapping. But call it each time for typed * characters. */ - if (typebuf.tb_maplen) + if (typebuf.tb_maplen) { line_breakcheck(); - else - os_breakcheck(); /* check for CTRL-C */ + } else { + os_breakcheck(); // check for CTRL-C + } keylen = 0; if (got_int) { // flush all input @@ -1814,11 +1820,11 @@ static int vgetorpeek(bool advance) && get_real_state() != SELECTMODE); nolmaplen = 0; } - /* First try buffer-local mappings. */ + // First try buffer-local mappings. mp = curbuf->b_maphash[MAP_HASH(local_State, c1)]; mp2 = maphash[MAP_HASH(local_State, c1)]; if (mp == NULL) { - /* There are no buffer-local mappings. */ + // There are no buffer-local mappings. mp = mp2; mp2 = NULL; } @@ -1845,8 +1851,8 @@ static int vgetorpeek(bool advance) || typebuf.tb_maplen == 0)) { int nomap = nolmaplen; int c2; - /* find the match length of this mapping */ - for (mlen = 1; mlen < typebuf.tb_len; ++mlen) { + // find the match length of this mapping + for (mlen = 1; mlen < typebuf.tb_len; mlen++) { c2 = typebuf.tb_buf[typebuf.tb_off + mlen]; if (nomap > 0) --nomap; @@ -1901,7 +1907,7 @@ static int vgetorpeek(bool advance) if (keylen > typebuf.tb_len) { if (!timedout && !(mp_match != NULL && mp_match->m_nowait)) { - /* break at a partly match */ + // break at a partly match keylen = KEYLEN_PART_MAP; break; } @@ -1953,13 +1959,14 @@ static int vgetorpeek(bool advance) setcursor(); continue; } - /* Need more chars for partly match. */ - if (mlen == typebuf.tb_len) + // Need more chars for partly match. + if (mlen == typebuf.tb_len) { keylen = KEYLEN_PART_KEY; - else if (max_mlen < mlen) - /* no match, may have to check for termcode at - * next character */ + } else if (max_mlen < mlen) { + // no match, may have to check for termcode at + // next character max_mlen = mlen + 1; + } } if ((mp == NULL || max_mlen >= mp_match_len) @@ -1991,13 +1998,11 @@ static int vgetorpeek(bool advance) } } - /* complete match */ + // complete match if (keylen >= 0 && keylen <= typebuf.tb_len) { int save_m_expr; int save_m_noremap; int save_m_silent; - char_u *save_m_keys; - char_u *save_m_str; // Write chars to script file(s) // Note: :lmap mappings are written *after* being applied. #5658 @@ -2007,7 +2012,7 @@ static int vgetorpeek(bool advance) } cmd_silent = (typebuf.tb_silent > 0); - del_typebuf(keylen, 0); /* remove the mapped keys */ + del_typebuf(keylen, 0); // remove the mapped keys /* * Put the replacement string in front of mapstr. @@ -2032,9 +2037,8 @@ static int vgetorpeek(bool advance) */ if (VIsual_active && VIsual_select && (mp->m_mode & VISUAL)) { - VIsual_select = FALSE; - (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, - 0, TRUE, FALSE); + VIsual_select = false; + (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false); } /* Copy the values from *mp that are used, because @@ -2044,8 +2048,8 @@ static int vgetorpeek(bool advance) save_m_expr = mp->m_expr; save_m_noremap = mp->m_noremap; save_m_silent = mp->m_silent; - save_m_keys = NULL; /* only saved when needed */ - save_m_str = 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 /* * Handle ":map <expr>": evaluate the {rhs} as an @@ -2141,14 +2145,14 @@ static int vgetorpeek(bool advance) char_u *ptr; if (mode_displayed) { - unshowmode(TRUE); - mode_deleted = TRUE; + unshowmode(true); + mode_deleted = true; } validate_cursor(); old_wcol = curwin->w_wcol; old_wrow = curwin->w_wrow; - /* move cursor left, if possible */ + // move cursor left, if possible if (curwin->w_cursor.col != 0) { if (curwin->w_wcol > 0) { if (did_ai) { @@ -2170,7 +2174,7 @@ static int vgetorpeek(bool advance) + curwin->w_wcol / curwin->w_width_inner; curwin->w_wcol %= curwin->w_width_inner; curwin->w_wcol += curwin_col_off(); - col = 0; /* no correction needed */ + col = 0; // no correction needed } else { --curwin->w_wcol; col = curwin->w_cursor.col - 1; @@ -2197,8 +2201,9 @@ static int vgetorpeek(bool advance) curwin->w_wcol = old_wcol; curwin->w_wrow = old_wrow; } - if (c < 0) - continue; /* end of input script reached */ + if (c < 0) { + continue; // end of input script reached + } // Allow mapping for just typed characters. When we get here c // is the number of extra bytes and typebuf.tb_len is 1. @@ -2207,20 +2212,20 @@ static int vgetorpeek(bool advance) } typebuf.tb_len += c; - /* buffer full, don't map */ + // buffer full, don't map if (typebuf.tb_len >= typebuf.tb_maplen + MAXMAPLEN) { - timedout = TRUE; + timedout = true; continue; } if (ex_normal_busy > 0) { static int tc = 0; - /* No typeahead left and inside ":normal". Must return - * something to avoid getting stuck. When an incomplete - * mapping is present, behave like it timed out. */ + // No typeahead left and inside ":normal". Must return + // something to avoid getting stuck. When an incomplete + // mapping is present, behave like it timed out. if (typebuf.tb_len > 0) { - timedout = TRUE; + timedout = true; continue; } /* When 'insertmode' is set, ESC just beeps in Insert @@ -2254,7 +2259,7 @@ static int vgetorpeek(bool advance) if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 && advance && must_redraw != 0 && !need_wait_return) { update_screen(0); - setcursor(); /* put cursor back where it belongs */ + setcursor(); // put cursor back where it belongs } /* @@ -2267,16 +2272,16 @@ static int vgetorpeek(bool advance) if (typebuf.tb_len > 0 && advance && !exmode_active) { if (((State & (NORMAL | INSERT)) || State == LANGMAP) && State != HITRETURN) { - /* this looks nice when typing a dead character map */ + // this looks nice when typing a dead character map if (State & INSERT && ptr2cells(typebuf.tb_buf + typebuf.tb_off - + typebuf.tb_len - 1) == 1) { - edit_putchar(typebuf.tb_buf[typebuf.tb_off - + typebuf.tb_len - 1], FALSE); - setcursor(); /* put cursor back where it belongs */ + + typebuf.tb_len - 1) == 1) { + edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], + false); + setcursor(); // put cursor back where it belongs c1 = 1; } - /* need to use the col and row from above here */ + // need to use the col and row from above here old_wcol = curwin->w_wcol; old_wrow = curwin->w_wrow; curwin->w_wcol = new_wcol; @@ -2332,31 +2337,34 @@ static int vgetorpeek(bool advance) if (i != 0) pop_showcmd(); if (c1 == 1) { - if (State & INSERT) + if (State & INSERT) { edit_unputchar(); - if (State & CMDLINE) + } + if (State & CMDLINE) { unputcmdline(); - else - setcursor(); /* put cursor back where it belongs */ + } else { + setcursor(); // put cursor back where it belongs + } } - if (c < 0) - continue; /* end of input script reached */ - if (c == NUL) { /* no character available */ - if (!advance) + if (c < 0) { + continue; // end of input script reached + } + if (c == NUL) { // no character available + if (!advance) { break; - if (wait_tb_len > 0) { /* timed out */ - timedout = TRUE; + } + if (wait_tb_len > 0) { // timed out + timedout = true; continue; } - } else { /* allow mapping for just typed characters */ - while (typebuf.tb_buf[typebuf.tb_off - + typebuf.tb_len] != NUL) - typebuf.tb_noremap[typebuf.tb_off - + typebuf.tb_len++] = RM_YES; + } else { // allow mapping for just typed characters + while (typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] != NUL) { + typebuf.tb_noremap[typebuf.tb_off + typebuf.tb_len++] = RM_YES; + } } - } /* for (;;) */ - } /* if (!character from stuffbuf) */ + } // for (;;) + } // if (!character from stuffbuf) // if advance is false don't loop on NULs } while (c < 0 || (advance && c == NUL)); @@ -2368,15 +2376,17 @@ static int vgetorpeek(bool advance) */ if (advance && p_smd && msg_silent == 0 && (State & INSERT)) { if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) { - if (typebuf.tb_len && !KeyTyped) - redraw_cmdline = TRUE; /* delete mode later */ - else - unshowmode(FALSE); + if (typebuf.tb_len && !KeyTyped) { + redraw_cmdline = true; // delete mode later + } else { + unshowmode(false); + } } else if (c != ESC && mode_deleted) { - if (typebuf.tb_len && !KeyTyped) - redraw_cmdline = TRUE; /* show mode later */ - else + if (typebuf.tb_len && !KeyTyped) { + redraw_cmdline = true; // show mode later + } else { showmode(); + } } } @@ -2440,8 +2450,8 @@ int inchar( * on char wait, flush swapfile, write error....). */ if (State != HITRETURN) { - did_outofmem_msg = FALSE; /* display out of memory message (again) */ - did_swapwrite_msg = FALSE; /* display swap file write error again */ + did_outofmem_msg = false; // display out of memory message (again) + did_swapwrite_msg = false; // display swap file write error again } // Get a character from a script file if there is one. @@ -3175,7 +3185,7 @@ static void validate_maphash(void) /* * Get the mapping mode from the command name. */ -int get_map_mode(char_u **cmdp, int forceit) +int get_map_mode(char_u **cmdp, bool forceit) { char_u *p; int modec; @@ -3183,30 +3193,31 @@ int get_map_mode(char_u **cmdp, int forceit) p = *cmdp; modec = *p++; - if (modec == 'i') - mode = INSERT; /* :imap */ - else if (modec == 'l') - mode = LANGMAP; /* :lmap */ - else if (modec == 'c') - mode = CMDLINE; /* :cmap */ - else if (modec == 'n' && *p != 'o') /* avoid :noremap */ - mode = NORMAL; /* :nmap */ - else if (modec == 'v') - mode = VISUAL + SELECTMODE; /* :vmap */ - else if (modec == 'x') - mode = VISUAL; /* :xmap */ - else if (modec == 's') - mode = SELECTMODE; /* :smap */ - else if (modec == 'o') - mode = OP_PENDING; /* :omap */ - else if (modec == 't') - mode = TERM_FOCUS; // :tmap - else { - --p; - if (forceit) - mode = INSERT + CMDLINE; /* :map ! */ - else - mode = VISUAL + SELECTMODE + NORMAL + OP_PENDING; /* :map */ + if (modec == 'i') { + mode = INSERT; // :imap + } else if (modec == 'l') { + mode = LANGMAP; // :lmap + } else if (modec == 'c') { + mode = CMDLINE; // :cmap + } else if (modec == 'n' && *p != 'o') { // avoid :noremap + mode = NORMAL; // :nmap + } else if (modec == 'v') { + mode = VISUAL + SELECTMODE; // :vmap + } else if (modec == 'x') { + mode = VISUAL; // :xmap + } else if (modec == 's') { + mode = SELECTMODE; // :smap + } else if (modec == 'o') { + mode = OP_PENDING; // :omap + } else if (modec == 't') { + mode = TERM_FOCUS; // :tmap + } else { + p--; + if (forceit) { + mode = INSERT + CMDLINE; // :map ! + } else { + mode = VISUAL + SELECTMODE + NORMAL + OP_PENDING; // :map + } } *cmdp = p; @@ -3237,12 +3248,11 @@ void map_clear_mode(char_u *cmdp, char_u *arg, int forceit, int abbr) /* * Clear all mappings in "mode". */ -void -map_clear_int ( - buf_T *buf, /* buffer for local mappings */ - int mode, /* mode in which to delete */ - int local, /* TRUE for buffer-local mappings */ - int abbr /* TRUE for abbreviations */ +void map_clear_int( + buf_T *buf, // buffer for local mappings + int mode, // mode in which to delete + bool local, // true for buffer-local mappings + bool abbr // true for abbreviations ) { mapblock_T *mp, **mpp; @@ -3253,12 +3263,14 @@ map_clear_int ( for (hash = 0; hash < 256; ++hash) { if (abbr) { - if (hash > 0) /* there is only one abbrlist */ + if (hash > 0) { // there is only one abbrlist break; - if (local) + } + if (local) { mpp = &buf->b_first_abbr; - else + } else { mpp = &first_abbr; + } } else { if (local) mpp = &buf->b_maphash[hash]; @@ -3286,7 +3298,7 @@ map_clear_int ( mp->m_next = maphash[new_hash]; maphash[new_hash] = mp; } - continue; /* continue with *mpp */ + continue; // continue with *mpp } } mpp = &(mp->m_next); @@ -3341,10 +3353,9 @@ char *map_mode_to_chars(int mode) return (char *)mapmode.ga_data; } -static void -showmap ( +static void showmap( mapblock_T *mp, - int local /* TRUE for buffer-local map */ + bool local // true for buffer-local map ) { size_t len = 1; @@ -3355,8 +3366,9 @@ showmap ( if (msg_didout || msg_silent != 0) { msg_putchar('\n'); - if (got_int) /* 'q' typed at MORE prompt */ + if (got_int) { // 'q' typed at MORE prompt return; + } } { @@ -3372,8 +3384,8 @@ showmap ( // Display the LHS. Get length of what we write. len = (size_t)msg_outtrans_special(mp->m_keys, true, 0); do { - msg_putchar(' '); /* padd with blanks */ - ++len; + msg_putchar(' '); // padd with blanks + len++; } while (len < 12); if (mp->m_noremap == REMAP_NONE) { @@ -3506,21 +3518,20 @@ int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr) * Used below when expanding mapping/abbreviation names. */ static int expand_mapmodes = 0; -static int expand_isabbrev = 0; -static int expand_buffer = FALSE; +static bool expand_isabbrev = false; +static bool expand_buffer = false; /* * Work out what to complete when doing command line completion of mapping * or abbreviation names. */ -char_u * -set_context_in_map_cmd ( +char_u *set_context_in_map_cmd( expand_T *xp, char_u *cmd, char_u *arg, - int forceit, /* TRUE if '!' given */ - int isabbrev, /* TRUE if abbreviation */ - int isunmap, /* TRUE if unmap/unabbrev command */ + bool forceit, // true if '!' given + bool isabbrev, // true if abbreviation + bool isunmap, // true if unmap/unabbrev command cmdidx_T cmdidx ) { @@ -3536,10 +3547,10 @@ set_context_in_map_cmd ( } expand_isabbrev = isabbrev; xp->xp_context = EXPAND_MAPPINGS; - expand_buffer = FALSE; + expand_buffer = false; for (;; ) { if (STRNCMP(arg, "<buffer>", 8) == 0) { - expand_buffer = TRUE; + expand_buffer = true; arg = skipwhite(arg + 8); continue; } @@ -3589,7 +3600,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) validate_maphash(); - *num_file = 0; /* return values in case of FAIL */ + *num_file = 0; // return values in case of FAIL *file = NULL; /* @@ -3628,8 +3639,9 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) for (hash = 0; hash < 256; ++hash) { if (expand_isabbrev) { - if (hash > 0) /* only one abbrev list */ - break; /* for (hash) */ + if (hash > 0) { // only one abbrev list + break; // for (hash) + } mp = first_abbr; } else if (expand_buffer) mp = curbuf->b_maphash[hash]; @@ -3648,26 +3660,27 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) } xfree(p); } - } /* for (mp) */ - } /* for (hash) */ + } // for (mp) + } // for (hash) - if (count == 0) /* no match found */ - break; /* for (round) */ + if (count == 0) { // no match found + break; // for (round) + } if (round == 1) { *file = (char_u **)xmalloc((size_t)count * sizeof(char_u *)); } - } /* for (round) */ + } // for (round) if (count > 1) { char_u **ptr1; char_u **ptr2; char_u **ptr3; - /* Sort the matches */ + // Sort the matches sort_strings(*file, count); - /* Remove multiple entries */ + // Remove multiple entries ptr1 = *file; ptr2 = ptr1 + 1; ptr3 = ptr1 + count; @@ -3705,7 +3718,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) bool check_abbr(int c, char_u *ptr, int col, int mincol) { int len; - int scol; /* starting column of the abbr. */ + int scol; // starting column of the abbr. int j; char_u *s; char_u tb[MB_MAXBYTES + 4]; @@ -3756,7 +3769,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) if (scol < mincol) scol = mincol; - if (scol < col) { /* there is a word in front of the cursor */ + if (scol < col) { // there is a word in front of the cursor ptr += scol; len = col - scol; mp = curbuf->b_first_abbr; @@ -3778,7 +3791,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) vim_unescape_csi(q); qlen = (int)STRLEN(q); } - /* find entries with right mode and keys */ + // find entries with right mode and keys match = (mp->m_mode & State) && qlen == len && !STRNCMP(q, ptr, (size_t)len); @@ -3805,7 +3818,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) */ j = 0; if (c != Ctrl_RSB) { - /* special key code, split up */ + // special key code, split up if (IS_SPECIAL(c) || c == K_SPECIAL) { tb[j++] = K_SPECIAL; tb[j++] = (char_u)K_SECOND(c); @@ -3821,17 +3834,17 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) j += utf_char2bytes(c, tb + j); } tb[j] = NUL; - /* insert the last typed char */ - (void)ins_typebuf(tb, 1, 0, TRUE, mp->m_silent); + // insert the last typed char + (void)ins_typebuf(tb, 1, 0, true, mp->m_silent); } if (mp->m_expr) s = eval_map_expr(mp->m_str, c); else s = mp->m_str; if (s != NULL) { - /* insert the to string */ - (void)ins_typebuf(s, mp->m_noremap, 0, TRUE, mp->m_silent); - /* no abbrev. for these chars */ + // insert the to string + (void)ins_typebuf(s, mp->m_noremap, 0, true, mp->m_silent); + // no abbrev. for these chars typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1; if (mp->m_expr) xfree(s); @@ -3856,7 +3869,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) static char_u * eval_map_expr ( char_u *str, - int c /* NUL or typed character for abbreviation */ + int c // NUL or typed character for abbreviation ) { char_u *res; @@ -3874,11 +3887,11 @@ eval_map_expr ( save_cmd = save_cmdline_alloc(); - /* Forbid changing text or using ":normal" to avoid most of the bad side - * effects. Also restore the cursor position. */ - ++textlock; - ++ex_normal_lock; - set_vim_var_char(c); /* set v:char to the typed character */ + // Forbid changing text or using ":normal" to avoid most of the bad side + // effects. Also restore the cursor position. + textlock++; + ex_normal_lock++; + set_vim_var_char(c); // set v:char to the typed character save_cursor = curwin->w_cursor; save_msg_col = msg_col; save_msg_row = msg_row; @@ -3894,7 +3907,7 @@ eval_map_expr ( if (p == NULL) return NULL; - /* Escape CSI in the result to be able to use the string as typeahead. */ + // Escape CSI in the result to be able to use the string as typeahead. res = vim_strsave_escape_csi(p); xfree(p); @@ -3914,7 +3927,7 @@ char_u *vim_strsave_escape_csi(char_u *p) char_u *d = res; for (char_u *s = p; *s != NUL; ) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { - /* Copy special key unmodified. */ + // Copy special key unmodified. *d++ = *s++; *d++ = *s++; *d++ = *s++; @@ -4213,9 +4226,10 @@ int put_escstr(FILE *fd, char_u *strstart, int what) c = TO_SPECIAL(str[1], str[2]); str += 2; } - if (IS_SPECIAL(c) || modifiers) { /* special key */ - if (fputs((char *)get_special_key_name(c, modifiers), fd) < 0) + if (IS_SPECIAL(c) || modifiers) { // special key + if (fputs((char *)get_special_key_name(c, modifiers), fd) < 0) { return FAIL; + } continue; } } @@ -4271,35 +4285,36 @@ char_u * check_map ( char_u *keys, int mode, - int exact, /* require exact match */ - int ign_mod, /* ignore preceding modifier */ - int abbr, /* do abbreviations */ - mapblock_T **mp_ptr, /* return: pointer to mapblock or NULL */ - int *local_ptr /* return: buffer-local mapping or NULL */ + int exact, // require exact match + int ign_mod, // ignore preceding modifier + int abbr, // do abbreviations + mapblock_T **mp_ptr, // return: pointer to mapblock or NULL + int *local_ptr // return: buffer-local mapping or NULL ) { - int hash; int len, minlen; mapblock_T *mp; - int local; validate_maphash(); len = (int)STRLEN(keys); - for (local = 1; local >= 0; --local) - /* loop over all hash lists */ - for (hash = 0; hash < 256; ++hash) { + for (int local = 1; local >= 0; local--) { + // loop over all hash lists + for (int hash = 0; hash < 256; hash++) { if (abbr) { - if (hash > 0) /* there is only one list. */ + if (hash > 0) { // there is only one list. break; - if (local) + } + if (local) { mp = curbuf->b_first_abbr; - else + } else { mp = first_abbr; - } else if (local) + } + } else if (local) { mp = curbuf->b_maphash[hash]; - else + } else { mp = maphash[hash]; + } for (; mp != NULL; mp = mp->m_next) { /* skip entries with wrong mode, wrong length and not matching * ones */ @@ -4322,6 +4337,7 @@ check_map ( } } } + } return NULL; } @@ -4336,7 +4352,7 @@ void add_map(char_u *map, int mode) char_u *s; char_u *cpo_save = p_cpo; - p_cpo = (char_u *)""; /* Allow <> notation */ + p_cpo = (char_u *)""; // Allow <> notation s = vim_strsave(map); (void)do_map(0, s, mode, FALSE); xfree(s); @@ -4384,7 +4400,7 @@ static char_u * translate_mapping ( } if (IS_SPECIAL(c) || modifiers) { // special key ga_concat(&ga, get_special_key_name(c, modifiers)); - continue; /* for (str) */ + continue; // for (str) } } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 7b8e809de7..ffe0357bd8 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -256,7 +256,7 @@ EXTERN linenr_T sourcing_lnum INIT(= 0); // line number of the source file EXTERN int ex_nesting_level INIT(= 0); // nesting level EXTERN int debug_break_level INIT(= -1); // break below this level -EXTERN int debug_did_msg INIT(= false); // did "debug mode" message +EXTERN bool debug_did_msg INIT(= false); // did "debug mode" message EXTERN int debug_tick INIT(= 0); // breakpoint change count EXTERN int debug_backtrace_level INIT(= 0); // breakpoint backtrace level diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 92ecbe160b..8fa61515ef 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -429,11 +429,9 @@ int get_number_indent(linenr_T lnum) return (int)col; } -/* - * Return appropriate space number for breakindent, taking influencing - * parameters into account. Window must be specified, since it is not - * necessarily always the current one. - */ +// Return appropriate space number for breakindent, taking influencing +// parameters into account. Window must be specified, since it is not +// necessarily always the current one. int get_breakindent_win(win_T *wp, const char_u *line) FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 9298e57411..771bf923b2 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -33,15 +33,12 @@ typedef struct { * Search starts at w_cursor.lnum and goes backwards. * Return NULL when not inside a comment. */ -static pos_T *ind_find_start_comment(void) -{ /* XXX */ +static pos_T *ind_find_start_comment(void) // XXX +{ return find_start_comment(curbuf->b_ind_maxcomment); } -pos_T * -find_start_comment ( /* XXX */ - int ind_maxcomment -) +pos_T *find_start_comment(int ind_maxcomment) // XXX { pos_T *pos; char_u *line; @@ -109,8 +106,8 @@ static pos_T *ind_find_start_CORS(linenr_T *is_raw) * Search starts at w_cursor.lnum and goes backwards. * Return NULL when not inside a raw string. */ -static pos_T *find_start_rawstring(int ind_maxcomment) -{ /* XXX */ +static pos_T *find_start_rawstring(int ind_maxcomment) // XXX +{ pos_T *pos; char_u *line; char_u *p; @@ -152,31 +149,35 @@ static char_u *skip_string(char_u *p) /* * We loop, because strings may be concatenated: "date""time". */ - for (;; ++p) { - if (p[0] == '\'') { /* 'c' or '\n' or '\000' */ - if (!p[1]) /* ' at end of line */ + for (;; p++) { + if (p[0] == '\'') { // 'c' or '\n' or '\000' + if (!p[1]) { // ' at end of line break; + } i = 2; - if (p[1] == '\\') { /* '\n' or '\000' */ - ++i; - while (ascii_isdigit(p[i - 1])) /* '\000' */ - ++i; + if (p[1] == '\\') { // '\n' or '\000' + i++; + while (ascii_isdigit(p[i - 1])) { // '\000' + i++; + } } - if (p[i] == '\'') { /* check for trailing ' */ + if (p[i] == '\'') { // check for trailing ' p += i; continue; } - } else if (p[0] == '"') { /* start of string */ - for (++p; p[0]; ++p) { - if (p[0] == '\\' && p[1] != NUL) - ++p; - else if (p[0] == '"') /* end of string */ + } else if (p[0] == '"') { // start of string + for (++p; p[0]; p++) { + if (p[0] == '\\' && p[1] != NUL) { + p++; + } else if (p[0] == '"') { // end of string break; + } + } + if (p[0] == '"') { + continue; // continue for another string } - if (p[0] == '"') - continue; /* continue for another string */ } else if (p[0] == 'R' && p[1] == '"') { - /* Raw string: R"[delim](...)[delim]" */ + // Raw string: R"[delim](...)[delim]" char_u *delim = p + 2; char_u *paren = vim_strchr(delim, '('); @@ -190,14 +191,16 @@ static char_u *skip_string(char_u *p) p += delim_len + 1; break; } - if (p[0] == '"') - continue; /* continue for another string */ + if (p[0] == '"') { + continue; // continue for another string + } } } - break; /* no string found */ + break; // no string found + } + if (!*p) { + p--; // backup from NUL } - if (!*p) - --p; /* backup from NUL */ return p; } @@ -255,20 +258,22 @@ static char_u *cin_skipcomment(char_u *s) s += STRLEN(s); break; } - if (*s != '/') + if (*s != '/') { break; - ++s; - if (*s == '/') { /* slash-slash comment continues till eol */ + } + s++; + if (*s == '/') { // slash-slash comment continues till eol s += STRLEN(s); break; } if (*s != '*') break; - for (++s; *s; ++s) /* skip slash-star comment */ + for (++s; *s; s++) { // skip slash-star comment if (s[0] == '*' && s[1] == '/') { s += 2; break; } + } } return s; } @@ -285,7 +290,7 @@ static int cin_nocode(char_u *s) /* * Check previous lines for a "//" line comment, skipping over blank lines. */ -static pos_T *find_line_comment(void) /* XXX */ +static pos_T *find_line_comment(void) // XXX { static pos_T pos; char_u *line; @@ -335,39 +340,38 @@ static bool cin_has_js_key(char_u *text) /// Checks if string matches "label:"; move to character after ':' if true. /// "*s" must point to the start of the label, if there is one. -static int cin_islabel_skip(char_u **s) +static bool cin_islabel_skip(char_u **s) + FUNC_ATTR_NONNULL_ALL { - if (!vim_isIDc(**s)) /* need at least one ID character */ - return FALSE; + if (!vim_isIDc(**s)) { // need at least one ID character + return false; + } while (vim_isIDc(**s)) (*s)++; *s = cin_skipcomment(*s); - /* "::" is not a label, it's C++ */ + // "::" is not a label, it's C++ return **s == ':' && *++*s != ':'; } -/* - * Recognize a label: "label:". - * Note: curwin->w_cursor must be where we are looking for the label. - */ -int cin_islabel(void) -{ /* XXX */ +// Recognize a label: "label:". +// Note: curwin->w_cursor must be where we are looking for the label. +bool cin_islabel(void) // XXX +{ char_u *s = cin_skipcomment(get_cursor_line_ptr()); - /* - * Exclude "default" from labels, since it should be indented - * like a switch label. Same for C++ scope declarations. - */ - if (cin_isdefault(s)) - return FALSE; - if (cin_isscopedecl(s)) - return FALSE; - + // Exclude "default" from labels, since it should be indented + // like a switch label. Same for C++ scope declarations. + if (cin_isdefault(s)) { + return false; + } + if (cin_isscopedecl(s)) { + return false; + } if (!cin_islabel_skip(&s)) { - return FALSE; + return false; } /* @@ -392,21 +396,24 @@ int cin_islabel(void) } line = get_cursor_line_ptr(); - if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */ + if (cin_ispreproc(line)) { // ignore #defines, #if, etc. continue; - if (*(line = cin_skipcomment(line)) == NUL) + } + if (*(line = cin_skipcomment(line)) == NUL) { continue; + } curwin->w_cursor = cursor_save; if (cin_isterminated(line, TRUE, FALSE) || cin_isscopedecl(line) - || cin_iscase(line, TRUE) - || (cin_islabel_skip(&line) && cin_nocode(line))) - return TRUE; - return FALSE; + || cin_iscase(line, true) + || (cin_islabel_skip(&line) && cin_nocode(line))) { + return true; + } + return false; } curwin->w_cursor = cursor_save; - return TRUE; /* label at start of file??? */ + return true; // label at start of file??? } /* @@ -451,10 +458,9 @@ static int cin_isinit(void) /* * Recognize a switch label: "case .*:" or "default:". */ -int -cin_iscase ( +bool cin_iscase( char_u *s, - int strict /* Allow relaxed check of case statement for JS */ + bool strict // Allow relaxed check of case statement for JS ) { s = cin_skipcomment(s); @@ -465,29 +471,32 @@ cin_iscase ( break; } if (*s == ':') { - if (s[1] == ':') /* skip over "::" for C++ */ - ++s; - else - return TRUE; + if (s[1] == ':') { // skip over "::" for C++ + s++; + } else { + return true; + } } - if (*s == '\'' && s[1] && s[2] == '\'') - s += 2; /* skip over ':' */ - else if (*s == '/' && (s[1] == '*' || s[1] == '/')) - return FALSE; /* stop at comment */ - else if (*s == '"') { - /* JS etc. */ - if (strict) - return FALSE; /* stop at string */ - else - return TRUE; + if (*s == '\'' && s[1] && s[2] == '\'') { + s += 2; // skip over ':' + } else if (*s == '/' && (s[1] == '*' || s[1] == '/')) { + return false; // stop at comment + } else if (*s == '"') { + // JS etc. + if (strict) { + return false; // stop at string + } else { + return true; + } } } - return FALSE; + return false; } - if (cin_isdefault(s)) - return TRUE; - return FALSE; + if (cin_isdefault(s)) { + return true; + } + return false; } /* @@ -503,23 +512,24 @@ static int cin_isdefault(char_u *s) /* * Recognize a "public/private/protected" scope declaration label. */ -int cin_isscopedecl(char_u *s) +bool cin_isscopedecl(char_u *s) { int i; s = cin_skipcomment(s); - if (STRNCMP(s, "public", 6) == 0) + if (STRNCMP(s, "public", 6) == 0) { i = 6; - else if (STRNCMP(s, "protected", 9) == 0) + } else if (STRNCMP(s, "protected", 9) == 0) { i = 9; - else if (STRNCMP(s, "private", 7) == 0) + } else if (STRNCMP(s, "private", 7) == 0) { i = 7; - else - return FALSE; + } else { + return false; + } return *(s = cin_skipcomment(s + i)) == ':' && s[1] != ':'; } -/* Maximum number of lines to search back for a "namespace" line. */ +// Maximum number of lines to search back for a "namespace" line. #define FIND_NAMESPACE_LIM 20 // Recognize a "namespace" scope declaration. @@ -569,12 +579,14 @@ static char_u *after_label(char_u *l) { for (; *l; ++l) { if (*l == ':') { - if (l[1] == ':') /* skip over "::" for C++ */ - ++l; - else if (!cin_iscase(l + 1, FALSE)) + if (l[1] == ':') { // skip over "::" for C++ + l++; + } else if (!cin_iscase(l + 1, false)) { break; - } else if (*l == '\'' && l[1] && l[2] == '\'') - l += 2; /* skip over 'x' */ + } + } else if (*l == '\'' && l[1] && l[2] == '\'') { + l += 2; // skip over 'x' + } } if (*l == NUL) return NULL; @@ -588,10 +600,7 @@ static char_u *after_label(char_u *l) * Get indent of line "lnum", skipping a label. * Return 0 if there is nothing after the label. */ -static int -get_indent_nolabel ( /* XXX */ - linenr_T lnum -) +static int get_indent_nolabel(linenr_T lnum) // XXX { char_u *l; pos_T fp; @@ -624,12 +633,13 @@ static int skip_label(linenr_T lnum, char_u **pp) cursor_save = curwin->w_cursor; curwin->w_cursor.lnum = lnum; l = get_cursor_line_ptr(); - /* XXX */ - if (cin_iscase(l, FALSE) || cin_isscopedecl(l) || cin_islabel()) { + // XXX + if (cin_iscase(l, false) || cin_isscopedecl(l) || cin_islabel()) { amount = get_indent_nolabel(lnum); l = after_label(get_cursor_line_ptr()); - if (l == NULL) /* just in case */ + if (l == NULL) { // just in case l = get_cursor_line_ptr(); + } } else { amount = get_indent(); l = get_cursor_line_ptr(); @@ -710,10 +720,11 @@ static int cin_get_equal_amount(linenr_T lnum) line = s = ml_get(lnum); while (*s != NUL && vim_strchr((char_u *)"=;{}\"'", *s) == NULL) { - if (cin_iscomment(s)) /* ignore comments */ + if (cin_iscomment(s)) { // ignore comments s = cin_skipcomment(s); - else - ++s; + } else { + s++; + } } if (*s != '=') return 0; @@ -722,8 +733,9 @@ static int cin_get_equal_amount(linenr_T lnum) if (cin_nocode(s)) return 0; - if (*s == '"') /* nice alignment for continued strings */ - ++s; + if (*s == '"') { // nice alignment for continued strings + s++; + } fp.lnum = lnum; fp.col = (colnr_T)(s - line); @@ -806,8 +818,8 @@ static int cin_islinecomment(char_u *p) static char_u cin_isterminated ( char_u *s, - int incl_open, /* include '{' at the end as terminator */ - int incl_comma /* recognize a trailing comma */ + int incl_open, // include '{' at the end as terminator + int incl_comma // recognize a trailing comma ) { char_u found_start = 0; @@ -823,7 +835,7 @@ cin_isterminated ( is_else = cin_iselse(s); while (*s) { - /* skip over comments, "" strings and 'c'haracters */ + // skip over comments, "" strings and 'c'haracters s = skip_string(cin_skipcomment(s)); if (*s == '}' && n_open > 0) --n_open; @@ -942,12 +954,12 @@ static int cin_isfuncdecl(char_u **sp, linenr_T first_lnum, linenr_T min_lnum) s = skipwhite(s); if (!just_started && (!comma && *s != ',' && *s != ')')) break; - just_started = FALSE; - } else if (cin_iscomment(s)) /* ignore comments */ + just_started = false; + } else if (cin_iscomment(s)) { // ignore comments s = cin_skipcomment(s); - else { - ++s; - just_started = FALSE; + } else { + s++; + just_started = false; } } @@ -965,8 +977,9 @@ static int cin_isif(char_u *p) static int cin_iselse(char_u *p) { - if (*p == '}') /* accept "} else" */ + if (*p == '}') { // accept "} else" p = cin_skipcomment(p + 1); + } return STRNCMP(p, "else", 4) == 0 && !vim_isIDc(p[4]); } @@ -980,27 +993,24 @@ static int cin_isdo(char_u *p) * We only accept a "while (condition) ;", with only white space between the * ')' and ';'. The condition may be spread over several lines. */ -static int -cin_iswhileofdo ( /* XXX */ - char_u *p, - linenr_T lnum -) +static int cin_iswhileofdo(char_u *p, linenr_T lnum) // XXX { pos_T cursor_save; pos_T *trypos; int retval = FALSE; p = cin_skipcomment(p); - if (*p == '}') /* accept "} while (cond);" */ + if (*p == '}') { // accept "} while (cond);" p = cin_skipcomment(p + 1); + } if (cin_starts_with(p, "while")) { cursor_save = curwin->w_cursor; curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; p = get_cursor_line_ptr(); - while (*p && *p != 'w') { /* skip any '}', until the 'w' of the "while" */ - ++p; - ++curwin->w_cursor.col; + while (*p && *p != 'w') { // skip any '}', until the 'w' of the "while" + p++; + curwin->w_cursor.col++; } if ((trypos = findmatchlimit(NULL, 0, 0, curbuf->b_ind_maxparen)) != NULL @@ -1067,8 +1077,9 @@ static int cin_iswhileofdo_end(int terminated) pos_T *trypos; int i; - if (terminated != ';') /* there must be a ';' at the end */ - return FALSE; + if (terminated != ';') { // there must be a ';' at the end + return false; + } p = line = get_cursor_line_ptr(); while (*p != NUL) { @@ -1083,15 +1094,16 @@ static int cin_iswhileofdo_end(int terminated) trypos = find_match_paren(curbuf->b_ind_maxparen); if (trypos != NULL) { s = cin_skipcomment(ml_get(trypos->lnum)); - if (*s == '}') /* accept "} while (cond);" */ + if (*s == '}') { // accept "} while (cond);" s = cin_skipcomment(s + 1); + } if (cin_starts_with(s, "while")) { curwin->w_cursor.lnum = trypos->lnum; return TRUE; } } - /* Searching may have made "line" invalid, get it again. */ + // Searching may have made "line" invalid, get it again. line = get_cursor_line_ptr(); p = line + i; } @@ -1134,8 +1146,9 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) { pos->col = 0; s = skipwhite(line); - if (*s == '#') /* skip #define FOO x ? (x) : x */ - return FALSE; + if (*s == '#') { // skip #define FOO x ? (x) : x + return false; + } s = cin_skipcomment(s); if (*s == NUL) return FALSE; @@ -1230,23 +1243,23 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) { class_or_struct = FALSE; lookfor_ctor_init = TRUE; } else if (s[0] == '?') { - /* Avoid seeing '() :' after '?' as constructor init. */ - return FALSE; + // Avoid seeing '() :' after '?' as constructor init. + return false; } else if (!vim_isIDc(s[0])) { - /* if it is not an identifier, we are wrong */ + // if it is not an identifier, we are wrong class_or_struct = false; lookfor_ctor_init = false; } else if (pos->col == 0) { - /* it can't be a constructor-initialization any more */ - lookfor_ctor_init = FALSE; + // it can't be a constructor-initialization any more + lookfor_ctor_init = false; - /* the first statement starts here: lineup with this one... */ + // the first statement starts here: lineup with this one... if (cpp_base_class) { pos->col = (colnr_T)(s - line); } } - /* When the line ends in a comma don't align with it. */ + // When the line ends in a comma don't align with it. if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1)) { pos->col = 0; } @@ -1271,10 +1284,12 @@ static int get_baseclass_amount(int col) if (col == 0) { amount = get_indent(); if (find_last_paren(get_cursor_line_ptr(), '(', ')') - && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) - amount = get_indent_lnum(trypos->lnum); /* XXX */ - if (!cin_ends_in(get_cursor_line_ptr(), (char_u *)",", NULL)) + && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { + amount = get_indent_lnum(trypos->lnum); // XXX + } + if (!cin_ends_in(get_cursor_line_ptr(), (char_u *)",", NULL)) { amount += curbuf->b_ind_cpp_baseclass; + } } else { curwin->w_cursor.col = col; getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); @@ -1389,12 +1404,12 @@ static int cin_skip2pos(pos_T *trypos) * Return NULL if no match found. * Ignore a '{' that is in a comment, makes indenting the next three lines * work. */ -/* foo() */ -/* { */ -/* } */ +// foo() +// { +// } -static pos_T *find_start_brace(void) -{ /* XXX */ +static pos_T *find_start_brace(void) // XXX +{ pos_T cursor_save; pos_T *trypos; pos_T *pos; @@ -1402,11 +1417,11 @@ static pos_T *find_start_brace(void) cursor_save = curwin->w_cursor; while ((trypos = findmatchlimit(NULL, '{', FM_BLOCKSTOP, 0)) != NULL) { - pos_copy = *trypos; /* copy pos_T, next findmatch will change it */ + pos_copy = *trypos; // copy pos_T, next findmatch will change it trypos = &pos_copy; curwin->w_cursor = *trypos; pos = NULL; - /* ignore the { if it's in a // or / * * / comment */ + // ignore the { if it's in a // or / * * / comment if ((colnr_T)cin_skip2pos(trypos) == trypos->col && (pos = ind_find_start_CORS(NULL)) == NULL) { // XXX break; @@ -1449,7 +1464,7 @@ retry: } else { pos_T *trypos_wk; - pos_copy = *trypos; /* copy trypos, findmatch will change it */ + pos_copy = *trypos; // copy trypos, findmatch will change it trypos = &pos_copy; curwin->w_cursor = *trypos; if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) { // XXX @@ -1515,17 +1530,17 @@ static int find_last_paren(char_u *l, int start, int end) int retval = FALSE; int open_count = 0; - curwin->w_cursor.col = 0; /* default is start of line */ + curwin->w_cursor.col = 0; // default is start of line for (i = 0; l[i] != NUL; i++) { - i = (int)(cin_skipcomment(l + i) - l); /* ignore parens in comments */ - i = (int)(skip_string(l + i) - l); /* ignore parens in quotes */ - if (l[i] == start) - ++open_count; - else if (l[i] == end) { - if (open_count > 0) - --open_count; - else { + i = (int)(cin_skipcomment(l + i) - l); // ignore parens in comments + i = (int)(skip_string(l + i) - l); // ignore parens in quotes + if (l[i] == start) { + open_count++; + } else if (l[i] == end) { + if (open_count > 0) { + open_count--; + } else { curwin->w_cursor.col = i; retval = TRUE; } @@ -1561,7 +1576,7 @@ void parse_cino(buf_T *buf) * an opening brace. */ buf->b_ind_no_brace = 0; - /* Column where the first { of a function should be located }. */ + // Column where the first { of a function should be located }. buf->b_ind_first_open = 0; /* Spaces from the prevailing indent a leftmost open brace should be @@ -1581,26 +1596,26 @@ void parse_cino(buf_T *buf) * otherwise the jump label will be put to column 1. */ buf->b_ind_jump_label = -1; - /* Spaces from the switch() indent a "case xx" label should be located. */ + // Spaces from the switch() indent a "case xx" label should be located. buf->b_ind_case = sw; - /* Spaces from the "case xx:" code after a switch() should be located. */ + // Spaces from the "case xx:" code after a switch() should be located. buf->b_ind_case_code = sw; - /* Lineup break at end of case in switch() with case label. */ + // Lineup break at end of case in switch() with case label. buf->b_ind_case_break = 0; /* Spaces from the class declaration indent a scope declaration label * should be located. */ buf->b_ind_scopedecl = sw; - /* Spaces from the scope declaration label code should be located. */ + // Spaces from the scope declaration label code should be located. buf->b_ind_scopedecl_code = sw; - /* Amount K&R-style parameters should be indented. */ + // Amount K&R-style parameters should be indented. buf->b_ind_param = sw; - /* Amount a function type spec should be indented. */ + // Amount a function type spec should be indented. buf->b_ind_func_type = sw; /* Amount a cpp base class declaration or constructor initialization @@ -1611,7 +1626,7 @@ void parse_cino(buf_T *buf) * should be located. */ buf->b_ind_continuation = sw; - /* Spaces from the indent of the line with an unclosed parentheses. */ + // Spaces from the indent of the line with an unclosed parentheses. buf->b_ind_unclosed = sw * 2; /* Spaces from the indent of the line with an unclosed parentheses, which @@ -1635,35 +1650,35 @@ void parse_cino(buf_T *buf) * opening parentheses. */ buf->b_ind_matching_paren = 0; - /* Indent a closing parentheses under the previous line. */ + // Indent a closing parentheses under the previous line. buf->b_ind_paren_prev = 0; - /* Extra indent for comments. */ + // Extra indent for comments. buf->b_ind_comment = 0; - /* Spaces from the comment opener when there is nothing after it. */ + // Spaces from the comment opener when there is nothing after it. buf->b_ind_in_comment = 3; /* Boolean: if non-zero, use b_ind_in_comment even if there is something * after the comment opener. */ buf->b_ind_in_comment2 = 0; - /* Max lines to search for an open paren. */ + // Max lines to search for an open paren. buf->b_ind_maxparen = 20; - /* Max lines to search for an open comment. */ + // Max lines to search for an open comment. buf->b_ind_maxcomment = 70; - /* Handle braces for java code. */ + // Handle braces for java code. buf->b_ind_java = 0; - /* Not to confuse JS object properties with labels. */ + // Not to confuse JS object properties with labels. buf->b_ind_js = 0; - /* Handle blocked cases correctly. */ + // Handle blocked cases correctly. buf->b_ind_keep_case_label = 0; - /* Handle C++ namespace. */ + // Handle C++ namespace. buf->b_ind_cpp_namespace = 0; /* Handle continuation lines containing conditions of if(), for() and @@ -1777,9 +1792,9 @@ int get_c_indent(void) pos_T our_paren_pos; char_u *start; int start_brace; -#define BRACE_IN_COL0 1 /* '{' is in column 0 */ -#define BRACE_AT_START 2 /* '{' is at start of line */ -#define BRACE_AT_END 3 /* '{' is at end of line */ +#define BRACE_IN_COL0 1 // '{' is in column 0 +#define BRACE_AT_START 2 // '{' is at start of line +#define BRACE_AT_END 3 // '{' is at end of line linenr_T ourscope; char_u *l; char_u *look; @@ -1802,24 +1817,24 @@ int get_c_indent(void) int whilelevel; linenr_T lnum; int n; - int iscase; int lookfor_break; - int lookfor_cpp_namespace = FALSE; - int cont_amount = 0; /* amount for continuation line */ + bool lookfor_cpp_namespace = false; + int cont_amount = 0; // amount for continuation line int original_line_islabel; int added_to_amount = 0; linenr_T raw_string_start = 0; cpp_baseclass_cache_T cache_cpp_baseclass = { false, { MAXLNUM, 0 } }; - /* make a copy, value is changed below */ + // make a copy, value is changed below int ind_continuation = curbuf->b_ind_continuation; - /* remember where the cursor was when we started */ + // remember where the cursor was when we started cur_curpos = curwin->w_cursor; - /* if we are at line 1 zero indent is fine, right? */ - if (cur_curpos.lnum == 1) + // if we are at line 1 zero indent is fine, right? + if (cur_curpos.lnum == 1) { return 0; + } /* Get a copy of the current contents of the line. * This is required, because only the most recent line obtained with @@ -1840,11 +1855,11 @@ int get_c_indent(void) theline = skipwhite(linecopy); - /* move the cursor to the start of the line */ + // move the cursor to the start of the line curwin->w_cursor.col = 0; - original_line_islabel = cin_islabel(); /* XXX */ + original_line_islabel = cin_islabel(); // XXX /* * If we are inside a raw string don't change the indent. @@ -1852,7 +1867,7 @@ int get_c_indent(void) */ comment_pos = ind_find_start_comment(); if (comment_pos != NULL) { - /* findmatchlimit() static pos is overwritten, make a copy */ + // findmatchlimit() static pos is overwritten, make a copy tryposCopy = *comment_pos; comment_pos = &tryposCopy; } @@ -1887,8 +1902,8 @@ int get_c_indent(void) * previous line, lineup with that one. */ if (cin_islinecomment(theline) - && (trypos = find_line_comment()) != NULL) { /* XXX */ - /* find how indented the line beginning the comment is */ + && (trypos = find_line_comment()) != NULL) { // XXX + // find how indented the line beginning the comment is getvcol(curwin, trypos, &col, NULL, NULL); amount = col; goto theend; @@ -1897,18 +1912,18 @@ int get_c_indent(void) * If we're inside a comment and not looking at the start of the * comment, try using the 'comments' option. */ - if (!cin_iscomment(theline) && comment_pos != NULL) { /* XXX */ + if (!cin_iscomment(theline) && comment_pos != NULL) { // XXX int lead_start_len = 2; int lead_middle_len = 1; - char_u lead_start[COM_MAX_LEN]; /* start-comment string */ - char_u lead_middle[COM_MAX_LEN]; /* middle-comment string */ - char_u lead_end[COM_MAX_LEN]; /* end-comment string */ + char_u lead_start[COM_MAX_LEN]; // start-comment string + char_u lead_middle[COM_MAX_LEN]; // middle-comment string + char_u lead_end[COM_MAX_LEN]; // end-comment string char_u *p; int start_align = 0; int start_off = 0; int done = FALSE; - /* find how indented the line beginning the comment is */ + // find how indented the line beginning the comment is getvcol(curwin, comment_pos, &col, NULL, NULL); amount = col; *lead_start = NUL; @@ -1981,13 +1996,13 @@ int get_c_indent(void) if (STRNCMP(theline, lead_middle, lead_middle_len) != 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); - /* XXX */ - if (off != 0) + // XXX + if (off != 0) { amount += off; - else if (align == COM_RIGHT) - amount += vim_strsize(lead_start) - - vim_strsize(lead_middle); - done = TRUE; + } else if (align == COM_RIGHT) { + amount += vim_strsize(lead_start) - vim_strsize(lead_middle); + } + done = true; break; } } @@ -2010,18 +2025,20 @@ int get_c_indent(void) * otherwise, add the amount specified by "c" in 'cino' */ amount = -1; - for (lnum = cur_curpos.lnum - 1; lnum > comment_pos->lnum; --lnum) { - if (linewhite(lnum)) /* skip blank lines */ + for (lnum = cur_curpos.lnum - 1; lnum > comment_pos->lnum; lnum--) { + if (linewhite(lnum)) { // skip blank lines continue; - amount = get_indent_lnum(lnum); /* XXX */ + } + amount = get_indent_lnum(lnum); // XXX break; } - if (amount == -1) { /* use the comment opener */ + if (amount == -1) { // use the comment opener if (!curbuf->b_ind_in_comment2) { - start = ml_get(comment_pos->lnum); - look = start + comment_pos->col + 2; /* skip / and * */ - if (*look != NUL) /* if something after it */ - comment_pos->col = (colnr_T)(skipwhite(look) - start); + start = ml_get(comment_pos->lnum); + look = start + comment_pos->col + 2; // skip / and * + if (*look != NUL) { // if something after it + comment_pos->col = (colnr_T)(skipwhite(look) - start); + } } getvcol(curwin, comment_pos, &col, NULL, NULL); amount = col; @@ -2038,9 +2055,8 @@ int get_c_indent(void) amount = get_indent_lnum(trypos->lnum); goto theend; } - /* - * Are we inside parentheses or braces? - */ /* XXX */ + // Are we inside parentheses or braces? + // XXX if (((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL && curbuf->b_ind_java == 0) || (tryposBrace = find_start_brace()) != NULL @@ -2063,8 +2079,8 @@ int get_c_indent(void) * a previous non-empty line that matches the same paren. */ if (theline[0] == ')' && curbuf->b_ind_paren_prev) { - /* Line up with the start of the matching paren line. */ - amount = get_indent_lnum(curwin->w_cursor.lnum - 1); /* XXX */ + // Line up with the start of the matching paren line. + amount = get_indent_lnum(curwin->w_cursor.lnum - 1); // XXX } else { amount = -1; for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum) { @@ -2083,12 +2099,12 @@ int get_c_indent(void) continue; } - /* XXX */ + // XXX if ((trypos = find_match_paren( corr_ind_maxparen(&cur_curpos))) != NULL && trypos->lnum == our_paren_pos.lnum && trypos->col == our_paren_pos.col) { - amount = get_indent_lnum(lnum); /* XXX */ + amount = get_indent_lnum(lnum); // XXX if (theline[0] == ')') { if (our_paren_pos.lnum != lnum @@ -2200,10 +2216,11 @@ int get_c_indent(void) col = our_paren_pos.col + 1; while (ascii_iswhite(l[col])) col++; - if (l[col] != NUL) /* In case of trailing space */ + if (l[col] != NUL) { // In case of trailing space our_paren_pos.col = col; - else + } else { our_paren_pos.col++; + } } } @@ -2219,7 +2236,7 @@ int get_c_indent(void) } if (theline[0] == ')' && curbuf->b_ind_matching_paren) { - /* Line up with the start of the matching paren line. */ + // Line up with the start of the matching paren line. } else if ((curbuf->b_ind_unclosed == 0 && is_if_for_while == 0) || (!curbuf->b_ind_unclosed_noignore && *look == '(' && ignore_paren_col == 0)) { @@ -2271,9 +2288,10 @@ int get_c_indent(void) } } - /* add extra indent for a comment */ - if (cin_iscomment(theline)) + // add extra indent for a comment + if (cin_iscomment(theline)) { amount += curbuf->b_ind_comment; + } } else { // We are inside braces, there is a { before this line at the position // stored in tryposBrace. @@ -2317,7 +2335,7 @@ int get_c_indent(void) // ldfd) { // } if ((curbuf->b_ind_js || curbuf->b_ind_keep_case_label) - && cin_iscase(skipwhite(get_cursor_line_ptr()), FALSE)) { + && cin_iscase(skipwhite(get_cursor_line_ptr()), false)) { amount = get_indent(); } else if (curbuf->b_ind_js) { amount = get_indent_lnum(lnum); @@ -2348,14 +2366,15 @@ int get_c_indent(void) * to match it with. */ lookfor = LOOKFOR_INITIAL; - if (cin_iselse(theline)) + if (cin_iselse(theline)) { lookfor = LOOKFOR_IF; - else if (cin_iswhileofdo(theline, cur_curpos.lnum)) /* XXX */ + } else if (cin_iswhileofdo(theline, cur_curpos.lnum)) { // XXX lookfor = LOOKFOR_DO; + } if (lookfor != LOOKFOR_INITIAL) { curwin->w_cursor.lnum = cur_curpos.lnum; if (find_match(lookfor, ourscope) == OK) { - amount = get_indent(); /* XXX */ + amount = get_indent(); // XXX goto theend; } } @@ -2390,7 +2409,7 @@ int get_c_indent(void) amount += curbuf->b_ind_cpp_extern_c; } } else { - /* Compensate for adding b_ind_open_extra later. */ + // Compensate for adding b_ind_open_extra later. amount -= curbuf->b_ind_open_extra; if (amount < 0) amount = 0; @@ -2399,19 +2418,20 @@ int get_c_indent(void) lookfor_break = FALSE; - if (cin_iscase(theline, FALSE)) { /* it's a switch() label */ - lookfor = LOOKFOR_CASE; /* find a previous switch() label */ + if (cin_iscase(theline, false)) { // it's a switch() label + lookfor = LOOKFOR_CASE; // find a previous switch() label amount += curbuf->b_ind_case; - } else if (cin_isscopedecl(theline)) { /* private:, ... */ - lookfor = LOOKFOR_SCOPEDECL; /* class decl is this block */ + } else if (cin_isscopedecl(theline)) { // private:, ... + lookfor = LOOKFOR_SCOPEDECL; // class decl is this block amount += curbuf->b_ind_scopedecl; } else { - if (curbuf->b_ind_case_break && cin_isbreak(theline)) - /* break; ... */ - lookfor_break = TRUE; + if (curbuf->b_ind_case_break && cin_isbreak(theline)) { + // break; ... + lookfor_break = true; + } lookfor = LOOKFOR_INITIAL; - /* b_ind_level from start of block */ + // b_ind_level from start of block amount += curbuf->b_ind_level; } scope_amount = amount; @@ -2503,16 +2523,17 @@ int get_c_indent(void) if (terminated != ';' && cin_isinit()) break; - /* nothing useful found */ - if (terminated == 0 || terminated == '{') + // nothing useful found + if (terminated == 0 || terminated == '{') { continue; + } } if (terminated != ';') { - /* Skip parens and braces. Position the cursor - * over the rightmost paren, so that matching it - * will take us back to the start of the line. - */ /* XXX */ + // Skip parens and braces. Position the cursor + // over the rightmost paren, so that matching it + // will take us back to the start of the line. + // XXX trypos = NULL; if (find_last_paren(l, '(', ')')) trypos = find_match_paren( @@ -2582,7 +2603,7 @@ int get_c_indent(void) continue; } - /* Finally the actual check for "namespace". */ + // Finally the actual check for "namespace". if (cin_is_cpp_namespace(l)) { amount += curbuf->b_ind_cpp_namespace - added_to_amount; @@ -2614,7 +2635,7 @@ int get_c_indent(void) * If this is a switch() label, may line up relative to that. * If this is a C++ scope declaration, do the same. */ - iscase = cin_iscase(l, FALSE); + bool iscase = cin_iscase(l, false); if (iscase || cin_isscopedecl(l)) { /* we are only looking for cpp base class * declaration/initialization any longer */ @@ -2640,27 +2661,24 @@ int get_c_indent(void) break; } - /* - * case xx: <- line up with this case - * x = 333; - * case yy: - */ - if ( (iscase && lookfor == LOOKFOR_CASE) - || (iscase && lookfor_break) - || (!iscase && lookfor == LOOKFOR_SCOPEDECL)) { - /* - * Check that this case label is not for another - * switch() - */ /* XXX */ + // case xx: <- line up with this case + // x = 333; + // case yy: + if ((iscase && lookfor == LOOKFOR_CASE) + || (iscase && lookfor_break) + || (!iscase && lookfor == LOOKFOR_SCOPEDECL)) { + // Check that this case label is not for another + // switch() + // XXX if ((trypos = find_start_brace()) == NULL || trypos->lnum == ourscope) { - amount = get_indent(); /* XXX */ + amount = get_indent(); // XXX break; } continue; } - n = get_indent_nolabel(curwin->w_cursor.lnum); /* XXX */ + n = get_indent_nolabel(curwin->w_cursor.lnum); // XXX /* * case xx: if (cond) <- line up with this if @@ -2708,7 +2726,7 @@ int get_c_indent(void) * case xx: * -> y = 1; */ - scope_amount = get_indent() + (iscase /* XXX */ + scope_amount = get_indent() + (iscase // XXX ? curbuf->b_ind_case_code : curbuf->b_ind_scopedecl_code); lookfor = curbuf->b_ind_case_break @@ -2750,11 +2768,10 @@ int get_c_indent(void) continue; } - /* - * Are we at the start of a cpp base class declaration or - * constructor initialization? - */ /* XXX */ - n = FALSE; + // Are we at the start of a cpp base class declaration or + // constructor initialization? + // XXX + n = 0; if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) { n = cin_is_cpp_baseclass(&cache_cpp_baseclass); l = get_cursor_line_ptr(); @@ -2766,13 +2783,14 @@ int get_c_indent(void) else amount += ind_continuation; } else if (theline[0] == '{') { - /* Need to find start of the declaration. */ + // Need to find start of the declaration. lookfor = LOOKFOR_UNTERM; ind_continuation = 0; continue; - } else - /* XXX */ + } else { + // XXX amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col); + } break; } else if (lookfor == LOOKFOR_CPP_BASECLASS) { /* only look, whether there is a cpp base class @@ -2871,8 +2889,8 @@ int get_c_indent(void) */ curwin->w_cursor = *trypos; l = get_cursor_line_ptr(); - if (cin_iscase(l, FALSE) || cin_isscopedecl(l)) { - ++curwin->w_cursor.lnum; + if (cin_iscase(l, false) || cin_isscopedecl(l)) { + curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; continue; } @@ -3025,9 +3043,10 @@ int get_c_indent(void) * -> here; */ if (lookfor == LOOKFOR_UNTERM) { - /* When line ends in a comma add extra indent */ - if (terminated == ',') + // When line ends in a comma add extra indent + if (terminated == ',') { amount += ind_continuation; + } break; } @@ -3144,9 +3163,10 @@ int get_c_indent(void) if (whilelevel == 0) { lookfor = LOOKFOR_TERM; - amount = get_indent(); /* XXX */ - if (theline[0] == '{') + amount = get_indent(); // XXX + if (theline[0] == '{') { amount += curbuf->b_ind_open_extra; + } } ++whilelevel; } @@ -3174,8 +3194,8 @@ int get_c_indent(void) if (whilelevel > 0) { l = cin_skipcomment(get_cursor_line_ptr()); if (cin_isdo(l)) { - amount = get_indent(); /* XXX */ - --whilelevel; + amount = get_indent(); // XXX + whilelevel--; continue; } } @@ -3240,8 +3260,8 @@ term_again: */ curwin->w_cursor = *trypos; l = get_cursor_line_ptr(); - if (cin_iscase(l, FALSE) || cin_isscopedecl(l)) { - ++curwin->w_cursor.lnum; + if (cin_iscase(l, false) || cin_isscopedecl(l)) { + curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; continue; } @@ -3256,8 +3276,7 @@ term_again: * stat; * } */ - iscase = (curbuf->b_ind_keep_case_label - && cin_iscase(l, FALSE)); + iscase = curbuf->b_ind_keep_case_label && cin_iscase(l, false); /* * Get indent and pointer to text for current line, @@ -3267,7 +3286,7 @@ term_again: if (theline[0] == '{') amount += curbuf->b_ind_open_extra; - /* See remark above: "Only add b_ind_open_extra.." */ + // See remark above: "Only add b_ind_open_extra.." l = skipwhite(l); if (*l == '{') amount -= curbuf->b_ind_open_extra; @@ -3297,11 +3316,11 @@ term_again: * that block. */ l = get_cursor_line_ptr(); - if (find_last_paren(l, '{', '}') /* XXX */ + if (find_last_paren(l, '{', '}') // XXX && (trypos = find_start_brace()) != NULL) { curwin->w_cursor = *trypos; - /* if not "else {" check for terminated again */ - /* but skip block for "} else {" */ + // if not "else {" check for terminated again + // but skip block for "} else {" l = cin_skipcomment(get_cursor_line_ptr()); if (*l == '}' || !cin_iselse(l)) goto term_again; @@ -3314,13 +3333,14 @@ term_again: } } - /* add extra indent for a comment */ - if (cin_iscomment(theline)) + // add extra indent for a comment + if (cin_iscomment(theline)) { amount += curbuf->b_ind_comment; - - /* subtract extra left-shift for jump labels */ - if (curbuf->b_ind_jump_label > 0 && original_line_islabel) + } + // subtract extra left-shift for jump labels + if (curbuf->b_ind_jump_label > 0 && original_line_islabel) { amount -= curbuf->b_ind_jump_label; + } goto theend; } @@ -3360,7 +3380,7 @@ term_again: goto theend; } - /* search backwards until we find something we recognize */ + // search backwards until we find something we recognize amount = 0; curwin->w_cursor = cur_curpos; while (curwin->w_cursor.lnum > 1) { @@ -3386,7 +3406,7 @@ term_again: l = get_cursor_line_ptr(); } if (n) { - /* XXX */ + // XXX amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col); break; } @@ -3415,11 +3435,11 @@ term_again: */ if (cin_ends_in(l, (char_u *)",", NULL) || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\')) { - /* take us back to opening paren */ + // take us back to opening paren if (find_last_paren(l, '(', ')') - && (trypos = find_match_paren( - curbuf->b_ind_maxparen)) != NULL) + && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { curwin->w_cursor = *trypos; + } /* For a line ending in ',' that is a continuation line go * back to the first line with a backslash: @@ -3435,7 +3455,7 @@ term_again: curwin->w_cursor.col = 0; } - amount = get_indent(); /* XXX */ + amount = get_indent(); // XXX if (amount == 0) amount = cin_first_id_amount(); @@ -3448,8 +3468,9 @@ term_again: * If the line looks like a function declaration, and we're * not in a comment, put it the left margin. */ - if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) /* XXX */ + if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) { // XXX break; + } l = get_cursor_line_ptr(); /* @@ -3535,13 +3556,14 @@ term_again: if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) curwin->w_cursor = *trypos; - amount = get_indent(); /* XXX */ + amount = get_indent(); // XXX break; } - /* add extra indent for a comment */ - if (cin_iscomment(theline)) + // add extra indent for a comment + if (cin_iscomment(theline)) { amount += curbuf->b_ind_comment; + } /* add extra indent if the previous line ended in a backslash: * "asdfasdf\ @@ -3565,7 +3587,7 @@ theend: amount = 0; laterend: - /* put the cursor back where it belongs */ + // put the cursor back where it belongs curwin->w_cursor = cur_curpos; xfree(linecopy); @@ -3598,7 +3620,7 @@ static int find_match(int lookfor, linenr_T ourscope) look = cin_skipcomment(get_cursor_line_ptr()); if (!cin_iselse(look) && !cin_isif(look) - && !cin_isdo(look) /* XXX */ + && !cin_isdo(look) // XXX && !cin_iswhileofdo(look, curwin->w_cursor.lnum)) { continue; } @@ -3607,9 +3629,10 @@ static int find_match(int lookfor, linenr_T ourscope) * if we've gone outside the braces entirely, * we must be out of scope... */ - theirscope = find_start_brace(); /* XXX */ - if (theirscope == NULL) + theirscope = find_start_brace(); // XXX + if (theirscope == NULL) { break; + } /* * and if the brace enclosing this is further @@ -3649,7 +3672,7 @@ static int find_match(int lookfor, linenr_T ourscope) continue; } - /* If it's an "if" decrement elselevel */ + // If it's an "if" decrement elselevel look = cin_skipcomment(get_cursor_line_ptr()); if (cin_isif(look)) { elselevel--; @@ -3661,9 +3684,10 @@ static int find_match(int lookfor, linenr_T ourscope) whilelevel = 0; } - /* If it's a "do" decrement whilelevel */ - if (cin_isdo(look)) + // If it's a "do" decrement whilelevel + if (cin_isdo(look)) { whilelevel--; + } /* * if we've used up all the elses, then diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e5de57ceaa..2d351f4dba 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1079,13 +1079,15 @@ do_execreg( } } escaped = vim_strsave_escape_csi(reg->y_array[i]); - retval = ins_typebuf(escaped, remap, 0, TRUE, silent); + retval = ins_typebuf(escaped, remap, 0, true, silent); xfree(escaped); - if (retval == FAIL) + if (retval == FAIL) { return FAIL; - if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) - == FAIL) + } + if (colon + && ins_typebuf((char_u *)":", remap, 0, true, silent) == FAIL) { return FAIL; + } } reg_executing = regname == 0 ? '"' : regname; // disable the 'q' command } @@ -1109,8 +1111,9 @@ static void put_reedit_in_typebuf(int silent) buf[0] = (char_u)(restart_edit == 'I' ? 'i' : restart_edit); buf[1] = NUL; } - if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) + if (ins_typebuf(buf, REMAP_NONE, 0, true, silent) == OK) { restart_edit = NUL; + } } } @@ -1130,25 +1133,29 @@ static int put_in_typebuf( int retval = OK; put_reedit_in_typebuf(silent); - if (colon) - retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); + if (colon) { + retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, true, silent); + } if (retval == OK) { char_u *p; - if (esc) + if (esc) { p = vim_strsave_escape_csi(s); - else + } else { p = s; - if (p == NULL) + } + if (p == NULL) { retval = FAIL; - else - retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, - 0, TRUE, silent); - if (esc) + } else { + retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, 0, true, silent); + } + if (esc) { xfree(p); + } + } + if (colon && retval == OK) { + retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, true, silent); } - if (colon && retval == OK) - retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); return retval; } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 47f0eec0b8..16749ba86b 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -165,8 +165,8 @@ enum { SHM_WRI = 'w', ///< "[w]" instead of "written". SHM_ABBREVIATIONS = 'a', ///< Use abbreviations from #SHM_ALL_ABBREVIATIONS. SHM_WRITE = 'W', ///< Don't use "written" at all. - SHM_TRUNC = 't', ///< Trunctate file messages. - SHM_TRUNCALL = 'T', ///< Trunctate all messages. + SHM_TRUNC = 't', ///< Truncate file messages. + SHM_TRUNCALL = 'T', ///< Truncate all messages. SHM_OVER = 'o', ///< Overwrite file messages. SHM_OVERALL = 'O', ///< Overwrite more messages. SHM_SEARCH = 's', ///< No search hit bottom messages. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index b5d890bf52..2974245857 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -123,7 +123,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, int shell_style = STYLE_ECHO; int check_spaces; static bool did_find_nul = false; - bool ampersent = false; + bool ampersand = false; // vimglob() function to define for Posix shell static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; @@ -245,7 +245,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, p--; } if (*p == '&') { // remove trailing '&' - ampersent = true; + ampersand = true; *p = ' '; } STRCAT(command, ">"); @@ -309,7 +309,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, shellopts |= kShellOptHideMess; } - if (ampersent) { + if (ampersand) { STRCAT(command, "&"); // put the '&' after the redirection } @@ -331,7 +331,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, // When running in the background, give it some time to create the temp // file, but don't wait for it to finish. - if (ampersent) { + if (ampersand) { os_delay(10L, true); } diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 68abf57413..32c9750628 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -398,7 +398,7 @@ void pum_redraw(void) char_u *p = NULL; int totwidth, width, w; int thumb_pos = 0; - int thumb_heigth = 1; + int thumb_height = 1; int round; int n; @@ -449,11 +449,11 @@ void pum_redraw(void) } if (pum_scrollbar) { - thumb_heigth = pum_height * pum_height / pum_size; - if (thumb_heigth == 0) { - thumb_heigth = 1; + thumb_height = pum_height * pum_height / pum_size; + if (thumb_height == 0) { + thumb_height = 1; } - thumb_pos = (pum_first * (pum_height - thumb_heigth) + thumb_pos = (pum_first * (pum_height - thumb_height) + (pum_size - pum_height) / 2) / (pum_size - pum_height); } @@ -616,11 +616,11 @@ void pum_redraw(void) if (pum_scrollbar > 0) { if (pum_rl) { grid_putchar(&pum_grid, ' ', row, col_off - pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth + i >= thumb_pos && i < thumb_pos + thumb_height ? attr_thumb : attr_scroll); } else { grid_putchar(&pum_grid, ' ', row, col_off + pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth + i >= thumb_pos && i < thumb_pos + thumb_height ? attr_thumb : attr_scroll); } } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a2589ac431..d7693c7a6f 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -5895,7 +5895,7 @@ static void regdump(char_u *pattern, bt_regprog_T *r) fprintf(f, " count %" PRId64, (int64_t)OPERAND_MIN(s)); s += 4; } else if (op == RE_LNUM || op == RE_COL || op == RE_VCOL) { - /* one int plus comperator */ + // one int plus comparator fprintf(f, " count %" PRId64, (int64_t)OPERAND_MIN(s)); s += 5; } @@ -7139,6 +7139,7 @@ list_T *reg_submatch_list(int no) tv_list_append_string(list, s, (const char *)rsm.sm_match->endp[no] - s); } + tv_list_ref(list); return list; } diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 8b5ee59d40..b6bcee3fda 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -559,7 +559,9 @@ static char_u *nfa_get_match_text(nfa_state_T *start) */ static void realloc_post_list(void) { - size_t new_max = (post_end - post_start) + 1000; + // For weird patterns the number of states can be very high. Increasing by + // 50% seems a reasonable compromise between memory use and speed. + const size_t new_max = (post_end - post_start) * 3 / 2; int *new_start = xrealloc(post_start, new_max * sizeof(int)); post_ptr = new_start + (post_ptr - post_start); post_end = new_start + new_max; diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index b760828458..4641408069 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -31,14 +31,11 @@ endif SCRIPTS ?= $(SCRIPTS_DEFAULT) # Tests using runtest.vim. -NEW_TESTS_ALOT := test_alot_utf8 test_alot +NEW_TESTS_ALOT := test_alot_utf8 test_alot test_alot_latin NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(addsuffix .vim,$(NEW_TESTS_ALOT))) -NEW_TESTS_IN_ALOT_LATIN := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' test_alot_latin.vim) # Ignored tests. -# test_alot_latin: Nvim does not allow setting encoding. # test_largefile: uses too much resources to run on CI. NEW_TESTS_IGNORE := \ - test_alot_latin $(NEW_TESTS_IN_ALOT_LATIN) \ test_largefile \ NEW_TESTS := $(sort $(basename $(notdir $(wildcard test_*.vim)))) diff --git a/src/nvim/testdir/test_alot_latin.vim b/src/nvim/testdir/test_alot_latin.vim index ebb3bde4ce..23a404cac1 100644 --- a/src/nvim/testdir/test_alot_latin.vim +++ b/src/nvim/testdir/test_alot_latin.vim @@ -4,7 +4,4 @@ " These tests use latin1 'encoding'. Setting 'encoding' is in the individual " files, so that they can be run by themselves. -" Nvim does not allow setting 'encoding', so skip this test group. -finish - source test_regexp_latin.vim diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index b4f7478807..1d114221dc 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -52,6 +52,37 @@ func Test_assert_fails_in_try_block() endtry endfunc +func Test_assert_inrange() + call assert_equal(0, assert_inrange(7, 7, 7)) + call assert_equal(0, assert_inrange(5, 7, 5)) + call assert_equal(0, assert_inrange(5, 7, 6)) + call assert_equal(0, assert_inrange(5, 7, 7)) + call assert_equal(1, assert_inrange(5, 7, 4)) + call assert_match("Expected range 5 - 7, but got 4", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_inrange(5, 7, 8)) + call assert_match("Expected range 5 - 7, but got 8", v:errors[0]) + call remove(v:errors, 0) + + call assert_fails('call assert_inrange(1, 1)', 'E119:') + + if has('float') + call assert_equal(0, assert_inrange(7.0, 7, 7)) + call assert_equal(0, assert_inrange(7, 7.0, 7)) + call assert_equal(0, assert_inrange(7, 7, 7.0)) + call assert_equal(0, assert_inrange(5, 7, 5.0)) + call assert_equal(0, assert_inrange(5, 7, 6.0)) + call assert_equal(0, assert_inrange(5, 7, 7.0)) + + call assert_equal(1, assert_inrange(5, 7, 4.0)) + call assert_match("Expected range 5.0 - 7.0, but got 4.0", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_inrange(5, 7, 8.0)) + call assert_match("Expected range 5.0 - 7.0, but got 8.0", v:errors[0]) + call remove(v:errors, 0) + endif +endfunc + " Must be last. func Test_zz_quit_detected() " Verify that if a test function ends Vim the test script detects this. diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 1bb2ee53de..cacdd68d10 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -1,5 +1,5 @@ " Tests for regexp in latin1 encoding -set encoding=latin1 +" set encoding=latin1 scriptencoding latin1 func s:equivalence_test() @@ -22,11 +22,13 @@ func s:equivalence_test() endfunc func Test_equivalence_re1() + throw 'skipped: Nvim does not support enc=latin1' set re=1 call s:equivalence_test() endfunc func Test_equivalence_re2() + throw 'skipped: Nvim does not support enc=latin1' set re=2 call s:equivalence_test() endfunc @@ -39,6 +41,17 @@ func Test_range_with_newline() bwipe! endfunc +func Test_pattern_compile_speed() + if !exists('+spellcapcheck') || !has('reltime') + return + endif + let start = reltime() + " this used to be very slow, not it should be about a second + set spc=\\v(((((Nxxxxxxx&&xxxx){179})+)+)+){179} + call assert_inrange(0.01, 10.0, reltimefloat(reltime(start))) + set spc= +endfunc + func Test_get_equi_class() new " Incomplete equivalence class caused invalid memory access @@ -87,6 +100,7 @@ func Test_multi_failure() endfunc func Test_recursive_addstate() + throw 'skipped: TODO: ' " This will call addstate() recursively until it runs into the limit. let lnum = search('\v((){328}){389}') call assert_equal(0, lnum) diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 2a27f7a3a1..cc3bfe9f7f 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -746,3 +746,12 @@ func Test_sub_beyond_end() call assert_equal('#', getline(1)) bwipe! endfunc + +func Test_submatch_list_concatenate() + let pat = 'A\(.\)' + let Rep = {-> string([submatch(0, 1)] + [[submatch(1)]])} + " call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]") + call assert_equal(substitute('A1', pat, Rep, ''), "[['A1'], ['1']]") +endfunc + +" vim: shiftwidth=2 sts=2 expandtab |