mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
fix(events): don't expand non-file as file name
This commit is contained in:
@ -1676,6 +1676,7 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
|
|||||||
|| event == EVENT_USER || event == EVENT_WINCLOSED
|
|| event == EVENT_USER || event == EVENT_WINCLOSED
|
||||||
|| event == EVENT_WINRESIZED || event == EVENT_WINSCROLLED) {
|
|| event == EVENT_WINRESIZED || event == EVENT_WINSCROLLED) {
|
||||||
fname = xstrdup(fname);
|
fname = xstrdup(fname);
|
||||||
|
autocmd_fname_full = true; // don't expand it later
|
||||||
} else {
|
} else {
|
||||||
fname = FullName_save(fname, false);
|
fname = FullName_save(fname, false);
|
||||||
}
|
}
|
||||||
|
@ -2087,17 +2087,17 @@ char *path_shorten_fname(char *full_path, char *dir_name)
|
|||||||
assert(dir_name != NULL);
|
assert(dir_name != NULL);
|
||||||
size_t len = strlen(dir_name);
|
size_t len = strlen(dir_name);
|
||||||
|
|
||||||
// If dir_name is a path head, full_path can always be made relative.
|
|
||||||
if (len == (size_t)path_head_length() && is_path_head(dir_name)) {
|
|
||||||
return full_path + len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If full_path and dir_name do not match, it's impossible to make one
|
// If full_path and dir_name do not match, it's impossible to make one
|
||||||
// relative to the other.
|
// relative to the other.
|
||||||
if (path_fnamencmp(dir_name, full_path, len) != 0) {
|
if (path_fnamencmp(dir_name, full_path, len) != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If dir_name is a path head, full_path can always be made relative.
|
||||||
|
if (len == (size_t)path_head_length() && is_path_head(dir_name)) {
|
||||||
|
return full_path + len;
|
||||||
|
}
|
||||||
|
|
||||||
char *p = full_path + len;
|
char *p = full_path + len;
|
||||||
|
|
||||||
// If *p is not pointing to a path separator, this means that full_path's
|
// If *p is not pointing to a path separator, this means that full_path's
|
||||||
|
@ -228,23 +228,28 @@ describe('autocmd api', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('receives an args table', function()
|
it('receives an args table', function()
|
||||||
local res = exec_lua [[
|
local group_id = meths.create_augroup("TestGroup", {})
|
||||||
local group_id = vim.api.nvim_create_augroup("TestGroup", {})
|
-- Having an existing autocmd calling expand("<afile>") shouldn't change args #18964
|
||||||
local autocmd_id = vim.api.nvim_create_autocmd("User", {
|
meths.create_autocmd('User', {
|
||||||
|
group = 'TestGroup',
|
||||||
|
pattern = 'Te*',
|
||||||
|
command = 'call expand("<afile>")',
|
||||||
|
})
|
||||||
|
|
||||||
|
local autocmd_id = exec_lua [[
|
||||||
|
return vim.api.nvim_create_autocmd("User", {
|
||||||
group = "TestGroup",
|
group = "TestGroup",
|
||||||
pattern = "Te*",
|
pattern = "Te*",
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
vim.g.autocmd_args = args
|
vim.g.autocmd_args = args
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {group_id, autocmd_id}
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
meths.exec_autocmds("User", {pattern = "Test pattern"})
|
meths.exec_autocmds("User", {pattern = "Test pattern"})
|
||||||
eq({
|
eq({
|
||||||
id = res[2],
|
id = autocmd_id,
|
||||||
group = res[1],
|
group = group_id,
|
||||||
event = "User",
|
event = "User",
|
||||||
match = "Test pattern",
|
match = "Test pattern",
|
||||||
file = "Test pattern",
|
file = "Test pattern",
|
||||||
@ -252,27 +257,24 @@ describe('autocmd api', function()
|
|||||||
}, meths.get_var("autocmd_args"))
|
}, meths.get_var("autocmd_args"))
|
||||||
|
|
||||||
-- Test without a group
|
-- Test without a group
|
||||||
res = exec_lua [[
|
autocmd_id = exec_lua [[
|
||||||
local autocmd_id = vim.api.nvim_create_autocmd("User", {
|
return vim.api.nvim_create_autocmd("User", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
vim.g.autocmd_args = args
|
vim.g.autocmd_args = args
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {autocmd_id}
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
meths.exec_autocmds("User", {pattern = "some_pat"})
|
meths.exec_autocmds("User", {pattern = "some_pat"})
|
||||||
eq({
|
eq({
|
||||||
id = res[1],
|
id = autocmd_id,
|
||||||
group = nil,
|
group = nil,
|
||||||
event = "User",
|
event = "User",
|
||||||
match = "some_pat",
|
match = "some_pat",
|
||||||
file = "some_pat",
|
file = "some_pat",
|
||||||
buf = 1,
|
buf = 1,
|
||||||
}, meths.get_var("autocmd_args"))
|
}, meths.get_var("autocmd_args"))
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can receive arbitrary data', function()
|
it('can receive arbitrary data', function()
|
||||||
|
Reference in New Issue
Block a user