diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt index 7a1649a74b..0bf04034ec 100644 --- a/runtime/doc/quickfix.txt +++ b/runtime/doc/quickfix.txt @@ -1246,7 +1246,7 @@ not "b:current_compiler". What the command actually does is the following: - Delete the "current_compiler" and "b:current_compiler" variables. - Define the "CompilerSet" user command. With "!" it does ":set", without "!" it does ":setlocal". -- Execute ":runtime! compiler/{name}.(vim|lua)". The plugins are expected to +- Execute ":runtime! compiler/{name}.{vim,lua}". The plugins are expected to set options with "CompilerSet" and set the "current_compiler" variable to the name of the compiler. - Delete the "CompilerSet" user command. diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index a66d77910b..53f6904170 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -225,15 +225,15 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|. When {file} contains wildcards it is expanded to all matching files. Example: > - :runtime! plugin/**/*.vim -< This is what Vim uses to load the plugin files when + :runtime! plugin/**/*.{vim,lua} +< This is what Nvim uses to load the plugin files when starting up. This similar command: > - :runtime plugin/**/*.vim + :runtime plugin/**/*.{vim,lua} < would source the first file only. - For each {file} pattern, if a file has both a `.vim` - and `.lua` extensions, the `.vim` version will be sourced - first. + For each {file} pattern, if two `.vim` and `.lua` file + names match and differ only in extension, the `.vim` + file is sourced first. When 'verbose' is one or higher, there is a message when no file could be found. diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 09c935cb9b..631e666b6a 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -4895,8 +4895,8 @@ in their own color. output "default". :colo[rscheme] {name} Load color scheme {name}. This searches 'runtimepath' - for the file "colors/{name}.(vim|lua)". The first one that - is found is loaded. + for the file "colors/{name}.{vim,lua}". The first one + that is found is loaded. Note: "colors/{name}.vim" is tried first. Also searches all plugins in 'packpath', first below "start" and then under "opt". diff --git a/runtime/filetype.lua b/runtime/filetype.lua index f772785d21..cf5fe39656 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -32,8 +32,7 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { if not vim.g.did_load_ftdetect then vim.cmd([[ augroup filetypedetect - runtime! ftdetect/*.vim - runtime! ftdetect/*.lua + runtime! ftdetect/*.{vim,lua} augroup END ]]) end diff --git a/runtime/ftplugin.vim b/runtime/ftplugin.vim index f5c411fbe6..7b55134a4b 100644 --- a/runtime/ftplugin.vim +++ b/runtime/ftplugin.vim @@ -30,10 +30,8 @@ augroup filetypeplugin for name in split(s, '\.') " Load Lua ftplugins after Vim ftplugins _per directory_ " TODO(clason): use nvim__get_runtime when supports globs and modeline - exe printf('runtime! ftplugin/%s.vim ftplugin/%s.lua - \ ftplugin/%s_*.vim ftplugin/%s_*.lua - \ ftplugin/%s/*.vim ftplugin/%s/*.lua', - \ name, name, name, name, name, name) + " XXX: "[.]" in the first pattern makes it a wildcard on Windows + exe $'runtime! ftplugin/{name}[.]{{vim,lua}} ftplugin/{name}_*.{{vim,lua}} ftplugin/{name}/*.{{vim,lua}}' endfor endif endfunc diff --git a/runtime/indent.vim b/runtime/indent.vim index 2b64dd44b9..e4ddc09401 100644 --- a/runtime/indent.vim +++ b/runtime/indent.vim @@ -24,8 +24,8 @@ augroup filetypeindent " When there is a dot it is used to separate filetype names. Thus for " "aaa.bbb" load "indent/aaa.vim" and then "indent/bbb.vim". for name in split(s, '\.') - exe 'runtime! indent/' . name . '.vim' - exe 'runtime! indent/' . name . '.lua' + " XXX: "[.]" in the pattern makes it a wildcard on Windows + exe $'runtime! indent/{name}[.]{{vim,lua}}' endfor endif endfunc diff --git a/runtime/syntax/synload.vim b/runtime/syntax/synload.vim index 056e38bf79..80685a5213 100644 --- a/runtime/syntax/synload.vim +++ b/runtime/syntax/synload.vim @@ -48,8 +48,8 @@ fun! s:SynSet() " load each in sequence. Skip empty entries. for name in split(s, '\.') if !empty(name) - exe "runtime! syntax/" . name . ".vim syntax/" . name . "/*.vim" - exe "runtime! syntax/" . name . ".lua syntax/" . name . "/*.lua" + " XXX: "[.]" in the first pattern makes it a wildcard on Windows + exe $'runtime! syntax/{name}[.]{{vim,lua}} syntax/{name}/*.{{vim,lua}}' endif endfor endif diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index eac483b8e7..9cd4a17b27 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -1067,21 +1067,22 @@ theend: /// Load scripts in "plugin" directory of the package. /// For opt packages, also load scripts in "ftdetect" (start packages already -/// load these from filetype.vim) +/// load these from filetype.lua) static int load_pack_plugin(bool opt, char *fname) { - static const char *ftpat = "%s/ftdetect/*"; // NOLINT + static const char plugpat[] = "%s/plugin/**/*"; // NOLINT + static const char ftpat[] = "%s/ftdetect/*"; // NOLINT char *const ffname = fix_fname(fname); - size_t len = strlen(ffname) + strlen(ftpat); + size_t len = strlen(ffname) + sizeof(plugpat); char *pat = xmallocz(len); - vim_snprintf(pat, len, "%s/plugin/**/*", ffname); // NOLINT + vim_snprintf(pat, len, plugpat, ffname); // NOLINT gen_expand_wildcards_and_cb(1, &pat, EW_FILE, true, source_callback_vim_lua, NULL); char *cmd = xstrdup("g:did_load_filetypes"); - // If runtime/filetype.vim wasn't loaded yet, the scripts will be + // If runtime/filetype.lua wasn't loaded yet, the scripts will be // found when it loads. if (opt && eval_to_number(cmd) > 0) { do_cmdline_cmd("augroup filetypedetect"); @@ -1255,7 +1256,7 @@ void load_plugins(void) /// ":packadd[!] {name}" void ex_packadd(exarg_T *eap) { - static const char *plugpat = "pack/*/%s/%s"; // NOLINT + static const char plugpat[] = "pack/*/%s/%s"; // NOLINT int res = OK; // Round 1: use "start", round 2: use "opt". @@ -1265,7 +1266,7 @@ void ex_packadd(exarg_T *eap) continue; } - const size_t len = strlen(plugpat) + strlen(eap->arg) + 5; + const size_t len = sizeof(plugpat) + strlen(eap->arg) + 5; char *pat = xmallocz(len); vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); // The first round don't give a "not found" error, in the second round @@ -1367,11 +1368,11 @@ expand: /// Expand color scheme, compiler or filetype names. /// Search from 'runtimepath': -/// 'runtimepath'/{dirnames}/{pat}.(vim|lua) +/// 'runtimepath'/{dirnames}/{pat}.{vim,lua} /// When "flags" has DIP_START: search also from "start" of 'packpath': -/// 'packpath'/pack/*/start/*/{dirnames}/{pat}.(vim|lua) +/// 'packpath'/pack/*/start/*/{dirnames}/{pat}.{vim,lua} /// When "flags" has DIP_OPT: search also from "opt" of 'packpath': -/// 'packpath'/pack/*/opt/*/{dirnames}/{pat}.(vim|lua) +/// 'packpath'/pack/*/opt/*/{dirnames}/{pat}.{vim,lua} /// "dirnames" is an array with one or more directory names. int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirnames[]) { diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 3253854093..c541e32353 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -975,16 +975,23 @@ describe('runtime:', function() end) - it('loads ftdetect/*.lua', function() + it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function() local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep) - local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep) + local after_ftdetect_folder = table.concat({xconfig, 'nvim', 'after', 'ftdetect'}, pathsep) mkdir_p(ftdetect_folder) - write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]]) - - clear{ args_rm={'-u'}, env=xenv } - - eq(1, eval('g:lua_ftdetect')) - rmdir(ftdetect_folder) + mkdir_p(after_ftdetect_folder) + finally(function() + rmdir(ftdetect_folder) + rmdir(after_ftdetect_folder) + end) + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/ftdetect/ are loaded after all files in ftdetect/. + write_file(table.concat({ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'A']]) + write_file(table.concat({ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({after_ftdetect_folder, 'new-ft.vim'}, pathsep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_ftdetect_folder, 'new-ft.lua'}, pathsep), [[vim.g.seq = vim.g.seq .. 'b']]) + clear{ args_rm={'-u'}, args = {'--cmd', 'let g:seq = ""'}, env=xenv } + eq('ABab', eval('g:seq')) end) end) diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index aa682cad19..1f312fc513 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -19,6 +19,7 @@ describe('runtime:', function() clear{args = {'-u', init}} exec('set rtp+=' .. plug_dir) exec([[ + set shell=doesnotexist set completeslash=slash set isfname+=(,) ]]) @@ -43,8 +44,8 @@ describe('runtime:', function() mkdir_p(colorscheme_folder) end) - it('loads lua colorscheme', function() - local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme.lua' + it('lua colorschemes work and are included in cmdline completion', function() + local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep) write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]]) eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color')) @@ -55,17 +56,7 @@ describe('runtime:', function() eq(1, eval('g:lua_colorscheme')) end) - it('loads vim colorscheme when both lua and vim version exist', function() - local colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme' - write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']]) - write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']]) - - exec('colorscheme new_colorscheme') - - eq('vim', eval('g:colorscheme')) - end) - - it("loads lua colorscheme in 'rtp' if vim version only exists in 'pp' #23724", function() + it("'rtp'/'pp' order is respected", function() local pack_dir = 'Test_Pack' mkdir_p(pack_dir) finally(function() @@ -73,38 +64,53 @@ describe('runtime:', function() end) exec('set pp+=' .. pack_dir) - local pack_opt_dir = pack_dir .. sep .. 'pack' .. sep .. 'some_name' .. sep .. 'opt' - local colors_opt_dir = pack_opt_dir .. sep .. 'some_pack' .. sep .. 'colors' + local pack_opt_dir = table.concat({pack_dir, 'pack', 'some_name', 'opt'}, sep) + local colors_opt_dir = table.concat({pack_opt_dir, 'some_pack', 'colors'}, sep) mkdir_p(colors_opt_dir) - local rtp_colorscheme_file = colorscheme_folder .. sep .. 'new_colorscheme' - local pp_opt_colorscheme_file = colors_opt_dir .. sep .. 'new_colorscheme' + local after_colorscheme_folder = table.concat({plug_dir, 'after', 'colors'}, sep) + mkdir_p(after_colorscheme_folder) + exec('set rtp+=' .. plug_dir .. '/after') - write_file(pp_opt_colorscheme_file .. '.lua', [[vim.g.colorscheme = 'lua_pp']]) + write_file(table.concat({colors_opt_dir, 'new_colorscheme.lua'}, sep), + [[vim.g.colorscheme = 'lua_pp']]) exec('colorscheme new_colorscheme') eq('lua_pp', eval('g:colorscheme')) - write_file(pp_opt_colorscheme_file .. '.vim', [[let g:colorscheme = 'vim_pp']]) + write_file(table.concat({colors_opt_dir, 'new_colorscheme.vim'}, sep), + [[let g:colorscheme = 'vim_pp']]) exec('colorscheme new_colorscheme') eq('vim_pp', eval('g:colorscheme')) - write_file(rtp_colorscheme_file .. '.lua', [[vim.g.colorscheme = 'lua_rtp']]) + write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.lua'}, sep), + [[vim.g.colorscheme = 'lua_rtp_after']]) + exec('colorscheme new_colorscheme') + eq('lua_rtp_after', eval('g:colorscheme')) + + write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.vim'}, sep), + [[let g:colorscheme = 'vim_rtp_after']]) + exec('colorscheme new_colorscheme') + eq('vim_rtp_after', eval('g:colorscheme')) + + write_file(table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep), + [[vim.g.colorscheme = 'lua_rtp']]) exec('colorscheme new_colorscheme') eq('lua_rtp', eval('g:colorscheme')) - write_file(rtp_colorscheme_file .. '.vim', [[let g:colorscheme = 'vim_rtp']]) + write_file(table.concat({colorscheme_folder, 'new_colorscheme.vim'}, sep), + [[let g:colorscheme = 'vim_rtp']]) exec('colorscheme new_colorscheme') eq('vim_rtp', eval('g:colorscheme')) end) end) describe('compiler', function() - local compiler_folder = plug_dir .. sep .. 'compiler' + local compiler_folder = table.concat({plug_dir, 'compiler'}, sep) before_each(function() mkdir_p(compiler_folder) end) - it('loads lua compilers', function() + it('lua compilers work and are included in cmdline completion', function() local compiler_file = compiler_folder .. sep .. 'new_compiler.lua' write_file(compiler_file, [[vim.b.lua_compiler = 1]]) @@ -116,23 +122,27 @@ describe('runtime:', function() eq(1, eval('b:lua_compiler')) end) - it('loads vim compilers when both lua and vim version exist', function() - local compiler_file = compiler_folder .. sep .. 'new_compiler' - exec('let b:compiler = "compiler"') - write_file(compiler_file..'.vim', [[let b:compiler = b:compiler.'_vim']]) - write_file(compiler_file..'.lua', [[vim.b.compiler = vim.b.compiler..'_lua']]) - + it("'rtp' order is respected", function() + local after_compiler_folder = table.concat({plug_dir, 'after', 'compiler'}, sep) + mkdir_p(table.concat({compiler_folder, 'new_compiler'}, sep)) + mkdir_p(table.concat({after_compiler_folder, 'new_compiler'}, sep)) + exec('set rtp+=' .. plug_dir .. '/after') + exec('let g:seq = ""') + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/compiler/ are loaded after all files in compiler/. + write_file(table.concat({compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'A']]) + write_file(table.concat({compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({after_compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) exec('compiler new_compiler') - - -- lua version is sourced after vim - eq('compiler_vim_lua', eval('b:compiler')) + eq('ABab', eval('g:seq')) end) end) describe('ftplugin', function() local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep) - it('loads lua ftplugins', function() + it('lua ftplugins work and are included in cmdline completion', function() mkdir_p(ftplugin_folder) local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep) write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]]) @@ -172,7 +182,7 @@ describe('runtime:', function() describe('indent', function() local indent_folder = table.concat({plug_dir, 'indent'}, sep) - it('loads lua indents', function() + it('lua indents work and are included in cmdline completion', function() mkdir_p(indent_folder) local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep) write_file(indent_file , [[vim.b.lua_indent = 1]]) @@ -183,6 +193,22 @@ describe('runtime:', function() exec [[set filetype=new-ft]] eq(1, eval('b:lua_indent')) end) + + it("'rtp' order is respected", function() + local after_indent_folder = table.concat({plug_dir, 'after', 'indent'}, sep) + mkdir_p(table.concat({indent_folder, 'new-ft'}, sep)) + mkdir_p(table.concat({after_indent_folder, 'new-ft'}, sep)) + exec('set rtp+=' .. plug_dir .. '/after') + exec('let g:seq = ""') + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/indent/ are loaded after all files in indent/. + write_file(table.concat({indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']]) + write_file(table.concat({indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({after_indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) + exec('setfiletype new-ft') + eq('ABab', eval('g:seq')) + end) end) describe('syntax', function() @@ -216,22 +242,45 @@ describe('runtime:', function() eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax')) eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime')) end) + + it("'rtp' order is respected", function() + local after_syntax_folder = table.concat({plug_dir, 'after', 'syntax'}, sep) + mkdir_p(table.concat({syntax_folder, 'my-lang'}, sep)) + mkdir_p(table.concat({after_syntax_folder, 'my-lang'}, sep)) + exec('set rtp+=' .. plug_dir .. '/after') + exec('let g:seq = ""') + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/syntax/ are loaded after all files in syntax/. + write_file(table.concat({syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'A']]) + write_file(table.concat({syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'C']]) + write_file(table.concat({syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']]) + write_file(table.concat({after_syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) + write_file(table.concat({after_syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'c']]) + write_file(table.concat({after_syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']]) + exec('setfiletype my-lang') + eq('ABCDabcd', eval('g:seq')) + end) end) describe('spell', function() - local spell_folder = table.concat({plug_dir, 'spell'}, sep) - - it('loads spell/LANG.{vim,lua}', function() - mkdir_p(spell_folder) - local spell_vim = table.concat({spell_folder , 'Xtest.vim'}, sep) - write_file(spell_vim , [[let b:spell_vim = 1]]) - local spell_lua = table.concat({spell_folder , 'Xtest.lua'}, sep) - write_file(spell_lua , [[vim.b.spell_lua = 1]]) + it("loads spell/LANG.{vim,lua} respecting 'rtp' order", function() + local spell_folder = table.concat({plug_dir, 'spell'}, sep) + local after_spell_folder = table.concat({plug_dir, 'after', 'spell'}, sep) + mkdir_p(table.concat({spell_folder, 'Xtest'}, sep)) + mkdir_p(table.concat({after_spell_folder, 'Xtest'}, sep)) + exec('set rtp+=' .. plug_dir .. '/after') + exec('let g:seq = ""') + -- A .lua file is loaded after a .vim file if they only differ in extension. + -- All files in after/spell/ are loaded after all files in spell/. + write_file(table.concat({spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'A']]) + write_file(table.concat({spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({after_spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'a']]) + write_file(table.concat({after_spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) exec('set spelllang=Xtest') - eq(1, eval('b:spell_vim')) - eq(1, eval('b:spell_lua')) + eq('ABab', eval('g:seq')) end) end) end) -