feat(runtime): Allow lua to be used in ftplugin

This commit is contained in:
shadmansaleh 2021-06-02 16:25:50 +06:00
parent 68be8b99cf
commit fd5e5d2715
3 changed files with 25 additions and 2 deletions

View File

@ -411,7 +411,7 @@ Examples for the "stuff" filetype on Unix: >
The <filetype> part is the name of the filetype the plugin is to be used for.
Only files of this filetype will use the settings from the plugin. The <name>
part of the plugin file doesn't matter, you can use it to have several plugins
for the same filetype. Note that it must end in ".vim".
for the same filetype. Note that it must end in ".vim" or ".lua".
Further reading:

View File

@ -28,7 +28,9 @@ augroup filetypeplugin
" When there is a dot it is used to separate filetype names. Thus for
" "aaa.bbb" load "aaa" and then "bbb".
for name in split(s, '\.')
exe 'runtime! ftplugin/' . name . '.vim ftplugin/' . name . '_*.vim ftplugin/' . name . '/*.vim'
exe 'runtime! ftplugin/' . name . '.vim ftplugin/' . name . '_*.vim ftplugin/' . name . '/*.vim'
" Load lua ftplugins
exe printf('runtime! ftplugin/%s.lua ftplugin/%s_*.lua ftplugin/%s/*.lua', name, name, name)
endfor
endif
endfunc

View File

@ -23,6 +23,7 @@ describe('runtime:', function()
end)
describe('plugin', function()
before_each(clear)
it('loads plugin/*.lua from XDG config home', function()
local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
@ -53,6 +54,7 @@ describe('runtime:', function()
end)
describe('colors', function()
before_each(clear)
it('loads lua colorscheme', function()
local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
pathsep)
@ -87,6 +89,7 @@ describe('runtime:', function()
describe('compiler', function()
local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep)
before_each(clear)
it('loads lua compilers', function()
local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'},
@ -115,5 +118,23 @@ describe('runtime:', function()
rmdir(compiler_folder)
end)
end)
describe('ftplugin', function()
local ftplugin_folder = table.concat({xconfig, 'nvim', 'ftplugin'}, pathsep)
before_each(clear)
it('loads lua ftplugins', function()
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep)
mkdir_p(ftplugin_folder)
write_file(ftplugin_file , [[ vim.g.lua_ftplugin = 1 ]])
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
exec [[set filetype=new-ft]]
eq(1, eval('g:lua_ftplugin'))
rmdir(ftplugin_folder)
end)
end)
end)