0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

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: #16655

Co-authored-by: dkearns <dougkearns@gmail.com>
Signed-off-by: brianhuster <phambinhanctb2004@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
brianhuster
2025-02-25 20:22:18 +01:00
committed by Christian Brabandt
parent 12b1eb58ab
commit 00a00f5d3f
5 changed files with 48 additions and 16 deletions

View File

@@ -5,13 +5,24 @@
" Contributor: Dorai Sitaram <ds26@gte.com>
" C.D. MacEachern <craig.daniel.maceachern@gmail.com>
" Tyler Miller <tmillr@proton.me>
" Last Change: 2024 Dec 03
" 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 +32,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
@@ -75,7 +86,19 @@ let s:patterns = [
\ ['local\s+function\s+.+', 'end'],
\ ]
function! LuaFold(lnum) abort
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
function LuaFold(lnum) abort
if b:lua_lasttick == b:changedtick
return b:lua_foldlists[a:lnum-1]
endif