diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 31 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 3 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 29 | ||||
-rw-r--r-- | src/nvim/search.c | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 19 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 36 | ||||
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/autocmd/termclose_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/core/job_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ex_cmds/ctrl_c_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/plugin/man_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/output_spec.lua | 2 | ||||
-rw-r--r-- | test/helpers.lua | 12 | ||||
-rw-r--r-- | test/unit/mbyte_spec.lua | 3 |
16 files changed, 124 insertions, 55 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index ba89c207c2..6b39f1a103 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1087,14 +1087,12 @@ TextChangedP After a change was made to the text in the popup menu is visible. Otherwise the same as TextChanged. *User* -User Never executed automatically. To be used for - autocommands that are only executed with - ":doautocmd". - Note that when `:doautocmd User MyEvent` is - used while there are no matching autocommands, - you will get an error. If you don't want - that, define a dummy autocommand yourself. - *UserGettingBored* +User Not executed automatically. Use |:doautocmd| + to trigger this, typically for "custom events" + in a plugin. Example: > + :autocmd User MyPlugin echom 'got MyPlugin event' + :doautocmd User MyPlugin +< *UserGettingBored* UserGettingBored When the user presses the same key 42 times. Just kidding! :-) *VimEnter* @@ -1389,18 +1387,17 @@ option will not cause any commands to be executed. When the [group] argument is not given, Vim executes the autocommands for all groups. When the [group] argument is included, Vim executes only the matching - autocommands for that group. Note: if you use an - undefined group name, Vim gives you an error message. + autocommands for that group. Undefined group is an + error. *<nomodeline>* After applying the autocommands the modelines are processed, so that their settings overrule the - settings from autocommands, like what happens when - editing a file. This is skipped when the <nomodeline> - argument is present. You probably want to use - <nomodeline> for events that are not used when loading - a buffer, such as |User|. - Processing modelines is also skipped when no - matching autocommands were executed. + settings from autocommands when editing a file. This + is skipped if <nomodeline> is specified. You probably + want to use <nomodeline> for events not used when + loading a buffer, such as |User|. + Modelines are also skipped when no matching + autocommands were executed. *:doautoa* *:doautoall* :doautoa[ll] [<nomodeline>] [group] {event} [fname] diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index bc742b9221..a358da460c 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -310,6 +310,9 @@ other arguments if used). |input()| and |inputdialog()| support user-defined cmdline highlighting. +Commands: + |:doautocmd| does not warn about "No matching autocommands". + Highlight groups: |hl-ColorColumn|, |hl-CursorColumn| are lower priority than most other groups diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 2a6ceb50f6..b315639681 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4614,7 +4614,7 @@ static void ex_doautocmd(exarg_T *eap) int call_do_modelines = check_nomodeline(&arg); bool did_aucmd; - (void)do_doautocmd(arg, true, &did_aucmd); + (void)do_doautocmd(arg, false, &did_aucmd); // Only when there is no <nomodeline>. if (call_do_modelines && did_aucmd) { do_modelines(0); diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7d8342c4dd..f7614fd3e1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3558,11 +3558,9 @@ set_context_in_map_cmd ( return NULL; } -/* - * Find all mapping/abbreviation names that match regexp 'prog'. - * For command line expansion of ":[un]map" and ":[un]abbrev" in all modes. - * Return OK if matches found, FAIL otherwise. - */ +// Find all mapping/abbreviation names that match regexp "regmatch". +// For command line expansion of ":[un]map" and ":[un]abbrev" in all modes. +// Return OK if matches found, FAIL otherwise. int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) { mapblock_T *mp; @@ -3622,7 +3620,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) mp = maphash[hash]; for (; mp; mp = mp->m_next) { if (mp->m_mode & expand_mapmodes) { - p = translate_mapping(mp->m_keys, true, CPO_TO_CPO_FLAGS); + p = translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS); if (p != NULL && vim_regexec(regmatch, p, (colnr_T)0)) { if (round == 1) ++count; @@ -4346,16 +4344,15 @@ void add_map(char_u *map, int mode) // corresponding external one recognized by :map/:abbrev commands. // // This function is called when expanding mappings/abbreviations on the -// command-line, and for building the "Ambiguous mapping..." error message. +// command-line. // -// It uses a growarray to build the translation string since the -// latter can be wider than the original description. The caller has to -// free the string afterwards. +// It uses a growarray to build the translation string since the latter can be +// wider than the original description. The caller has to free the string +// afterwards. // // Returns NULL when there is a problem. static char_u * translate_mapping ( char_u *str, - int expmap, // True when expanding mappings on command-line int cpo_flags // Value of various flags present in &cpo ) { @@ -4373,12 +4370,8 @@ static char_u * translate_mapping ( modifiers = *++str; c = *++str; } - + if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) { - if (expmap) { - ga_clear(&ga); - return NULL; - } c = TO_SPECIAL(str[1], str[2]); if (c == K_ZERO) { // display <Nul> as ^@ @@ -4387,10 +4380,6 @@ static char_u * translate_mapping ( str += 2; } if (IS_SPECIAL(c) || modifiers) { // special key - if (expmap) { - ga_clear(&ga); - return NULL; - } ga_concat(&ga, get_special_key_name(c, modifiers)); continue; /* for (str) */ } diff --git a/src/nvim/search.c b/src/nvim/search.c index 85de7f26de..7d46b3b4d5 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1130,7 +1130,7 @@ int do_search( && !cmd_silent && msg_silent == 0) { char_u *trunc; char_u off_buf[40]; - int off_len = 0; + size_t off_len = 0; // Compute msg_row early. msg_start(); @@ -1170,10 +1170,10 @@ int do_search( len = 0; // adjusted below } else if (msg_scrolled != 0) { // Use all the columns. - len = (int)(Rows - msg_row) * Columns - 1; + len = (Rows - msg_row) * Columns - 1; } else { // Use up to 'showcmd' column. - len = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; + len = (Rows - msg_row - 1) * Columns + sc_col - 1; } if (len < STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3) { len = STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3; @@ -1183,7 +1183,7 @@ int do_search( len = STRLEN(p) + off_len + 3; } - msgbuf = xmalloc((int)len); + msgbuf = xmalloc(len); { memset(msgbuf, ' ', len); msgbuf[0] = dirc; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index ddd0643feb..b686d0292f 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1673,6 +1673,25 @@ func Test_ReadWrite_Autocmds() call delete('test.out') endfunc +func Test_throw_in_BufWritePre() + new + call setline(1, ['one', 'two', 'three']) + call assert_false(filereadable('Xthefile')) + augroup throwing + au BufWritePre X* throw 'do not write' + augroup END + try + w Xthefile + catch + let caught = 1 + endtry + call assert_equal(1, caught) + call assert_false(filereadable('Xthefile')) + + bwipe! + au! throwing +endfunc + func Test_FileChangedShell_reload() if !has('unix') return diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index eb18284b4a..4b333e444a 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -44,6 +44,42 @@ func Test_map_completion() call assert_equal('"map <special> <nowait>', getreg(':')) call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') call assert_equal('"map <silent> <special>', getreg(':')) + + map ,f commaf + map ,g commaf + call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map ,f', getreg(':')) + call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map ,g', getreg(':')) + unmap ,f + unmap ,g + + set cpo-=< cpo-=B cpo-=k + map <Left> left + call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <Left>', getreg(':')) + unmap <Left> + + " set cpo+=< + map <Left> left + call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <Left>', getreg(':')) + unmap <Left> + set cpo-=< + + set cpo+=B + map <Left> left + call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <Left>', getreg(':')) + unmap <Left> + set cpo-=B + + " set cpo+=k + map <Left> left + call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <Left>', getreg(':')) + unmap <Left> + " set cpo-=k endfunc func Test_match_completion() diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 07218f11dd..dbe9f20412 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -181,7 +181,7 @@ describe('server -> client', function() end) describe('recursive (child) nvim client', function() - if os.getenv("TRAVIS") and helpers.os_name() == "osx" then + if helpers.isCI('travis') and helpers.os_name() == 'osx' then -- XXX: Hangs Travis macOS since e9061117a5b8f195c3f26a5cb94e18ddd7752d86. pending("[Hangs on Travis macOS. #5002]", function() end) return @@ -340,7 +340,7 @@ describe('server -> client', function() describe('connecting to its own pipe address', function() it('does not deadlock', function() - if not os.getenv("TRAVIS") and helpers.os_name() == "osx" then + if not helpers.isCI('travis') and helpers.os_name() == 'osx' then -- It does, in fact, deadlock on QuickBuild. #6851 pending("deadlocks on QuickBuild", function() end) return diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 20538d7141..0a583b6d8d 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -260,4 +260,26 @@ describe('autocmd', function() eq({false, 'Vim(call):E5555: API call: Invalid window id'}, meth_pcall(command, "call nvim_set_current_win(g:winid)")) end) + + it(':doautocmd does not warn "No matching autocommands" #10689', function() + local screen = Screen.new(32, 3) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + }) + + feed(':doautocmd User Foo<cr>') + screen:expect{grid=[[ + ^ | + {1:~ }| + :doautocmd User Foo | + ]]} + feed(':autocmd! SessionLoadPost<cr>') + feed(':doautocmd SessionLoadPost<cr>') + screen:expect{grid=[[ + ^ | + {1:~ }| + :doautocmd SessionLoadPost | + ]]} + end) end) diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua index 26f2b5da1b..50bcf1af5a 100644 --- a/test/functional/autocmd/termclose_spec.lua +++ b/test/functional/autocmd/termclose_spec.lua @@ -22,7 +22,7 @@ describe('TermClose event', function() command('terminal') -- shell-test exits immediately. retry(nil, nil, function() neq(-1, eval('jobwait([&channel], 0)[0]')) end) - eq(23, eval('g:test_termclose')) + retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) end) it('triggers when long-running terminal job gets stopped', function() diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 2b00327f14..212b76b5d9 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -205,7 +205,7 @@ describe('jobs', function() end) it("will not buffer data if it doesn't end in newlines", function() - if os.getenv("TRAVIS") and os.getenv("CC") == "gcc-4.9" + if helpers.isCI('travis') and os.getenv('CC') == 'gcc-4.9' and helpers.os_name() == "osx" then -- XXX: Hangs Travis macOS since e9061117a5b8f195c3f26a5cb94e18ddd7752d86. pending("[Hangs on Travis macOS. #5002]", function() end) diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 4c5383b712..f65d9f0d01 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -11,7 +11,7 @@ describe("CTRL-C (mapped)", function() it("interrupts :global", function() -- Crashes luajit. if helpers.skip_fragile(pending, - os.getenv("TRAVIS") or os.getenv("APPVEYOR")) then + helpers.isCI('travis') or helpers.isCI('appveyor')) then return end diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index b25bd7e85a..d95995797e 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local plugin_helpers = require('test.functional.plugin.helpers') local Screen = require('test.functional.ui.screen') local command, eval, rawfeed = helpers.command, helpers.eval, helpers.rawfeed local clear = helpers.clear @@ -9,7 +8,6 @@ describe(':Man', function() local screen before_each(function() - plugin_helpers.reset() clear() command('syntax on') command('set filetype=man') diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index 38c4527a5b..9a30ea73c4 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -52,7 +52,7 @@ describe("shell command :!", function() it("throttles shell-command output greater than ~10KB", function() if helpers.skip_fragile(pending, - (os.getenv("TRAVIS") and helpers.os_name() == "osx")) then + (helpers.isCI('travis') and helpers.os_name() == 'osx')) then return end child_session.feed_data( diff --git a/test/helpers.lua b/test/helpers.lua index 5739b42fe6..e14bcff2c8 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -674,11 +674,13 @@ function module.write_file(name, text, no_dedent, append) file:close() end -function module.isCI() - local is_travis = nil ~= os.getenv('TRAVIS') - local is_appveyor = nil ~= os.getenv('APPVEYOR') - local is_quickbuild = nil ~= lfs.attributes('/usr/home/quickbuild') - return is_travis or is_appveyor or is_quickbuild +function module.isCI(name) + local any = (name == nil) + assert(any or name == 'appveyor' or name == 'quickbuild' or name == 'travis') + local av = ((any or name == 'appveyor') and nil ~= os.getenv('APPVEYOR')) + local tr = ((any or name == 'travis') and nil ~= os.getenv('TRAVIS')) + local qb = ((any or name == 'quickbuild') and nil ~= lfs.attributes('/usr/home/quickbuild')) + return tr or av or qb end -- Gets the contents of $NVIM_LOG_FILE for printing to the build log. diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua index 3e65537270..1ff1bed9fe 100644 --- a/test/unit/mbyte_spec.lua +++ b/test/unit/mbyte_spec.lua @@ -8,6 +8,9 @@ local mbyte = helpers.cimport("./src/nvim/mbyte.h") local charset = helpers.cimport('./src/nvim/charset.h') describe('mbyte', function() + if helpers.isCI('quickbuild') then + pending("crashes on quickbuild", function() end) + end -- Array for composing characters local intp = ffi.typeof('int[?]') |