mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5933 from justinmk/dir-bufenter
open_buffer(): Raise `BufEnter` for directories.
This commit is contained in:
commit
f686635420
@ -189,14 +189,18 @@ open_buffer (
|
|||||||
curwin->w_cursor.lnum = 1;
|
curwin->w_cursor.lnum = 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
|
|
||||||
/* Set or reset 'modified' before executing autocommands, so that
|
// Set or reset 'modified' before executing autocommands, so that
|
||||||
* it can be changed there. */
|
// it can be changed there.
|
||||||
if (!readonlymode && !bufempty())
|
if (!readonlymode && !bufempty()) {
|
||||||
changed();
|
changed();
|
||||||
else if (retval != FAIL)
|
} else if (retval == OK) {
|
||||||
unchanged(curbuf, FALSE);
|
unchanged(curbuf, false);
|
||||||
apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
|
}
|
||||||
curbuf, &retval);
|
|
||||||
|
if (retval == OK) {
|
||||||
|
apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, false,
|
||||||
|
curbuf, &retval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,22 +210,21 @@ open_buffer (
|
|||||||
parse_cino(curbuf);
|
parse_cino(curbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Set/reset the Changed flag first, autocmds may change the buffer.
|
||||||
* Set/reset the Changed flag first, autocmds may change the buffer.
|
// Apply the automatic commands, before processing the modelines.
|
||||||
* Apply the automatic commands, before processing the modelines.
|
// So the modelines have priority over auto commands.
|
||||||
* So the modelines have priority over auto commands.
|
|
||||||
*/
|
// When reading stdin, the buffer contents always needs writing, so set
|
||||||
/* When reading stdin, the buffer contents always needs writing, so set
|
// the changed flag. Unless in readonly mode: "ls | nvim -R -".
|
||||||
* the changed flag. Unless in readonly mode: "ls | nvim -R -".
|
// When interrupted and 'cpoptions' contains 'i' set changed flag.
|
||||||
* When interrupted and 'cpoptions' contains 'i' set changed flag. */
|
|
||||||
if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
|
if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
|
||||||
|| modified_was_set /* ":set modified" used in autocmd */
|
|| modified_was_set // ":set modified" used in autocmd
|
||||||
|| (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
|
|| (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)) {
|
||||||
)
|
|
||||||
changed();
|
changed();
|
||||||
else if (retval != FAIL && !read_stdin)
|
} else if (retval == OK && !read_stdin) {
|
||||||
unchanged(curbuf, FALSE);
|
unchanged(curbuf, false);
|
||||||
save_file_ff(curbuf); /* keep this fileformat */
|
}
|
||||||
|
save_file_ff(curbuf); // keep this fileformat
|
||||||
|
|
||||||
/* require "!" to overwrite the file, because it wasn't read completely */
|
/* require "!" to overwrite the file, because it wasn't read completely */
|
||||||
if (aborting())
|
if (aborting())
|
||||||
|
@ -1193,8 +1193,8 @@ static void do_filter(
|
|||||||
|
|
||||||
if (do_out) {
|
if (do_out) {
|
||||||
if (otmp != NULL) {
|
if (otmp != NULL) {
|
||||||
if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM,
|
if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap,
|
||||||
eap, READ_FILTER) == FAIL) {
|
READ_FILTER) != OK) {
|
||||||
if (!aborting()) {
|
if (!aborting()) {
|
||||||
msg_putchar('\n');
|
msg_putchar('\n');
|
||||||
EMSG2(_(e_notread), otmp);
|
EMSG2(_(e_notread), otmp);
|
||||||
|
@ -6910,9 +6910,10 @@ static void ex_read(exarg_T *eap)
|
|||||||
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
|
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (i == FAIL) {
|
if (i != OK) {
|
||||||
if (!aborting())
|
if (!aborting()) {
|
||||||
EMSG2(_(e_notopen), eap->arg);
|
EMSG2(_(e_notopen), eap->arg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty && exmode_active) {
|
if (empty && exmode_active) {
|
||||||
/* Delete the empty line that remains. Historically ex does
|
/* Delete the empty line that remains. Historically ex does
|
||||||
|
@ -249,7 +249,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr)
|
|||||||
* READ_DUMMY read into a dummy buffer (to check if file contents changed)
|
* READ_DUMMY read into a dummy buffer (to check if file contents changed)
|
||||||
* READ_KEEP_UNDO don't clear undo info or read it from a file
|
* READ_KEEP_UNDO don't clear undo info or read it from a file
|
||||||
*
|
*
|
||||||
* return FAIL for failure, OK otherwise
|
* return FAIL for failure, NOTDONE for directory (failure), or OK
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
readfile (
|
readfile (
|
||||||
@ -258,7 +258,7 @@ readfile (
|
|||||||
linenr_T from,
|
linenr_T from,
|
||||||
linenr_T lines_to_skip,
|
linenr_T lines_to_skip,
|
||||||
linenr_T lines_to_read,
|
linenr_T lines_to_read,
|
||||||
exarg_T *eap, /* can be NULL! */
|
exarg_T *eap, // can be NULL!
|
||||||
int flags
|
int flags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -444,13 +444,14 @@ readfile (
|
|||||||
// ... or a character special file named /dev/fd/<n>
|
// ... or a character special file named /dev/fd/<n>
|
||||||
# endif
|
# endif
|
||||||
) {
|
) {
|
||||||
if (S_ISDIR(perm))
|
if (S_ISDIR(perm)) {
|
||||||
filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
|
filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
|
||||||
else
|
} else {
|
||||||
filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
|
filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
|
||||||
|
}
|
||||||
msg_end();
|
msg_end();
|
||||||
msg_scroll = msg_save;
|
msg_scroll = msg_save;
|
||||||
return FAIL;
|
return S_ISDIR(perm) ? NOTDONE : FAIL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -5104,13 +5105,13 @@ void buf_reload(buf_T *buf, int orig_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (saved == OK) {
|
if (saved == OK) {
|
||||||
curbuf->b_flags |= BF_CHECK_RO; /* check for RO again */
|
curbuf->b_flags |= BF_CHECK_RO; // check for RO again
|
||||||
keep_filetype = TRUE; /* don't detect 'filetype' */
|
keep_filetype = true; // don't detect 'filetype'
|
||||||
if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
|
if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, (linenr_T)0,
|
||||||
(linenr_T)0,
|
(linenr_T)MAXLNUM, &ea, flags) != OK) {
|
||||||
(linenr_T)MAXLNUM, &ea, flags) == FAIL) {
|
if (!aborting()) {
|
||||||
if (!aborting())
|
|
||||||
EMSG2(_("E321: Could not reload \"%s\""), buf->b_fname);
|
EMSG2(_("E321: Could not reload \"%s\""), buf->b_fname);
|
||||||
|
}
|
||||||
if (savebuf != NULL && buf_valid(savebuf) && buf == curbuf) {
|
if (savebuf != NULL && buf_valid(savebuf) && buf == curbuf) {
|
||||||
/* Put the text back from the save buffer. First
|
/* Put the text back from the save buffer. First
|
||||||
* delete any lines that readfile() added. */
|
* delete any lines that readfile() added. */
|
||||||
|
@ -1063,11 +1063,12 @@ void ml_recover(void)
|
|||||||
if (!cannot_open) {
|
if (!cannot_open) {
|
||||||
line_count = pp->pb_pointer[idx].pe_line_count;
|
line_count = pp->pb_pointer[idx].pe_line_count;
|
||||||
if (readfile(curbuf->b_ffname, NULL, lnum,
|
if (readfile(curbuf->b_ffname, NULL, lnum,
|
||||||
pp->pb_pointer[idx].pe_old_lnum - 1,
|
pp->pb_pointer[idx].pe_old_lnum - 1, line_count,
|
||||||
line_count, NULL, 0) == FAIL)
|
NULL, 0) != OK) {
|
||||||
cannot_open = TRUE;
|
cannot_open = true;
|
||||||
else
|
} else {
|
||||||
lnum += line_count;
|
lnum += line_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (cannot_open) {
|
if (cannot_open) {
|
||||||
++error;
|
++error;
|
||||||
|
@ -8,8 +8,6 @@ local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.fu
|
|||||||
local source, next_message = helpers.source, helpers.next_message
|
local source, next_message = helpers.source, helpers.next_message
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('server -> client', function()
|
describe('server -> client', function()
|
||||||
local cid
|
local cid
|
||||||
|
|
||||||
@ -212,6 +210,8 @@ describe('server -> client', function()
|
|||||||
funcs.jobstop(jobid)
|
funcs.jobstop(jobid)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
it('rpc and text stderr can be combined', function()
|
it('rpc and text stderr can be combined', function()
|
||||||
eq("ok",funcs.rpcrequest(jobid, "poll"))
|
eq("ok",funcs.rpcrequest(jobid, "poll"))
|
||||||
funcs.rpcnotify(jobid, "ping")
|
funcs.rpcnotify(jobid, "ping")
|
||||||
|
35
test/functional/autocmd/bufenter_spec.lua
Normal file
35
test/functional/autocmd/bufenter_spec.lua
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local clear = helpers.clear
|
||||||
|
local command = helpers.command
|
||||||
|
local eq = helpers.eq
|
||||||
|
local eval = helpers.eval
|
||||||
|
local execute = helpers.execute
|
||||||
|
local request = helpers.request
|
||||||
|
local source = helpers.source
|
||||||
|
|
||||||
|
describe('autocmd BufEnter', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it("triggered by nvim_command('edit <dir>')", function()
|
||||||
|
command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
|
||||||
|
request("nvim_command", "split .")
|
||||||
|
eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
|
||||||
|
eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('triggered by "try|:split <dir>|endtry" in a function', function()
|
||||||
|
command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
|
||||||
|
source([[
|
||||||
|
function! Test()
|
||||||
|
try
|
||||||
|
exe 'split .'
|
||||||
|
catch
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
]])
|
||||||
|
execute("call Test()")
|
||||||
|
eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
|
||||||
|
eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
|
||||||
|
end)
|
||||||
|
end)
|
@ -5,8 +5,6 @@ local command = helpers.command
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('autocmd TabNew', function()
|
describe('autocmd TabNew', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@ -19,12 +17,11 @@ describe('autocmd TabNew', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('matches when opening a new tab for FILE', function()
|
it('matches when opening a new tab for FILE', function()
|
||||||
local tmp_path = helpers.funcs.tempname()
|
|
||||||
command('let g:test = "foo"')
|
command('let g:test = "foo"')
|
||||||
command('autocmd! TabNew ' .. tmp_path .. ' let g:test = "bar"')
|
command('autocmd! TabNew Xtest-tabnew let g:test = "bar"')
|
||||||
command('tabnew ' .. tmp_path ..'X')
|
command('tabnew Xtest-tabnewX')
|
||||||
eq('foo', eval('g:test'))
|
eq('foo', eval('g:test'))
|
||||||
command('tabnew ' .. tmp_path)
|
command('tabnew Xtest-tabnew')
|
||||||
eq('bar', eval('g:test'))
|
eq('bar', eval('g:test'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
|
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('TabNewEntered', function()
|
describe('TabNewEntered', function()
|
||||||
describe('au TabNewEntered', function()
|
describe('au TabNewEntered', function()
|
||||||
describe('with * as <afile>', function()
|
describe('with * as <afile>', function()
|
||||||
@ -15,9 +13,9 @@ describe('TabNewEntered', function()
|
|||||||
end)
|
end)
|
||||||
describe('with FILE as <afile>', function()
|
describe('with FILE as <afile>', function()
|
||||||
it('matches when opening a new tab for FILE', function()
|
it('matches when opening a new tab for FILE', function()
|
||||||
local tmp_path = nvim('eval', 'tempname()')
|
nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
|
||||||
nvim('command', 'au! TabNewEntered '..tmp_path..' echom "tabnewentered:match"')
|
eq('\n"Xtest-tabnewentered" [New File]\ntabnewentered:4:4\ntabnewentered:match',
|
||||||
eq("\n\""..tmp_path.."\" [New File]\ntabnewentered:4:4\ntabnewentered:match", nvim('command_output', 'tabnew '..tmp_path))
|
nvim('command_output', 'tabnew Xtest-tabnewentered'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
describe('with CTRL-W T', function()
|
describe('with CTRL-W T', function()
|
||||||
|
@ -2,13 +2,14 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local clear, eq, next_msg, nvim, source = helpers.clear, helpers.eq,
|
local clear, eq, next_msg, nvim, source = helpers.clear, helpers.eq,
|
||||||
helpers.next_message, helpers.nvim, helpers.source
|
helpers.next_message, helpers.nvim, helpers.source
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('jobs with partials', function()
|
describe('jobs with partials', function()
|
||||||
local channel
|
local channel
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
clear()
|
||||||
|
if helpers.os_name() == 'windows' then
|
||||||
|
helpers.set_shell_powershell()
|
||||||
|
end
|
||||||
channel = nvim('get_api_info')[1]
|
channel = nvim('get_api_info')[1]
|
||||||
nvim('set_var', 'channel', channel)
|
nvim('set_var', 'channel', channel)
|
||||||
end)
|
end)
|
||||||
@ -16,12 +17,14 @@ describe('jobs with partials', function()
|
|||||||
it('works correctly', function()
|
it('works correctly', function()
|
||||||
source([[
|
source([[
|
||||||
function PrintArgs(a1, a2, id, data, event)
|
function PrintArgs(a1, a2, id, data, event)
|
||||||
call rpcnotify(g:channel, '1', a:a1, a:a2, a:data, a:event)
|
" Windows: Remove ^M char.
|
||||||
|
let normalized = map(a:data, 'substitute(v:val, "\r", "", "g")')
|
||||||
|
call rpcnotify(g:channel, '1', a:a1, a:a2, normalized, a:event)
|
||||||
endfunction
|
endfunction
|
||||||
let Callback = function('PrintArgs', ["foo", "bar"])
|
let Callback = function('PrintArgs', ["foo", "bar"])
|
||||||
let g:job_opts = {'on_stdout': Callback}
|
let g:job_opts = {'on_stdout': Callback}
|
||||||
call jobstart(['echo'], g:job_opts)
|
call jobstart('echo "some text"', g:job_opts)
|
||||||
]])
|
]])
|
||||||
eq({'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}}, next_msg())
|
eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -4,8 +4,6 @@ local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval
|
|||||||
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
||||||
local os_name = helpers.os_name
|
local os_name = helpers.os_name
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('serverstart(), serverstop()', function()
|
describe('serverstart(), serverstop()', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@ -42,8 +40,8 @@ describe('serverstart(), serverstop()', function()
|
|||||||
|
|
||||||
-- v:servername will take the next available server.
|
-- v:servername will take the next available server.
|
||||||
local servername = (os_name() == 'windows'
|
local servername = (os_name() == 'windows'
|
||||||
and [[\\.\pipe\Xtest-functional-server-server-pipe]]
|
and [[\\.\pipe\Xtest-functional-server-pipe]]
|
||||||
or 'Xtest-functional-server-server-socket')
|
or 'Xtest-functional-server-socket')
|
||||||
funcs.serverstart(servername)
|
funcs.serverstart(servername)
|
||||||
eq(servername, meths.get_vvar('servername'))
|
eq(servername, meths.get_vvar('servername'))
|
||||||
end)
|
end)
|
||||||
@ -63,9 +61,11 @@ describe('serverlist()', function()
|
|||||||
local n = eval('len(serverlist())')
|
local n = eval('len(serverlist())')
|
||||||
|
|
||||||
-- Add a few
|
-- Add a few
|
||||||
local servs = {'should-not-exist', 'another-one-that-shouldnt'}
|
local servs = (os_name() == 'windows'
|
||||||
|
and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] }
|
||||||
|
or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] })
|
||||||
for _, s in ipairs(servs) do
|
for _, s in ipairs(servs) do
|
||||||
eq(s, eval('serverstart("'..s..'")'))
|
eq(s, eval("serverstart('"..s.."')"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local new_servs = eval('serverlist()')
|
local new_servs = eval('serverlist()')
|
||||||
@ -75,10 +75,9 @@ describe('serverlist()', function()
|
|||||||
-- The new servers should be at the end of the list.
|
-- The new servers should be at the end of the list.
|
||||||
for i = 1, #servs do
|
for i = 1, #servs do
|
||||||
eq(servs[i], new_servs[i + n])
|
eq(servs[i], new_servs[i + n])
|
||||||
nvim('command', 'call serverstop("'..servs[i]..'")')
|
nvim('command', "call serverstop('"..servs[i].."')")
|
||||||
end
|
end
|
||||||
-- After calling serverstop() on the new servers, they should no longer be
|
-- After serverstop() the servers should NOT be in the list.
|
||||||
-- in the list.
|
|
||||||
eq(n, eval('len(serverlist())'))
|
eq(n, eval('len(serverlist())'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -346,6 +346,14 @@ local function source(code)
|
|||||||
return fname
|
return fname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function set_shell_powershell()
|
||||||
|
source([[
|
||||||
|
set shell=powershell shellquote=\" shellpipe=\| shellredir=>
|
||||||
|
set shellcmdflag=\ -ExecutionPolicy\ RemoteSigned\ -Command
|
||||||
|
let &shellxquote=' '
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
local function nvim(method, ...)
|
local function nvim(method, ...)
|
||||||
return request('nvim_'..method, ...)
|
return request('nvim_'..method, ...)
|
||||||
end
|
end
|
||||||
@ -590,6 +598,7 @@ return function(after_each)
|
|||||||
curtabmeths = curtabmeths,
|
curtabmeths = curtabmeths,
|
||||||
pending_win32 = pending_win32,
|
pending_win32 = pending_win32,
|
||||||
skip_fragile = skip_fragile,
|
skip_fragile = skip_fragile,
|
||||||
|
set_shell_powershell = set_shell_powershell,
|
||||||
tmpname = tmpname,
|
tmpname = tmpname,
|
||||||
NIL = mpack.NIL,
|
NIL = mpack.NIL,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user