diff options
author | brianhuster <phambinhanctb2004@gmail.com> | 2025-03-01 01:27:40 +0700 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2025-03-02 06:46:26 +0800 |
commit | 2b0f967b7704dcc782aebc99ec79482c20b5feef (patch) | |
tree | 92a7b9d5e70a208f27334feb7b739d0b0bb9b1f5 /runtime/ftplugin/lua.vim | |
parent | ea4a7cc616641a0ceaad402de57023009c26cf49 (diff) | |
download | rneovim-2b0f967b7704dcc782aebc99ec79482c20b5feef.tar.gz rneovim-2b0f967b7704dcc782aebc99ec79482c20b5feef.tar.bz2 rneovim-2b0f967b7704dcc782aebc99ec79482c20b5feef.zip |
vim-patch:00a00f5: runtime(lua): Update lua ftplugin and documentation
Problem:
- The doc says the default `g:lua_subversion` is 2, but in fact it is 3
(see `runtime/syntax/lua.vim`)
- `includeexpr` doesn't work with module in `init.lua`
Solution:
- Update documentation
- Assign value to option `&include`
- Add function `LuaInclude` and assign it to `l:&includeexpr`
closes: vim/vim#16655
https://github.com/vim/vim/commit/00a00f5d3fc8dcf08e959c207a90f5902abc6a08
Co-authored-by: brianhuster <phambinhanctb2004@gmail.com>
Co-authored-by: dkearns <dougkearns@gmail.com>
Diffstat (limited to 'runtime/ftplugin/lua.vim')
-rw-r--r-- | runtime/ftplugin/lua.vim | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/runtime/ftplugin/lua.vim b/runtime/ftplugin/lua.vim index 80cbba78a2..914e7ab6db 100644 --- a/runtime/ftplugin/lua.vim +++ b/runtime/ftplugin/lua.vim @@ -4,14 +4,24 @@ " Previous Maintainer: Max Ischenko <mfi@ukr.net> " Contributor: Dorai Sitaram <ds26@gte.com> " C.D. MacEachern <craig.daniel.maceachern@gmail.com> -" Tyler Miller <tmillr@proton.me> -" Last Change: 2024 Jan 14 +" Phạm Bình An <phambinhanctb2004@gmail.com> +" Last Change: 2025 Feb 25 if exists("b:did_ftplugin") finish endif let b:did_ftplugin = 1 +" keep in sync with syntax/lua.vim +if !exists("lua_version") + " Default is lua 5.3 + let lua_version = 5 + let lua_subversion = 3 +elseif !exists("lua_subversion") + " lua_version exists, but lua_subversion doesn't. In this case set it to 0 + let lua_subversion = 0 +endif + let s:cpo_save = &cpo set cpo&vim @@ -21,11 +31,11 @@ setlocal formatoptions-=t formatoptions+=croql let &l:define = '\<function\|\<local\%(\s\+function\)\=' -" TODO: handle init.lua -setlocal includeexpr=tr(v:fname,'.','/') +let &l:include = '\v<((do|load)file|require)[^''"]*[''"]\zs[^''"]+' +setlocal includeexpr=LuaInclude(v:fname) setlocal suffixesadd=.lua -let b:undo_ftplugin = "setlocal cms< com< def< fo< inex< sua<" +let b:undo_ftplugin = "setlocal cms< com< def< fo< inc< inex< sua<" if exists("loaded_matchit") && !exists("b:match_words") let b:match_ignorecase = 0 @@ -48,7 +58,24 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") let b:undo_ftplugin ..= " | unlet! b:browsefilter" endif -let &cpo = s:cpo_save -unlet s:cpo_save +" The rest of the file needs to be :sourced only once per Vim session +if exists("s:loaded_lua") || &cp + let &cpo = s:cpo_save + unlet s:cpo_save + finish +endif +let s:loaded_lua = 1 + +function LuaInclude(fname) abort + let lua_ver = str2float(printf("%d.%02d", g:lua_version, g:lua_subversion)) + let fname = tr(a:fname, '.', '/') + let paths = lua_ver >= 5.03 ? [ fname.'.lua', fname.'/init.lua' ] : [ fname.'.lua' ] + for path in paths + if filereadable(path) + return path + endif + endfor + return fname +endfunction " vim: nowrap sw=2 sts=2 ts=8 noet: |