diff options
-rw-r--r-- | runtime/doc/editing.txt | 3 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 23 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 1 | ||||
-rw-r--r-- | runtime/plugin/matchparen.vim | 4 | ||||
-rw-r--r-- | src/nvim/eval.c | 51 | ||||
-rw-r--r-- | src/nvim/fileio.c | 20 | ||||
-rw-r--r-- | src/nvim/message.c | 23 | ||||
-rw-r--r-- | src/nvim/misc1.c | 5 | ||||
-rw-r--r-- | src/nvim/normal.c | 10 | ||||
-rw-r--r-- | src/nvim/ops.c | 184 | ||||
-rw-r--r-- | src/nvim/os/win_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/path.c | 23 | ||||
-rw-r--r-- | src/nvim/screen.c | 8 | ||||
-rw-r--r-- | src/nvim/version.c | 14 | ||||
-rw-r--r-- | test/functional/ex_cmds/cd_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/legacy/wordcount_spec.lua | 167 | ||||
-rw-r--r-- | test/unit/tempfile_spec.lua | 3 |
17 files changed, 417 insertions, 136 deletions
diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index 0ad917006f..b1dd3239ea 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -77,7 +77,8 @@ g CTRL-G Prints the current position of the cursor in five than one position on the screen (<Tab> or special character), both the "real" column and the screen column are shown, separated with a dash. - See also 'ruler' option. + Also see the 'ruler' option and the |wordcount()| + function. *v_g_CTRL-G* {Visual}g CTRL-G Similar to "g CTRL-G", but Word, Character, Line, and diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 1990cf735d..6ae137a6ce 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2140,6 +2140,7 @@ winrestcmd() String returns command to restore window sizes winrestview( {dict}) none restore view of current window winsaveview() Dict save view of current window winwidth( {nr}) Number width of window {nr} +wordcount() Dict get byte/char/word statistics writefile( {list}, {fname} [, {flags}]) Number write list of lines to file {fname} xor( {expr}, {expr}) Number bitwise XOR @@ -7122,6 +7123,28 @@ winwidth({nr}) *winwidth()* : exe "normal 50\<C-W>|" :endif < +wordcount() *wordcount()* + The result is a dictionary of byte/chars/word statistics for + the current buffer. This is the same info as provided by + |g_CTRL-G| + The return value includes: + bytes Number of bytes in the buffer + chars Number of chars in the buffer + words Number of words in the buffer + cursor_bytes Number of bytes before cursor position + (not in Visual mode) + cursor_chars Number of chars before cursor position + (not in Visual mode) + cursor_words Number of words before cursor position + (not in Visual mode) + visual_bytes Number of bytes visually selected + (only in Visual mode) + visual_chars Number of chars visually selected + (only in Visual mode) + visual_words Number of chars visually selected + (only in Visual mode) + + *writefile()* writefile({list}, {fname} [, {flags}]) Write |List| {list} to file {fname}. Each list item is diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 8017b99f97..fc8419a522 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -921,6 +921,7 @@ Various: *various-functions* py3eval() evaluate Python expression (|+python3|) pyeval() evaluate Python expression (|+python|) + wordcount() get byte/word/char count of buffer ============================================================================== *41.7* Defining a function diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim index 2a5a16a57e..873302efee 100644 --- a/runtime/plugin/matchparen.vim +++ b/runtime/plugin/matchparen.vim @@ -1,6 +1,6 @@ " Vim plugin for showing matching parens " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2014 Jul 19 +" Last Change: 2015 Dec 31 " Exit quickly when: " - this plugin was already loaded (or disabled) @@ -55,7 +55,7 @@ function! s:Highlight_Matching_Pair() let before = 0 let text = getline(c_lnum) - let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\)') + let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\=\)') if empty(matches) let [c_before, c] = ['', ''] else diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 16a96ba29e..6e9f89bbb5 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6950,6 +6950,7 @@ static struct fst { { "winrestview", 1, 1, f_winrestview }, { "winsaveview", 0, 0, f_winsaveview }, { "winwidth", 1, 1, f_winwidth }, + { "wordcount", 0, 0, f_wordcount }, { "writefile", 2, 3, f_writefile }, { "xor", 2, 2, f_xor }, }; @@ -8338,6 +8339,7 @@ static void f_cursor(typval_T *argvars, typval_T *rettv) { long line, col; long coladd = 0; + bool set_curswant = true; rettv->vval.v_number = -1; if (argvars[1].v_type == VAR_UNKNOWN) { @@ -8354,30 +8356,35 @@ static void f_cursor(typval_T *argvars, typval_T *rettv) coladd = pos.coladd; if (curswant >= 0) { curwin->w_curswant = curswant - 1; + set_curswant = false; } } else { line = get_tv_lnum(argvars); col = get_tv_number_chk(&argvars[1], NULL); - if (argvars[2].v_type != VAR_UNKNOWN) + if (argvars[2].v_type != VAR_UNKNOWN) { coladd = get_tv_number_chk(&argvars[2], NULL); + } } if (line < 0 || col < 0 - || coladd < 0 - ) - return; /* type error; errmsg already given */ - if (line > 0) + || coladd < 0) { + return; // type error; errmsg already given + } + if (line > 0) { curwin->w_cursor.lnum = line; - if (col > 0) + } + if (col > 0) { curwin->w_cursor.col = col - 1; + } curwin->w_cursor.coladd = coladd; - /* Make sure the cursor is in a valid position. */ + // Make sure the cursor is in a valid position. check_cursor(); - /* Correct cursor for multi-byte character. */ - if (has_mbyte) + // Correct cursor for multi-byte character. + if (has_mbyte) { mb_adjust_cursor(); + } - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = set_curswant; rettv->vval.v_number = 0; } @@ -14683,25 +14690,30 @@ static void f_setpos(typval_T *argvars, typval_T *rettv) name = get_tv_string_chk(argvars); if (name != NULL) { if (list2fpos(&argvars[1], &pos, &fnum, &curswant) == OK) { - if (--pos.col < 0) + if (--pos.col < 0) { pos.col = 0; + } if (name[0] == '.' && name[1] == NUL) { - /* set cursor */ + // set cursor if (fnum == curbuf->b_fnum) { curwin->w_cursor = pos; if (curswant >= 0) { curwin->w_curswant = curswant - 1; + curwin->w_set_curswant = false; } check_cursor(); rettv->vval.v_number = 0; - } else + } else { EMSG(_(e_invarg)); + } } else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) { - /* set mark */ - if (setmark_pos(name[1], &pos, fnum) == OK) + // set mark + if (setmark_pos(name[1], &pos, fnum) == OK) { rettv->vval.v_number = 0; - } else + } + } else { EMSG(_(e_invarg)); + } } } } @@ -16926,6 +16938,13 @@ static void f_winwidth(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = wp->w_width; } +/// "wordcount()" function +static void f_wordcount(typval_T *argvars, typval_T *rettv) +{ + rettv_dict_alloc(rettv); + cursor_pos_info(rettv->vval.v_dict); +} + /// "writefile()" function static void f_writefile(typval_T *argvars, typval_T *rettv) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 6c0bc59d93..db1469db97 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5097,19 +5097,23 @@ void write_lnum_adjust(linenr_T offset) } #if defined(BACKSLASH_IN_FILENAME) -/* - * Convert all backslashes in fname to forward slashes in-place. - */ +/// Convert all backslashes in fname to forward slashes in-place, +/// unless when it looks like a URL. void forward_slash(char_u *fname) { char_u *p; - for (p = fname; *p != NUL; ++p) - /* The Big5 encoding can have '\' in the trail byte. */ - if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) - ++p; - else if (*p == '\\') + if (path_with_url(fname)) { + return; + } + for (p = fname; *p != NUL; p++) { + // The Big5 encoding can have '\' in the trail byte. + if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) { + p++; + } else if (*p == '\\') { *p = '/'; + } + } } #endif diff --git a/src/nvim/message.c b/src/nvim/message.c index f60b128712..265f8c00c0 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -467,22 +467,23 @@ int emsg(char_u *s) { int attr; char_u *p; - int ignore = FALSE; + int ignore = false; int severe; - /* Skip this if not giving error messages at the moment. */ - if (emsg_not_now()) - return TRUE; + // Skip this if not giving error messages at the moment. + if (emsg_not_now()) { + return true; + } - called_emsg = TRUE; - ex_exitval = 1; + called_emsg = true; + if (emsg_silent == 0) { + ex_exitval = 1; + } - /* - * If "emsg_severe" is TRUE: When an error exception is to be thrown, - * prefer this message over previous messages for the same command. - */ + // If "emsg_severe" is TRUE: When an error exception is to be thrown, + // prefer this message over previous messages for the same command. severe = emsg_severe; - emsg_severe = FALSE; + emsg_severe = false; if (!emsg_off || vim_strchr(p_debug, 't') != NULL) { /* diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 53eceaa4ef..48791384a6 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1777,6 +1777,9 @@ void changed(void) if (curbuf->b_may_swap && !bt_dontwrite(curbuf) ) { + int save_need_wait_return = need_wait_return; + + need_wait_return = false; ml_open_file(curbuf); /* The ml_open_file() can cause an ATTENTION message. @@ -1788,6 +1791,8 @@ void changed(void) os_delay(2000L, true); wait_return(TRUE); msg_scroll = save_msg_scroll; + } else { + need_wait_return = save_need_wait_return; } } changed_int(); diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 57638ee388..f5607f3676 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -6737,16 +6737,12 @@ static void nv_g_cmd(cmdarg_T *cap) clearopbeep(oap); break; - /* - * "g CTRL-G": display info about cursor position - */ + // "g CTRL-G": display info about cursor position case Ctrl_G: - cursor_pos_info(); + cursor_pos_info(NULL); break; - /* - * "gi": start Insert at the last position. - */ + // "gi": start Insert at the last position. case 'i': if (curbuf->b_last_insert.mark.lnum != 0) { curwin->w_cursor = curbuf->b_last_insert.mark; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a6ff68a8f8..eda963ff77 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5165,18 +5165,18 @@ static long line_count_info(char_u *line, long *wc, long *cc, long limit, int eo return i; } -/* - * Give some info about the position of the cursor (for "g CTRL-G"). - * In Visual mode, give some info about the selected region. (In this case, - * the *_count_cursor variables store running totals for the selection.) - */ -void cursor_pos_info(void) +/// Give some info about the position of the cursor (for "g CTRL-G"). +/// In Visual mode, give some info about the selected region. (In this case, +/// the *_count_cursor variables store running totals for the selection.) +/// When "dict" is not NULL store the info there instead of showing it. +void cursor_pos_info(dict_T *dict) { char_u *p; char_u buf1[50]; char_u buf2[40]; linenr_T lnum; long byte_count = 0; + long bom_count = 0; long byte_count_cursor = 0; long char_count = 0; long char_count_cursor = 0; @@ -5191,11 +5191,12 @@ void cursor_pos_info(void) const int l_VIsual_active = VIsual_active; const int l_VIsual_mode = VIsual_mode; - /* - * Compute the length of the file in characters. - */ + // Compute the length of the file in characters. if (curbuf->b_ml.ml_flags & ML_EMPTY) { - MSG(_(no_lines_msg)); + if (dict == NULL) { + MSG(_(no_lines_msg)); + return; + } } else { if (get_fileformat(curbuf) == EOL_DOS) eol_size = 2; @@ -5300,78 +5301,105 @@ void cursor_pos_info(void) &char_count, (long)MAXCOL, eol_size); } - /* Correction for when last line doesn't have an EOL. */ - if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) + // Correction for when last line doesn't have an EOL. + if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) { byte_count -= eol_size; + } + + if (dict == NULL) { + if (l_VIsual_active) { + if (l_VIsual_mode == Ctrl_V && curwin->w_curswant < MAXCOL) { + getvcols(curwin, &min_pos, &max_pos, &min_pos.col, &max_pos.col); + vim_snprintf((char *)buf1, sizeof(buf1), _("%" PRId64 " Cols; "), + (int64_t)(oparg.end_vcol - oparg.start_vcol + 1)); + } else { + buf1[0] = NUL; + } + + if (char_count_cursor == byte_count_cursor + && char_count == byte_count) { + vim_snprintf((char *)IObuff, IOSIZE, + _("Selected %s%" PRId64 " of %" PRId64 " Lines;" + " %" PRId64 " of %" PRId64 " Words;" + " %" PRId64 " of %" PRId64 " Bytes"), + buf1, (int64_t)line_count_selected, + (int64_t)curbuf->b_ml.ml_line_count, + (int64_t)word_count_cursor, (int64_t)word_count, + (int64_t)byte_count_cursor, (int64_t)byte_count); + } else { + vim_snprintf((char *)IObuff, IOSIZE, + _("Selected %s%" PRId64 " of %" PRId64 " Lines;" + " %" PRId64 " of %" PRId64 " Words;" + " %" PRId64 " of %" PRId64 " Chars;" + " %" PRId64 " of %" PRId64 " Bytes"), + buf1, (int64_t)line_count_selected, + (int64_t)curbuf->b_ml.ml_line_count, + (int64_t)word_count_cursor, (int64_t)word_count, + (int64_t)char_count_cursor, (int64_t)char_count, + (int64_t)byte_count_cursor, (int64_t)byte_count); + } + } else { + p = get_cursor_line_ptr(); + validate_virtcol(); + col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, + (int)curwin->w_virtcol + 1); + col_print(buf2, sizeof(buf2), (int)STRLEN(p), linetabsize(p)); + + if (char_count_cursor == byte_count_cursor + && char_count == byte_count) { + vim_snprintf((char *)IObuff, IOSIZE, + _("Col %s of %s; Line %" PRId64 " of %" PRId64 ";" + " Word %" PRId64 " of %" PRId64 ";" + " Byte %" PRId64 " of %" PRId64 ""), + (char *)buf1, (char *)buf2, + (int64_t)curwin->w_cursor.lnum, + (int64_t)curbuf->b_ml.ml_line_count, + (int64_t)word_count_cursor, (int64_t)word_count, + (int64_t)byte_count_cursor, (int64_t)byte_count); + } else { + vim_snprintf((char *)IObuff, IOSIZE, + _("Col %s of %s; Line %" PRId64 " of %" PRId64 ";" + " Word %" PRId64 " of %" PRId64 ";" + " Char %" PRId64 " of %" PRId64 ";" + " Byte %" PRId64 " of %" PRId64 ""), + (char *)buf1, (char *)buf2, + (int64_t)curwin->w_cursor.lnum, + (int64_t)curbuf->b_ml.ml_line_count, + (int64_t)word_count_cursor, (int64_t)word_count, + (int64_t)char_count_cursor, (int64_t)char_count, + (int64_t)byte_count_cursor, (int64_t)byte_count); + } + } + } + + // Don't shorten this message, the user asked for it. + bom_count = bomb_size(); + if (bom_count > 0) { + vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), + _("(+%" PRId64 " for BOM)"), (int64_t)byte_count); + } + if (dict == NULL) { + p = p_shm; + p_shm = (char_u *)""; + msg(IObuff); + p_shm = p; + } + } + + if (dict != NULL) { + dict_add_nr_str(dict, "words", word_count, NULL); + dict_add_nr_str(dict, "chars", char_count, NULL); + dict_add_nr_str(dict, "bytes", byte_count + bom_count, NULL); if (l_VIsual_active) { - if (l_VIsual_mode == Ctrl_V && curwin->w_curswant < MAXCOL) { - getvcols(curwin, &min_pos, &max_pos, &min_pos.col, - &max_pos.col); - vim_snprintf((char *)buf1, sizeof(buf1), _("%" PRId64 " Cols; "), - (int64_t)(oparg.end_vcol - oparg.start_vcol + 1)); - } else - buf1[0] = NUL; - - if (char_count_cursor == byte_count_cursor - && char_count == byte_count) - vim_snprintf((char *)IObuff, IOSIZE, - _("Selected %s%" PRId64 " of %" PRId64 " Lines; %" PRId64 - " of %" PRId64 " Words; %" PRId64 " of %" PRId64 " Bytes"), - buf1, (int64_t)line_count_selected, - (int64_t)curbuf->b_ml.ml_line_count, - (int64_t)word_count_cursor, (int64_t)word_count, - (int64_t)byte_count_cursor, (int64_t)byte_count); - else - vim_snprintf((char *)IObuff, IOSIZE, - _("Selected %s%" PRId64 " of %" PRId64 " Lines; %" PRId64 - " of %" PRId64 " Words; %" PRId64 " of %" PRId64 - " Chars; %" PRId64 " of %" PRId64 " Bytes"), - buf1, (int64_t)line_count_selected, - (int64_t)curbuf->b_ml.ml_line_count, - (int64_t)word_count_cursor, (int64_t)word_count, - (int64_t)char_count_cursor, (int64_t)char_count, - (int64_t)byte_count_cursor, (int64_t)byte_count); + dict_add_nr_str(dict, "visual_bytes", byte_count_cursor, NULL); + dict_add_nr_str(dict, "visual_chars", char_count_cursor, NULL); + dict_add_nr_str(dict, "visual_words", word_count_cursor, NULL); } else { - p = get_cursor_line_ptr(); - validate_virtcol(); - col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, - (int)curwin->w_virtcol + 1); - col_print(buf2, sizeof(buf2), (int)STRLEN(p), linetabsize(p)); - - if (char_count_cursor == byte_count_cursor - && char_count == byte_count) - vim_snprintf((char *)IObuff, IOSIZE, - _("Col %s of %s; Line %" PRId64 " of %" PRId64 "; Word %" PRId64 - " of %" PRId64 "; Byte %" PRId64 " of %" PRId64 ""), - (char *)buf1, (char *)buf2, - (int64_t)curwin->w_cursor.lnum, - (int64_t)curbuf->b_ml.ml_line_count, - (int64_t)word_count_cursor, (int64_t)word_count, - (int64_t)byte_count_cursor, (int64_t)byte_count); - else - vim_snprintf((char *)IObuff, IOSIZE, - _( - "Col %s of %s; Line %" PRId64 " of %" PRId64 "; Word %" PRId64 - " of %" PRId64 "; Char %" PRId64 " of %" PRId64 - "; Byte %" PRId64 " of %" PRId64 ""), - (char *)buf1, (char *)buf2, - (int64_t)curwin->w_cursor.lnum, - (int64_t)curbuf->b_ml.ml_line_count, - (int64_t)word_count_cursor, (int64_t)word_count, - (int64_t)char_count_cursor, (int64_t)char_count, - (int64_t)byte_count_cursor, (int64_t)byte_count); - } - - byte_count = bomb_size(); - if (byte_count > 0) - sprintf((char *)IObuff + STRLEN(IObuff), _("(+%" PRId64 " for BOM)"), - (int64_t)byte_count); - /* Don't shorten this message, the user asked for it. */ - p = p_shm; - p_shm = (char_u *)""; - msg(IObuff); - p_shm = p; + dict_add_nr_str(dict, "cursor_bytes", byte_count_cursor, NULL); + dict_add_nr_str(dict, "cursor_chars", char_count_cursor, NULL); + dict_add_nr_str(dict, "cursor_words", word_count_cursor, NULL); + } } } diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 55894e4d12..6a29f86e79 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -46,6 +46,8 @@ # endif #endif +#define BACKSLASH_IN_FILENAME + #ifdef _MSC_VER typedef SSIZE_T ssize_t; #endif diff --git a/src/nvim/path.c b/src/nvim/path.c index aff0ee2d48..41fd69f238 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1284,6 +1284,29 @@ static int expand_backtick( return cnt; } +#ifdef BACKSLASH_IN_FILENAME +/// Replace all slashes by backslashes. +/// This used to be the other way around, but MS-DOS sometimes has problems +/// with slashes (e.g. in a command name). We can't have mixed slashes and +/// backslashes, because comparing file names will not work correctly. The +/// commands that use a file name should try to avoid the need to type a +/// backslash twice. +/// When 'shellslash' set do it the other way around. +/// When the path looks like a URL leave it unmodified. +void slash_adjust(char_u *p) +{ + if (path_with_url(p)) { + return; + } + while (*p) { + if (*p == psepcN) { + *p = psepc; + } + mb_ptr_adv(p); + } +} +#endif + // Add a file to a file list. Accepted flags: // EW_DIR add directories // EW_FILE add files diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 59168b29a0..10b5b6bba4 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3693,9 +3693,13 @@ win_line ( && wp == curwin && lnum == wp->w_cursor.lnum && conceal_cursor_line(wp) && (int)wp->w_virtcol <= vcol + n_skip) { - wp->w_wcol = col - boguscols; + if (wp->w_p_rl) { + wp->w_wcol = wp->w_width - col + boguscols - 1; + } else { + wp->w_wcol = col - boguscols; + } wp->w_wrow = row; - did_wcol = TRUE; + did_wcol = true; } /* Don't override visual selection highlighting. */ diff --git a/src/nvim/version.c b/src/nvim/version.c index e0bd83434c..81137ff1c6 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -116,7 +116,7 @@ static int included_patches[] = { // 1565, // 1564, // 1563, - // 1562, + // 1562 NA // 1561 NA // 1560, // 1559, @@ -331,7 +331,7 @@ static int included_patches[] = { // 1350 NA // 1349 NA // 1348 NA - // 1347, + 1347, 1346, // 1345 NA // 1344 NA @@ -577,7 +577,7 @@ static int included_patches[] = { // 1104 NA // 1103 NA // 1102, - // 1101, + 1101, // 1100 NA // 1099 NA // 1098 NA @@ -587,7 +587,7 @@ static int included_patches[] = { // 1094, 1093, 1092, - // 1091, + 1091, // 1090, 1089, 1088, @@ -636,7 +636,7 @@ static int included_patches[] = { // 1045 NA // 1044 NA // 1043 NA - // 1042, + 1042, 1041, // 1040 NA // 1039, @@ -663,7 +663,7 @@ static int included_patches[] = { // 1018, // 1017, // 1016 NA - // 1015, + 1015, // 1014 NA 1013, // 1012 NA @@ -782,7 +782,7 @@ static int included_patches[] = { // 899 NA 898, // 897 NA - // 896, + 896, 895, // 894 NA 893, diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index b503eba46e..69467632a4 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -53,7 +53,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, wlwd()) -- Change tab-local working directory and verify it is different - execute('t' .. cmd .. ' ' .. directories[1]) + execute('silent t' .. cmd .. ' ' .. directories[1]) eq(globalDir .. '/' .. directories[1], cwd()) eq(cwd(), tcwd()) -- working directory maches tab directory eq(1, tlwd()) @@ -65,7 +65,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(1, tlwd()) -- Still tab-local working directory eq(0, wlwd()) -- Still no window-local working directory eq(globalDir .. '/' .. directories[1], cwd()) - execute('l' .. cmd .. ' ../' .. directories[2]) + execute('silent l' .. cmd .. ' ../' .. directories[2]) eq(globalDir .. '/' .. directories[2], cwd()) eq(globalDir .. '/' .. directories[1], tcwd()) eq(1, wlwd()) @@ -83,7 +83,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, wlwd()) -- Verify global changes don't affect local ones - execute('' .. cmd .. ' ' .. directories[3]) + execute('silent ' .. cmd .. ' ' .. directories[3]) eq(globalDir .. '/' .. directories[3], cwd()) execute('tabnext') eq(globalDir .. '/' .. directories[1], cwd()) @@ -91,7 +91,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, wlwd()) -- Still no window-local directory in this window -- Unless the global change happened in a tab with local directory - execute('' .. cmd .. ' ..') + execute('silent ' .. cmd .. ' ..') eq(globalDir, cwd() ) eq(0 , tlwd()) eq(0 , wlwd()) @@ -111,6 +111,10 @@ end -- Test legal parameters for 'getcwd' and 'haslocaldir' for _, cmd in ipairs {'getcwd', 'haslocaldir'} do describe(cmd..'()', function() + before_each(function() + clear() + end) + -- Test invalid argument types local err474 = 'Vim(call):E474: Invalid argument' it('fails on string', function() diff --git a/test/functional/legacy/wordcount_spec.lua b/test/functional/legacy/wordcount_spec.lua new file mode 100644 index 0000000000..63787a59d3 --- /dev/null +++ b/test/functional/legacy/wordcount_spec.lua @@ -0,0 +1,167 @@ +-- Test for wordcount() function + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute = helpers.clear, helpers.execute +local eq, eval = helpers.eq, helpers.eval + +describe('wordcount', function() + before_each(clear) + + it('is working', function() + insert([=[ + RESULT test:]=]) + + execute('new') + source([=[ + function DoRecordWin(...) + wincmd k + if exists("a:1") + call cursor(a:1) + endif + let result=[] + call add(result, getline(1, '$')) + call add(result, wordcount()) + wincmd j + return result + endfunction + ]=]) + + source([=[ + function PutInWindow(args) + wincmd k + %d _ + call append(1, a:args) + wincmd j + endfunction + ]=]) + + source([=[ + function! STL() + if mode() =~? 'V' + let g:visual_stat=wordcount() + endif + return string(wordcount()) + endfunction + ]=]) + + -- Test 1: empty window + eq(eval('DoRecordWin()'), + eval([=[ + [[''], {'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0, 'bytes': 0, 'cursor_bytes': 0}] + ]=]) + ) + + -- Test 2: some words, cursor at start + execute([[call PutInWindow('one two three')]]) + eq(eval('DoRecordWin([1, 1, 0])'), + eval([=[ + [['', 'one two three'], {'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0, 'bytes': 15, 'cursor_bytes': 1}] + ]=]) + ) + + -- Test 3: some words, cursor at end + execute([[call PutInWindow('one two three')]]) + eq(eval('DoRecordWin([2, 99, 0])'), + eval([=[ + [['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 14}] + ]=]) + ) + + -- Test 4: some words, cursor at end, ve=all + execute('set ve=all') + execute([[call PutInWindow('one two three')]]) + eq(eval('DoRecordWin([2,99,0])'), + eval([=[ + [['', 'one two three'], {'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 15}] + ]=]) + ) + execute('set ve=') + + -- Test 5: several lines with words + execute([=[call PutInWindow(['one two three', 'one two three', 'one two three'])]=]) + eq(eval('DoRecordWin([4,99,0])'), + eval([=[ + [['', 'one two three', 'one two three', 'one two three'], {'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9, 'bytes': 43, 'cursor_bytes': 42}] + ]=]) + ) + + -- Test 6: one line with BOM set + execute([[call PutInWindow('one two three')]]) + execute('wincmd k') + execute('set bomb') + execute('wincmd j') + eq(eval('DoRecordWin([2,99,0])'), + eval([=[ + [['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 18, 'cursor_bytes': 14}] + ]=]) + ) + execute('wincmd k') + execute('set nobomb') + execute('wincmd j') + + -- Test 7: one line with multibyte words + execute([=[call PutInWindow(['Äne M¤ne Müh'])]=]) + eq(eval('DoRecordWin([2,99,0])'), + eval([=[ + [['', 'Äne M¤ne Müh'], {'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3, 'bytes': 17, 'cursor_bytes': 16}] + ]=]) + ) + + -- Test 8: several lines with multibyte words + execute([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=]) + eq(eval('DoRecordWin([3,99,0])'), + eval([=[ + [['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7, 'bytes': 36, 'cursor_bytes': 35}] + ]=]) + ) + + -- Test 9: visual mode, complete buffer + execute([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=]) + execute('wincmd k') + execute('set ls=2 stl=%{STL()}') + -- -- Start visual mode quickly and select complete buffer. + execute('0') + feed('V2jy<cr>') + execute('set stl= ls=1') + execute('let log=DoRecordWin([3,99,0])') + execute('let log[1]=g:visual_stat') + eq(eval('log'), + eval([=[ + [['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32, 'visual_words': 7, 'visual_bytes': 36}] + ]=]) + ) + + -- Test 10: visual mode (empty) + execute([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=]) + execute('wincmd k') + execute('set ls=2 stl=%{STL()}') + -- Start visual mode quickly and select complete buffer. + execute('0') + feed('v$y<cr>') + execute('set stl= ls=1') + execute('let log=DoRecordWin([3,99,0])') + execute('let log[1]=g:visual_stat') + eq(eval('log'), + eval([=[ + [['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1, 'visual_words': 0, 'visual_bytes': 1}] + ]=]) + ) + + -- Test 11: visual mode, single line + execute([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=]) + execute('wincmd k') + execute('set ls=2 stl=%{STL()}') + -- Start visual mode quickly and select complete buffer. + execute('2') + feed('0v$y<cr>') + execute('set stl= ls=1') + execute('let log=DoRecordWin([3,99,0])') + execute('let log[1]=g:visual_stat') + eq(eval('log'), + eval([=[ + [['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13, 'visual_words': 3, 'visual_bytes': 16}] + ]=]) + ) + end) +end) diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index b3e84db132..7975d11aed 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -5,6 +5,9 @@ local os = helpers.cimport './src/nvim/os/os.h' local tempfile = helpers.cimport './src/nvim/fileio.h' describe('tempfile related functions', function() + before_each(function() + tempfile.vim_deltempdir() + end) after_each(function() tempfile.vim_deltempdir() end) |