From 6531b175addc33c710b6e4e3501077e1d7213a8c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 10:24:49 -0400 Subject: [PATCH 01/14] vim-patch:8.0.0878: no completion for :mapclear Problem: No completion for :mapclear. Solution: Add completion (Nobuhiro Takasaki et al. closes vim/vim#1943) https://github.com/vim/vim/commit/cae92dc3d5bdd4009910671328cd01394bfbe2cf --- runtime/doc/eval.txt | 1 + runtime/doc/map.txt | 1 + src/nvim/ex_docmd.c | 22 ++++++++++++++++++++++ src/nvim/ex_getln.c | 1 + src/nvim/testdir/test_cmdline.vim | 5 +++++ src/nvim/vim.h | 1 + 6 files changed, 31 insertions(+) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index cfc3b70443..900f54c5b9 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4099,6 +4099,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* highlight highlight groups history :history suboptions locale locale names (as output of locale -a) + mapclear buffer argument mapping mapping name menu menus messages |:messages| suboptions diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 804b7410f6..44c6196d53 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1227,6 +1227,7 @@ completion can be enabled: -complete=highlight highlight groups -complete=history :history suboptions -complete=locale locale names (as output of locale -a) + -complete=mapclear buffer argument -complete=mapping mapping name -complete=menu menus -complete=messages |:messages| suboptions diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index c31242f2ac..df9f5774bc 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3350,6 +3350,19 @@ const char * set_one_cmd_context( case CMD_xunmap: return (const char *)set_context_in_map_cmd( xp, (char_u *)cmd, (char_u *)arg, forceit, false, true, ea.cmdidx); + case CMD_mapclear: + case CMD_nmapclear: + case CMD_vmapclear: + case CMD_omapclear: + case CMD_imapclear: + case CMD_cmapclear: + case CMD_lmapclear: + case CMD_smapclear: + case CMD_xmapclear: + xp->xp_context = EXPAND_MAPCLEAR; + xp->xp_pattern = (char_u *)arg; + break; + case CMD_abbreviate: case CMD_noreabbrev: case CMD_cabbrev: case CMD_cnoreabbrev: case CMD_iabbrev: case CMD_inoreabbrev: @@ -4870,6 +4883,7 @@ static const char *command_complete[] = #ifdef HAVE_WORKING_LIBINTL [EXPAND_LOCALES] = "locale", #endif + [EXPAND_MAPCLEAR] = "mapclear", [EXPAND_MAPPINGS] = "mapping", [EXPAND_MENUS] = "menu", [EXPAND_MESSAGES] = "messages", @@ -9655,6 +9669,14 @@ char_u *get_messages_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) return NULL; } +char_u *get_mapclear_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) +{ + if (idx == 0) { + return (char_u *)""; + } + return NULL; +} + static TriState filetype_detect = kNone; static TriState filetype_plugin = kNone; static TriState filetype_indent = kNone; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1810056a4a..e8a85e7cf6 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4756,6 +4756,7 @@ ExpandFromContext ( } tab[] = { { EXPAND_COMMANDS, get_command_name, false, true }, { EXPAND_BEHAVE, get_behave_arg, true, true }, + { EXPAND_MAPCLEAR, get_mapclear_arg, true, true }, { EXPAND_MESSAGES, get_messages_arg, true, true }, { EXPAND_HISTORY, get_history_arg, true, true }, { EXPAND_USER_COMMANDS, get_user_commands, false, true }, diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 5a43838218..a93beac4ad 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -222,6 +222,11 @@ func Test_getcompletion() let l = getcompletion('not', 'messages') call assert_equal([], l) + let l = getcompletion('', 'mapclear') + call assert_true(index(l, '') >= 0) + let l = getcompletion('not', 'mapclear') + call assert_equal([], l) + if has('cscope') let l = getcompletion('', 'cscope') let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] diff --git a/src/nvim/vim.h b/src/nvim/vim.h index bddf092789..93cc58524e 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -155,6 +155,7 @@ enum { EXPAND_USER_ADDR_TYPE, EXPAND_PACKADD, EXPAND_MESSAGES, + EXPAND_MAPCLEAR, EXPAND_CHECKHEALTH, }; From be552c8340615a4c9e670bc77df5e6016214d4f4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 11:03:12 -0400 Subject: [PATCH 02/14] vim-patch:8.0.1231: expanding file name drops dash Problem: Expanding file name drops dash. (stucki) Solution: Use the right position. (Christian Brabandt, closes vim/vim#2184) https://github.com/vim/vim/commit/c312b8b87a589ed8452dbf0f555f05ff86d04692 --- src/nvim/ex_docmd.c | 9 ++++++++- src/nvim/testdir/test_cmdline.vim | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index df9f5774bc..5e5b6c382d 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8521,9 +8521,13 @@ eval_vars ( if (*s == '<') /* "#<99" uses v:oldfiles */ ++s; i = getdigits_int(&s); + if (s == src + 2 && src[1] == '-') { + // just a minus sign, don't skip over it + s--; + } *usedlen = (size_t)(s - src); /* length of what we expand */ - if (src[1] == '<') { + if (src[1] == '<' && i != 0) { if (*usedlen < 2) { /* Should we give an error message for # 1) { + *usedlen = 1; + } buf = buflist_findnr(i); if (buf == NULL) { *errormsg = (char_u *)_( diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index a93beac4ad..ac80dd383e 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -380,6 +380,27 @@ func Test_cmdline_complete_user_cmd() delcommand Foo endfunc +func Test_cmdline_write_alternatefile() + new + call setline('.', ['one', 'two']) + f foo.txt + new + f #-A + call assert_equal('foo.txt-A', expand('%')) + f #<-B.txt + call assert_equal('foo-B.txt', expand('%')) + f %< + call assert_equal('foo-B', expand('%')) + new + call assert_fails('f #<', 'E95') + bw! + f foo-B.txt + f %<-A + call assert_equal('foo-B-A', expand('%')) + bw! + bw! +endfunc + " using a leading backslash here set cpo+=C From 1dcdac013e4beea2a327e1fb98ac4627bbe174ec Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 11:28:05 -0400 Subject: [PATCH 03/14] vim-patch:8.0.1649: no completion for argument list commands Problem: No completion for argument list commands. Solution: Add arglist completion. (Yegappan Lakshmanan, closes vim/vim#2706) https://github.com/vim/vim/commit/cd43effecab02c6c28b1c4a3a14f91b8c3f26c0d --- runtime/doc/eval.txt | 1 + runtime/doc/map.txt | 1 + src/nvim/ex_cmds2.c | 9 +++++++++ src/nvim/ex_docmd.c | 8 ++++++++ src/nvim/ex_getln.c | 1 + src/nvim/testdir/test_cmdline.vim | 5 +++++ src/nvim/vim.h | 1 + 7 files changed, 26 insertions(+) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 900f54c5b9..4d5a592190 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4079,6 +4079,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* specifies what for. The following completion types are supported: + arglist file names in argument list augroup autocmd groups buffer buffer names behave :behave suboptions diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 44c6196d53..d630bf5652 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1208,6 +1208,7 @@ By default, the arguments of user defined commands do not undergo completion. However, by specifying one or the other of the following attributes, argument completion can be enabled: + -complete=arglist file names in argument list -complete=augroup autocmd groups -complete=buffer buffer names -complete=behave :behave suboptions diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 120278d3fb..c384d253b9 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2254,6 +2254,15 @@ static int alist_add_list(int count, char_u **files, int after) } } +// Function given to ExpandGeneric() to obtain the possible arguments of the +// argedit and argdelete commands. +char_u *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx) +{ + if (idx >= ARGCOUNT) { + return NULL; + } + return alist_name(&ARGLIST[idx]); +} /// ":compiler[!] {name}" void ex_compiler(exarg_T *eap) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 5e5b6c382d..fe4de6f83d 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3454,6 +3454,13 @@ const char * set_one_cmd_context( xp->xp_pattern = (char_u *)arg; break; + case CMD_argdelete: + while ((xp->xp_pattern = vim_strchr((const char_u *)arg, ' ')) != NULL) { + arg = (const char *)(xp->xp_pattern + 1); + } + xp->xp_context = EXPAND_ARGLIST; + xp->xp_pattern = (char_u *)arg; + break; default: break; @@ -4859,6 +4866,7 @@ static struct { */ static const char *command_complete[] = { + [EXPAND_ARGLIST] = "arglist", [EXPAND_AUGROUP] = "augroup", [EXPAND_BEHAVE] = "behave", [EXPAND_BUFFERS] = "buffer", diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index e8a85e7cf6..0190cfabe5 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4784,6 +4784,7 @@ ExpandFromContext ( #endif { EXPAND_ENV_VARS, get_env_name, true, true }, { EXPAND_USER, get_users, true, false }, + { EXPAND_ARGLIST, get_arglist_name, true, false }, }; int i; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index ac80dd383e..9ea80d73d4 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -137,6 +137,11 @@ func Test_getcompletion() let l = getcompletion('v:notexists', 'var') call assert_equal([], l) + args a.c b.c + let l = getcompletion('', 'arglist') + call assert_equal(['a.c', 'b.c'], l) + %argdelete + let l = getcompletion('', 'augroup') call assert_true(index(l, 'END') >= 0) let l = getcompletion('blahblah', 'augroup') diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 93cc58524e..767936ecee 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -156,6 +156,7 @@ enum { EXPAND_PACKADD, EXPAND_MESSAGES, EXPAND_MAPCLEAR, + EXPAND_ARGLIST, EXPAND_CHECKHEALTH, }; From 14b148f0adbdb339d98ae293929949bffa7fa94b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 12:16:17 -0400 Subject: [PATCH 04/14] vim-patch:8.0.1816: no test for setcmdpos() Problem: No test for setcmdpos(). Solution: Add a test. (Dominique Pelle, closes vim/vim#2901) https://github.com/vim/vim/commit/ff3be4fe1e2e723de48b826cb992c798e296c41e --- src/nvim/testdir/test_cmdline.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 9ea80d73d4..02c44ee6cb 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -471,4 +471,25 @@ func Test_verbosefile() call delete('Xlog') endfunc +func Test_setcmdpos() + func InsertTextAtPos(text, pos) + call assert_equal(0, setcmdpos(a:pos)) + return a:text + endfunc + + " setcmdpos() with position in the middle of the command line. + call feedkeys(":\"12\=InsertTextAtPos('a', 3)\b\", 'xt') + call assert_equal('"1ab2', @:) + + call feedkeys(":\"12\\=InsertTextAtPos('a', 3)\b\", 'xt') + call assert_equal('"1b2a', @:) + + " setcmdpos() with position beyond the end of the command line. + call feedkeys(":\"12\\=InsertTextAtPos('a', 10)\b\", 'xt') + call assert_equal('"12ab', @:) + + " setcmdpos() returns 1 when not editing the command line. + call assert_equal(1, setcmdpos(3)) +endfunc + set cpo& From 68cd18eb0413534807f75a45bb3008c9f2b52947 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 12:56:14 -0400 Subject: [PATCH 05/14] vim-patch:8.1.0101: no test for getcmdwintype() Problem: No test for getcmdwintype(). Solution: Add a test. (Dominique Pelle, closes vim/vim#3068) https://github.com/vim/vim/commit/81612b7a7dc50a6c0da9f42fa48f1f576a4ad616 --- src/nvim/testdir/test_cmdline.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 02c44ee6cb..1b7bd83b3c 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -461,6 +461,22 @@ func Test_getcmdtype() cunmap endfunc +func Test_getcmdwintype() + call feedkeys("q/:let a = getcmdwintype()\:q\", 'x!') + call assert_equal('/', a) + + call feedkeys("q?:let a = getcmdwintype()\:q\", 'x!') + call assert_equal('?', a) + + call feedkeys("q::let a = getcmdwintype()\:q\", 'x!') + call assert_equal(':', a) + + call feedkeys(":\:let a = getcmdwintype()\:q\", 'x!') + call assert_equal(':', a) + + call assert_equal('', getcmdwintype()) +endfunc + func Test_verbosefile() set verbosefile=Xlog echomsg 'foo' From 015df9c66e66283277c3709376bf6d1f83d55f53 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 21:25:33 -0400 Subject: [PATCH 06/14] vim-patch:8.0.1787: cannot insert the whole cursor line Problem: Cannot insert the whole cursor line. Solution: Make CTRL-R CTRL-L work. (Andy Massimino, closes vim/vim#2857) https://github.com/vim/vim/commit/e2c8d8392684a940cc5608acc73ff47486bd7b92 --- runtime/doc/cmdline.txt | 6 ++++-- src/nvim/ex_getln.c | 4 +++- src/nvim/ops.c | 8 ++++++++ src/nvim/testdir/test_cmdline.vim | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index c46a9fc2d8..f4bc2972bc 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -163,12 +163,14 @@ CTRL-R CTRL-F *c_CTRL-R_CTRL-F* *c__* CTRL-R CTRL-P *c_CTRL-R_CTRL-P* *c__* CTRL-R CTRL-W *c_CTRL-R_CTRL-W* *c__* CTRL-R CTRL-A *c_CTRL-R_CTRL-A* *c__* +CTRL-R CTRL-L *c_CTRL-R_CTRL-L* *c__* Insert the object under the cursor: CTRL-F the Filename under the cursor CTRL-P the Filename under the cursor, expanded with 'path' as in |gf| CTRL-W the Word under the cursor CTRL-A the WORD under the cursor; see |WORD| + CTRL-L the line under the cursor When 'incsearch' is set the cursor position at the end of the currently displayed match is used. With CTRL-W the part of @@ -176,8 +178,8 @@ CTRL-R CTRL-A *c_CTRL-R_CTRL-A* *c__* *c_CTRL-R_CTRL-R* *c__* *c_CTRL-R_CTRL-O* *c__* -CTRL-R CTRL-R {0-9a-z"%#:-=. CTRL-F CTRL-P CTRL-W CTRL-A} -CTRL-R CTRL-O {0-9a-z"%#:-=. CTRL-F CTRL-P CTRL-W CTRL-A} +CTRL-R CTRL-R {0-9a-z"%#:-=. CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L} +CTRL-R CTRL-O {0-9a-z"%#:-=. CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L} Insert register or object under the cursor. Works like |c_CTRL-R| but inserts the text literally. For example, if register a contains "xy^Hz" (where ^H is a backspace), diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0190cfabe5..1192f3cb84 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3295,8 +3295,10 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) /* check for valid regname; also accept special characters for CTRL-R in * the command line */ if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W - && regname != Ctrl_A && !valid_yank_reg(regname, false)) + && regname != Ctrl_A && regname != Ctrl_L + && !valid_yank_reg(regname, false)) { return FAIL; + } /* A register containing CTRL-R can cause an endless loop. Allow using * CTRL-C to break the loop. */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7defde731a..af95f94946 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1257,6 +1257,14 @@ int get_spec_reg( *allocated = TRUE; return TRUE; + case Ctrl_L: // Line under cursor + if (!errmsg) { + return false; + } + + *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false); + return true; + case '_': /* black hole: always empty */ *argp = (char_u *)""; return TRUE; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 1b7bd83b3c..c302948ba3 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -321,6 +321,9 @@ func Test_paste_in_cmdline() call feedkeys("ft:aaa \\ bbb\\"\", 'tx') call assert_equal('"aaa /tmp/some bbb', @:) + call feedkeys(":aaa \\ bbb\\"\", 'tx') + call assert_equal('"aaa '.getline(1).' bbb', @:) + set incsearch call feedkeys("fy:aaa veryl\\ bbb\\"\", 'tx') call assert_equal('"aaa verylongword bbb', @:) From 58ad7fc578125aed6187944eb44c574041479fbf Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 22:32:06 -0400 Subject: [PATCH 07/14] ops: refactor get_spec_reg() Return value is bool. errmsg (param) is bool in here and in getaltfname(). allocated (param) is bool. --- src/nvim/buffer.c | 5 ++-- src/nvim/ex_getln.c | 5 ++-- src/nvim/ops.c | 62 ++++++++++++++++++++++----------------------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 00d472b4c8..64569c294b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2659,9 +2659,8 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum) * Get alternate file name for current window. * Return NULL if there isn't any, and give error message if requested. */ -char_u * -getaltfname ( - int errmsg /* give error message */ +char_u * getaltfname( + bool errmsg // give error message ) { char_u *fname; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1192f3cb84..14303bae77 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3286,10 +3286,9 @@ void restore_cmdline_alloc(char_u *p) /// @returns FAIL for failure, OK otherwise static bool cmdline_paste(int regname, bool literally, bool remcr) { - long i; char_u *arg; char_u *p; - int allocated; + bool allocated; struct cmdline_info save_ccline; /* check for valid regname; also accept special characters for CTRL-R in @@ -3311,7 +3310,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) * things like going to another buffer when evaluating an expression. */ save_cmdline(&save_ccline); ++textlock; - i = get_spec_reg(regname, &arg, &allocated, TRUE); + const bool i = get_spec_reg(regname, &arg, &allocated, true); --textlock; restore_cmdline(&save_ccline); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index af95f94946..f4a65a2314 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1110,7 +1110,7 @@ int insert_reg( ) { int retval = OK; - int allocated; + bool allocated; /* * It is possible to get into an endless loop by having CTRL-R a in @@ -1187,75 +1187,75 @@ static void stuffescaped(const char *arg, int literally) } } -/* - * If "regname" is a special register, return TRUE and store a pointer to its - * value in "argp". - */ -int get_spec_reg( +// If "regname" is a special register, return true and store a pointer to its +// value in "argp". +bool get_spec_reg( int regname, char_u **argp, - int *allocated, /* return: TRUE when value was allocated */ - int errmsg /* give error message when failing */ + bool *allocated, // return: true when value was allocated + bool errmsg // give error message when failing ) { size_t cnt; *argp = NULL; - *allocated = FALSE; + *allocated = false; switch (regname) { case '%': /* file name */ if (errmsg) check_fname(); /* will give emsg if not set */ *argp = curbuf->b_fname; - return TRUE; + return true; case '#': /* alternate file name */ *argp = getaltfname(errmsg); /* may give emsg if not set */ - return TRUE; + return true; case '=': /* result of expression */ *argp = get_expr_line(); - *allocated = TRUE; - return TRUE; + *allocated = true; + return true; case ':': /* last command line */ if (last_cmdline == NULL && errmsg) EMSG(_(e_nolastcmd)); *argp = last_cmdline; - return TRUE; + return true; case '/': /* last search-pattern */ if (last_search_pat() == NULL && errmsg) EMSG(_(e_noprevre)); *argp = last_search_pat(); - return TRUE; + return true; case '.': /* last inserted text */ *argp = get_last_insert_save(); - *allocated = TRUE; + *allocated = true; if (*argp == NULL && errmsg) EMSG(_(e_noinstext)); - return TRUE; + return true; case Ctrl_F: /* Filename under cursor */ case Ctrl_P: /* Path under cursor, expand via "path" */ - if (!errmsg) - return FALSE; + if (!errmsg) { + return false; + } *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); - *allocated = TRUE; - return TRUE; + *allocated = true; + return true; case Ctrl_W: /* word under cursor */ case Ctrl_A: /* WORD (mnemonic All) under cursor */ - if (!errmsg) - return FALSE; + if (!errmsg) { + return false; + } cnt = find_ident_under_cursor(argp, (regname == Ctrl_W ? (FIND_IDENT|FIND_STRING) : FIND_STRING)); *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; - *allocated = TRUE; - return TRUE; + *allocated = true; + return true; case Ctrl_L: // Line under cursor if (!errmsg) { @@ -1267,10 +1267,10 @@ int get_spec_reg( case '_': /* black hole: always empty */ *argp = (char_u *)""; - return TRUE; + return true; } - return FALSE; + return false; } /// Paste a yank register into the command line. @@ -2660,7 +2660,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) int lendiff = 0; pos_T old_pos; char_u *insert_string = NULL; - int allocated = FALSE; + bool allocated = false; long cnt; if (flags & PUT_FIXINDENT) @@ -2756,7 +2756,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * For special registers '%' (file name), '#' (alternate file name) and * ':' (last command line), etc. we have to create a fake yank register. */ - if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) { + if (get_spec_reg(regname, &insert_string, &allocated, true)) { if (insert_string == NULL) return; } @@ -4915,8 +4915,8 @@ void *get_reg_contents(int regname, int flags) return NULL; char_u *retval; - int allocated; - if (get_spec_reg(regname, &retval, &allocated, FALSE)) { + bool allocated; + if (get_spec_reg(regname, &retval, &allocated, false)) { if (retval == NULL) return NULL; if (allocated) { From f5b7fd5fa366c752f1a2f0a00cad0e4c4d8b3c20 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Aug 2018 09:05:09 -0400 Subject: [PATCH 08/14] ex_docmd: forceit,usefilter are bool --- src/nvim/ex_docmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index fe4de6f83d..8d0a8f21a7 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2665,8 +2665,8 @@ const char * set_one_cmd_context( size_t len = 0; exarg_T ea; int context = EXPAND_NOTHING; - int forceit = false; - int usefilter = false; // Filter instead of file name. + bool forceit = false; + bool usefilter = false; // Filter instead of file name. ExpandInit(xp); xp->xp_pattern = (char_u *)buff; @@ -2787,7 +2787,7 @@ const char * set_one_cmd_context( xp->xp_context = EXPAND_NOTHING; /* Default now that we're past command */ if (*p == '!') { /* forced commands */ - forceit = TRUE; + forceit = true; ++p; } @@ -2816,7 +2816,7 @@ const char * set_one_cmd_context( usefilter = forceit; /* :r! filter if forced */ if (*arg == '!') { /* :r !filter */ ++arg; - usefilter = TRUE; + usefilter = true; } } From f53c95e7a8cbeb6fb523d179ae166a3ace87dbcd Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Aug 2018 10:57:07 -0400 Subject: [PATCH 09/14] vim-patch:8.1.0159: completion for user names does not work for a prefix. Problem: Completion for user names does not work if a prefix is also a full matching name. (Nazri Ramliy) Solution: Accept both full and partial matches. (Dominique Pelle) https://github.com/vim/vim/commit/6c5d1043022520512ee36aa1a29662b60af33c95 --- src/nvim/ex_docmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8d0a8f21a7..076e77be6a 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2978,7 +2978,7 @@ const char * set_one_cmd_context( // A full match ~user will be replaced by user's home // directory i.e. something like ~user -> /home/user/ if (*p == NUL && p > (const char *)xp->xp_pattern + 1 - && match_user(xp->xp_pattern + 1) == 1) { + && match_user(xp->xp_pattern + 1) >= 1) { xp->xp_context = EXPAND_USER; ++xp->xp_pattern; } From 3d71366af1287f356a812a38f2c0b22230fe409c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Aug 2018 17:14:25 -0400 Subject: [PATCH 10/14] vim-patch:8.0.1090: cannot get the text under the cursor like v:beval_text Problem: cannot get the text under the cursor like v:beval_text Solution: Add . https://github.com/vim/vim/commit/65f084749b260746d7f186af4f080298be2df55b --- runtime/doc/cmdline.txt | 5 +++++ src/nvim/ex_docmd.c | 34 ++++++++++++++++++++------------ src/nvim/testdir/test_normal.vim | 20 +++++++++++++++---- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index f4bc2972bc..6e0c3269ab 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -788,6 +788,11 @@ Also see |`=|. Note: these are typed literally, they are not special keys! is replaced with the word under the cursor (like |star|) is replaced with the WORD under the cursor (see |WORD|) + is replaced with the word under the cursor, including more + to form a C expression. E.g., when the cursor is on "arg" + of "ptr->arg" then the result is "ptr->arg"; when the + cursor is on "]" of "list[idx]" then the result is + "list[idx]". This is used for |v:beval_text|. is replaced with the path name under the cursor (like what |gf| uses) When executing autocommands, is replaced with the file name diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 076e77be6a..97e09b8869 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8392,23 +8392,25 @@ ssize_t find_cmdline_var(const char_u *src, size_t *usedlen) "%", #define SPEC_PERC 0 "#", -#define SPEC_HASH 1 +#define SPEC_HASH (SPEC_PERC + 1) "", /* cursor word */ -#define SPEC_CWORD 2 +#define SPEC_CWORD (SPEC_HASH + 1) "", /* cursor WORD */ -#define SPEC_CCWORD 3 +#define SPEC_CCWORD (SPEC_CWORD + 1) + "", // expr under cursor +#define SPEC_CEXPR (SPEC_CCWORD + 1) "", /* cursor path name */ -#define SPEC_CFILE 4 +#define SPEC_CFILE (SPEC_CEXPR + 1) "", /* ":so" file name */ -#define SPEC_SFILE 5 +#define SPEC_SFILE (SPEC_CFILE + 1) "", /* ":so" file line number */ -#define SPEC_SLNUM 6 +#define SPEC_SLNUM (SPEC_SFILE + 1) "", /* autocommand file name */ -# define SPEC_AFILE 7 +#define SPEC_AFILE (SPEC_SLNUM + 1) "", /* autocommand buffer number */ -# define SPEC_ABUF 8 +#define SPEC_ABUF (SPEC_AFILE + 1) "", /* autocommand match name */ -# define SPEC_AMATCH 9 +#define SPEC_AMATCH (SPEC_ABUF + 1) }; for (size_t i = 0; i < ARRAY_SIZE(spec_str); ++i) { @@ -8489,10 +8491,16 @@ eval_vars ( /* * word or WORD under cursor */ - if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD) { - resultlen = find_ident_under_cursor(&result, (spec_idx == SPEC_CWORD - ? (FIND_IDENT|FIND_STRING) - : FIND_STRING)); + if (spec_idx == SPEC_CWORD + || spec_idx == SPEC_CCWORD + || spec_idx == SPEC_CEXPR) { + resultlen = find_ident_under_cursor( + &result, + spec_idx == SPEC_CWORD + ? (FIND_IDENT | FIND_STRING) + : (spec_idx == SPEC_CEXPR + ? (FIND_IDENT | FIND_STRING | FIND_EVAL) + : FIND_STRING)); if (resultlen == 0) { *errormsg = (char_u *)""; return NULL; diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 4c63bd1f71..035c778749 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -392,10 +392,22 @@ func! Test_normal10_expand() call setline(1, ['1', 'ifooar,,cbar']) 2 norm! $ - let a=expand('') - let b=expand('') - call assert_equal('cbar', a) - call assert_equal('ifooar,,cbar', b) + call assert_equal('cbar', expand('')) + call assert_equal('ifooar,,cbar', expand('')) + + call setline(1, ['prx = list[idx];']) + 1 + let expected = ['', 'prx', 'prx', 'prx', + \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', + \ 'idx', 'idx', 'idx', 'idx', + \ 'list[idx]', + \ '];', + \ ] + for i in range(1, 16) + exe 'norm ' . i . '|' + call assert_equal(expected[i], expand(''), 'i == ' . i) + endfor + " clean up bw! endfunc From f46728c24185a28ea2a2456d483efc86a68e7927 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Aug 2018 20:39:43 -0400 Subject: [PATCH 11/14] vim-patch:8.0.1091: test for fails without +balloon_eval feature Problem: Test for fails without +balloon_eval feature. Solution: Remove #ifdefs. https://github.com/vim/vim/commit/95c83c64be8d4af74bfda1f283a5bcf3f110719e --- src/nvim/normal.c | 91 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 12 deletions(-) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 225fe4aa9a..a9d62d0355 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2990,6 +2990,43 @@ void reset_VIsual(void) } } +// Check for a balloon-eval special item to include when searching for an +// identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! +// Returns true if the character at "*ptr" should be included. +// "dir" is FORWARD or BACKWARD, the direction of searching. +// "*colp" is in/decremented if "ptr[-dir]" should also be included. +// "bnp" points to a counter for square brackets. +static bool find_is_eval_item( + const char_u *const ptr, + int *const colp, + int *const bnp, + const int dir) +{ + // Accept everything inside []. + if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) { + *bnp += 1; + } + if (*bnp > 0) { + if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) { + *bnp -= 1; + } + return true; + } + + // skip over "s.var" + if (*ptr == '.') { + return true; + } + + // two-character item: s->var + if (ptr[dir == BACKWARD ? 0 : 1] == '>' + && ptr[dir == BACKWARD ? -1 : 0] == '-') { + *colp += dir; + return true; + } + return false; +} + /* * Find the identifier under or to the right of the cursor. * "find_type" can have one of three values: @@ -3030,6 +3067,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, int this_class = 0; int prev_class; int prevcol; + int bn = 0; // bracket nesting /* * if i == 0: try to find an identifier @@ -3043,24 +3081,36 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, col = startcol; if (has_mbyte) { while (ptr[col] != NUL) { + // Stop at a ']' to evaluate "a[x]". + if ((find_type & FIND_EVAL) && ptr[col] == ']') { + break; + } this_class = mb_get_class(ptr + col); if (this_class != 0 && (i == 1 || this_class != 1)) break; col += (*mb_ptr2len)(ptr + col); } - } else + } else { while (ptr[col] != NUL && (i == 0 ? !vim_iswordc(ptr[col]) : ascii_iswhite(ptr[col])) - ) - ++col; + && (!(find_type & FIND_EVAL) || ptr[col] != ']')) { + col++; + } + } + // When starting on a ']' count it, so that we include the '['. + bn = ptr[col] == ']'; /* * 2. Back up to start of identifier/string. */ if (has_mbyte) { - /* Remember class of character under cursor. */ - this_class = mb_get_class(ptr + col); + // Remember class of character under cursor. + if ((find_type & FIND_EVAL) && ptr[col] == ']') { + this_class = mb_get_class((char_u *)"a"); + } else { + this_class = mb_get_class(ptr + col); + } while (col > 0 && this_class != 0) { prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); prev_class = mb_get_class(ptr + prevcol); @@ -3068,8 +3118,12 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, && (i == 0 || prev_class == 0 || (find_type & FIND_IDENT)) - ) + && (!(find_type & FIND_EVAL) + || prevcol == 0 + || !find_is_eval_item(ptr + prevcol, &prevcol, &bn, BACKWARD)) + ) { break; + } col = prevcol; } @@ -3086,8 +3140,12 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, : (!ascii_iswhite(ptr[col - 1]) && (!(find_type & FIND_IDENT) || !vim_iswordc(ptr[col - 1])))) - )) - --col; + || ((find_type & FIND_EVAL) + && col > 1 + && find_is_eval_item(ptr + col - 1, &col, &bn, BACKWARD)) + )) { + col--; + } /* If we don't want just any old string, or we've found an * identifier, stop searching. */ @@ -3114,6 +3172,8 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, /* * 3. Find the end if the identifier/string. */ + bn = 0; + startcol -= col; col = 0; if (has_mbyte) { /* Search for point of changing multibyte character class. */ @@ -3121,14 +3181,21 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, while (ptr[col] != NUL && ((i == 0 ? mb_get_class(ptr + col) == this_class : mb_get_class(ptr + col) != 0) - )) + || ((find_type & FIND_EVAL) + && col <= (int)startcol + && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) + )) { col += (*mb_ptr2len)(ptr + col); - } else + } + } else { while ((i == 0 ? vim_iswordc(ptr[col]) : (ptr[col] != NUL && !ascii_iswhite(ptr[col]))) - ) { - ++col; + || ((find_type & FIND_EVAL) + && col <= (int)startcol + && find_is_eval_item(ptr + col, &col, &bn, FORWARD))) { + col++; } + } assert(col >= 0); return (size_t)col; From 7482aef113054c783b407d61d800e96177b325db Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Aug 2018 21:49:12 -0400 Subject: [PATCH 12/14] normal: don't check has_mbyte has_mbyte is always true for nvim. --- src/nvim/normal.c | 128 ++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 83 deletions(-) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a9d62d0355..c8104b411a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3079,23 +3079,16 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, * 1. skip to start of identifier/string */ col = startcol; - if (has_mbyte) { - while (ptr[col] != NUL) { - // Stop at a ']' to evaluate "a[x]". - if ((find_type & FIND_EVAL) && ptr[col] == ']') { - break; - } - this_class = mb_get_class(ptr + col); - if (this_class != 0 && (i == 1 || this_class != 1)) - break; - col += (*mb_ptr2len)(ptr + col); + while (ptr[col] != NUL) { + // Stop at a ']' to evaluate "a[x]". + if ((find_type & FIND_EVAL) && ptr[col] == ']') { + break; } - } else { - while (ptr[col] != NUL - && (i == 0 ? !vim_iswordc(ptr[col]) : ascii_iswhite(ptr[col])) - && (!(find_type & FIND_EVAL) || ptr[col] != ']')) { - col++; + this_class = mb_get_class(ptr + col); + if (this_class != 0 && (i == 1 || this_class != 1)) { + break; } + col += utfc_ptr2len(ptr + col); } // When starting on a ']' count it, so that we include the '['. @@ -3104,59 +3097,38 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, /* * 2. Back up to start of identifier/string. */ - if (has_mbyte) { - // Remember class of character under cursor. - if ((find_type & FIND_EVAL) && ptr[col] == ']') { - this_class = mb_get_class((char_u *)"a"); - } else { - this_class = mb_get_class(ptr + col); - } - while (col > 0 && this_class != 0) { - prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); - prev_class = mb_get_class(ptr + prevcol); - if (this_class != prev_class - && (i == 0 - || prev_class == 0 - || (find_type & FIND_IDENT)) - && (!(find_type & FIND_EVAL) - || prevcol == 0 - || !find_is_eval_item(ptr + prevcol, &prevcol, &bn, BACKWARD)) - ) { - break; - } - col = prevcol; - } - - /* If we don't want just any old string, or we've found an - * identifier, stop searching. */ - if (this_class > 2) - this_class = 2; - if (!(find_type & FIND_STRING) || this_class == 2) - break; + // Remember class of character under cursor. + if ((find_type & FIND_EVAL) && ptr[col] == ']') { + this_class = mb_get_class((char_u *)"a"); } else { - while (col > 0 - && ((i == 0 - ? vim_iswordc(ptr[col - 1]) - : (!ascii_iswhite(ptr[col - 1]) - && (!(find_type & FIND_IDENT) - || !vim_iswordc(ptr[col - 1])))) - || ((find_type & FIND_EVAL) - && col > 1 - && find_is_eval_item(ptr + col - 1, &col, &bn, BACKWARD)) - )) { - col--; - } - - /* If we don't want just any old string, or we've found an - * identifier, stop searching. */ - if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) + this_class = mb_get_class(ptr + col); + } + while (col > 0 && this_class != 0) { + prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); + prev_class = mb_get_class(ptr + prevcol); + if (this_class != prev_class + && (i == 0 + || prev_class == 0 + || (find_type & FIND_IDENT)) + && (!(find_type & FIND_EVAL) + || prevcol == 0 + || !find_is_eval_item(ptr + prevcol, &prevcol, &bn, BACKWARD))) { break; + } + col = prevcol; + } + + // If we don't want just any old string, or we've found an + // identifier, stop searching. + if (this_class > 2) { + this_class = 2; + } + if (!(find_type & FIND_STRING) || this_class == 2) { + break; } } - if (ptr[col] == NUL || (i == 0 && ( - has_mbyte ? this_class != 2 : - !vim_iswordc(ptr[col])))) { + if (ptr[col] == NUL || (i == 0 && this_class != 2)) { /* * didn't find an identifier or string */ @@ -3175,26 +3147,16 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, bn = 0; startcol -= col; col = 0; - if (has_mbyte) { - /* Search for point of changing multibyte character class. */ - this_class = mb_get_class(ptr); - while (ptr[col] != NUL - && ((i == 0 ? mb_get_class(ptr + col) == this_class - : mb_get_class(ptr + col) != 0) - || ((find_type & FIND_EVAL) - && col <= (int)startcol - && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) - )) { - col += (*mb_ptr2len)(ptr + col); - } - } else { - while ((i == 0 ? vim_iswordc(ptr[col]) - : (ptr[col] != NUL && !ascii_iswhite(ptr[col]))) - || ((find_type & FIND_EVAL) - && col <= (int)startcol - && find_is_eval_item(ptr + col, &col, &bn, FORWARD))) { - col++; - } + // Search for point of changing multibyte character class. + this_class = mb_get_class(ptr); + while (ptr[col] != NUL + && ((i == 0 + ? mb_get_class(ptr + col) == this_class + : mb_get_class(ptr + col) != 0) + || ((find_type & FIND_EVAL) + && col <= (int)startcol + && find_is_eval_item(ptr + col, &col, &bn, FORWARD)))) { + col += utfc_ptr2len(ptr + col); } assert(col >= 0); From 0223c81457efa3d7180ede0f2cc33cfe4338059e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 13:23:51 -0400 Subject: [PATCH 13/14] lint --- src/nvim/ex_docmd.c | 28 ++++++++++++++-------------- src/nvim/ex_getln.c | 4 ++-- src/nvim/normal.c | 9 ++++----- src/nvim/ops.c | 26 +++++++++++++++----------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 97e09b8869..20c188ed55 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2786,9 +2786,9 @@ const char * set_one_cmd_context( xp->xp_context = EXPAND_NOTHING; /* Default now that we're past command */ - if (*p == '!') { /* forced commands */ + if (*p == '!') { // forced commands forceit = true; - ++p; + p++; } /* @@ -2813,9 +2813,9 @@ const char * set_one_cmd_context( } if (ea.cmdidx == CMD_read) { - usefilter = forceit; /* :r! filter if forced */ - if (*arg == '!') { /* :r !filter */ - ++arg; + usefilter = forceit; // :r! filter if forced + if (*arg == '!') { // :r !filter + arg++; usefilter = true; } } @@ -8393,23 +8393,23 @@ ssize_t find_cmdline_var(const char_u *src, size_t *usedlen) #define SPEC_PERC 0 "#", #define SPEC_HASH (SPEC_PERC + 1) - "", /* cursor word */ + "", // cursor word #define SPEC_CWORD (SPEC_HASH + 1) - "", /* cursor WORD */ + "", // cursor WORD #define SPEC_CCWORD (SPEC_CWORD + 1) "", // expr under cursor #define SPEC_CEXPR (SPEC_CCWORD + 1) - "", /* cursor path name */ + "", // cursor path name #define SPEC_CFILE (SPEC_CEXPR + 1) - "", /* ":so" file name */ + "", // ":so" file name #define SPEC_SFILE (SPEC_CFILE + 1) - "", /* ":so" file line number */ + "", // ":so" file line number #define SPEC_SLNUM (SPEC_SFILE + 1) - "", /* autocommand file name */ + "", // autocommand file name #define SPEC_AFILE (SPEC_SLNUM + 1) - "", /* autocommand buffer number */ + "", // autocommand buffer number #define SPEC_ABUF (SPEC_AFILE + 1) - "", /* autocommand match name */ + "", // autocommand match name #define SPEC_AMATCH (SPEC_ABUF + 1) }; @@ -8541,7 +8541,7 @@ eval_vars ( // just a minus sign, don't skip over it s--; } - *usedlen = (size_t)(s - src); /* length of what we expand */ + *usedlen = (size_t)(s - src); // length of what we expand if (src[1] == '<' && i != 0) { if (*usedlen < 2) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 14303bae77..9eb90643fe 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3309,9 +3309,9 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) /* Need to save and restore ccline. And set "textlock" to avoid nasty * things like going to another buffer when evaluating an expression. */ save_cmdline(&save_ccline); - ++textlock; + textlock++; const bool i = get_spec_reg(regname, &arg, &allocated, true); - --textlock; + textlock--; restore_cmdline(&save_ccline); if (i) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c8104b411a..afddd548a3 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3129,13 +3129,12 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, } if (ptr[col] == NUL || (i == 0 && this_class != 2)) { - /* - * didn't find an identifier or string - */ - if (find_type & FIND_STRING) + // didn't find an identifier or string + if (find_type & FIND_STRING) { EMSG(_("E348: No string under cursor")); - else + } else { EMSG(_(e_noident)); + } return 0; } ptr += col; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f4a65a2314..ff02d82ff3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1207,8 +1207,8 @@ bool get_spec_reg( *argp = curbuf->b_fname; return true; - case '#': /* alternate file name */ - *argp = getaltfname(errmsg); /* may give emsg if not set */ + case '#': // alternate file name + *argp = getaltfname(errmsg); // may give emsg if not set return true; case '=': /* result of expression */ @@ -1231,22 +1231,24 @@ bool get_spec_reg( case '.': /* last inserted text */ *argp = get_last_insert_save(); *allocated = true; - if (*argp == NULL && errmsg) + if (*argp == NULL && errmsg) { EMSG(_(e_noinstext)); + } return true; - case Ctrl_F: /* Filename under cursor */ - case Ctrl_P: /* Path under cursor, expand via "path" */ + case Ctrl_F: // Filename under cursor + case Ctrl_P: // Path under cursor, expand via "path" if (!errmsg) { return false; } - *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP - | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); + *argp = file_name_at_cursor( + FNAME_MESS | FNAME_HYP | (regname == Ctrl_P ? FNAME_EXP : 0), + 1L, NULL); *allocated = true; return true; - case Ctrl_W: /* word under cursor */ - case Ctrl_A: /* WORD (mnemonic All) under cursor */ + case Ctrl_W: // word under cursor + case Ctrl_A: // WORD (mnemonic All) under cursor if (!errmsg) { return false; } @@ -2757,8 +2759,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * ':' (last command line), etc. we have to create a fake yank register. */ if (get_spec_reg(regname, &insert_string, &allocated, true)) { - if (insert_string == NULL) + if (insert_string == NULL) { return; + } } if (!curbuf->terminal) { @@ -4917,8 +4920,9 @@ void *get_reg_contents(int regname, int flags) char_u *retval; bool allocated; if (get_spec_reg(regname, &retval, &allocated, false)) { - if (retval == NULL) + if (retval == NULL) { return NULL; + } if (allocated) { return get_reg_wrap_one_line(retval, flags); } From 89fec12e9f7e5f1ecc28ff0551fac3d2cb8267d2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Aug 2018 03:27:54 -0400 Subject: [PATCH 14/14] vim-patch:8.0.1418: no test for expanding backticks Problem: No test for expanding backticks. Solution: Add a test. (Dominique Pelle, closes vim/vim#2479) https://github.com/vim/vim/commit/ae6f8651251013bafef9de1aed09069deaae8122 --- src/nvim/testdir/test_normal.vim | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 035c778749..caa530e4aa 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -408,6 +408,15 @@ func! Test_normal10_expand() call assert_equal(expected[i], expand(''), 'i == ' . i) endfor + if executable('echo') + " Test expand(`...`) i.e. backticks command expansion. + " MS-Windows has a trailing space. + call assert_match('^abcde *$', expand('`echo abcde`')) + endif + + " Test expand(`=...`) i.e. backticks expression expansion + call assert_equal('5', expand('`=2+3`')) + " clean up bw! endfunc @@ -1548,12 +1557,12 @@ fun! Test_normal29_brace() \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', \ 'paragraph boundary |posix|.', \ '{', - \ 'This is no paragaraph', + \ 'This is no paragraph', \ 'unless the ''{'' is set', \ 'in ''cpoptions''', \ '}', \ '.IP', - \ 'The nroff macros IP seperates a paragraph', + \ 'The nroff macros IP separates a paragraph', \ 'That means, it must be a ''.''', \ 'followed by IP', \ '.LPIt does not matter, if afterwards some', @@ -1568,7 +1577,7 @@ fun! Test_normal29_brace() 1 norm! 0d2} call assert_equal(['.IP', - \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP', + \ 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', 'followed by IP', \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) norm! 0d} @@ -1588,21 +1597,21 @@ fun! Test_normal29_brace() " set cpo+={ " 1 " norm! 0d2} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', - " \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + " \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', " \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', " \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', " \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) " $ " norm! d} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', - " \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + " \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', " \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', " \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', " \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) " norm! gg} " norm! d5} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) " clean up set cpo-={