runtime(lua): Update lua ftplugin and documentation Commit: https://github.com/vim/vim/commit/00a00f5d3fc8dcf08e959c207a90f5902abc6a08 Author: brianhuster <phambinhanctb2...@gmail.com> Date: Tue Feb 25 20:22:18 2025 +0100
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 <dougkea...@gmail.com> Signed-off-by: brianhuster <phambinhanctb2...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 7f338a561..a2c757fb4 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 9.1. Last change: 2025 Feb 20 +*filetype.txt* For Vim version 9.1. Last change: 2025 Feb 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -744,12 +744,21 @@ Add following lines to $HOME/.vim/ftplugin/json.vim: > import autoload 'dist/json.vim' setl formatexpr=json.FormatExpr() -LUA *ft-lua-plugin* +LUA *ft-lua-plugin* *g:lua_folding* You can enable folding of Lua functions using |fold-expr| by: > let g:lua_folding = 1 +< *g:lua_version* *g:lua_subversion* +Lua filetype's 'includeexpr' and |ft-lua-syntax| highlighting use the global +variables "g:lua_version" and "g:lua_subversion" to determine the version of +Lua to use (5.3 is the default) +For example, to use Lua 5.1, set the variables like this: > + + let g:lua_version = 5 + let g:lua_subversion = 1 +< MAIL *ft-mail-plugin* Options: diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index d8c4b08ea..c4d7afc5f 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1,4 +1,4 @@ -*syntax.txt* For Vim version 9.1. Last change: 2025 Feb 23 +*syntax.txt* For Vim version 9.1. Last change: 2025 Feb 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -2343,13 +2343,9 @@ instead, and the name of your source file should be *.pike LUA *lua.vim* *ft-lua-syntax* -The Lua syntax file can be used for versions 4.0, 5.0, 5.1 and 5.2 (5.2 is -the default). You can select one of these versions using the global variables -lua_version and lua_subversion. For example, to activate Lua -5.1 syntax highlighting, set the variables like this: > - - :let lua_version = 5 - :let lua_subversion = 1 +The Lua syntax file can be used for versions 4.0, 5.0+. You can select one of +these versions using the global variables |g:lua_version| and +|g:lua_subversion|. MAIL *mail.vim* *ft-mail.vim* diff --git a/runtime/doc/tags b/runtime/doc/tags index 410807eac..49a849ef8 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -7625,6 +7625,9 @@ g:html_use_input_for_pc syntax.txt /*g:html_use_input_for_pc* g:html_use_xhtml syntax.txt /*g:html_use_xhtml* g:html_whole_filler syntax.txt /*g:html_whole_filler* g:lf_shell_syntax syntax.txt /*g:lf_shell_syntax* +g:lua_folding filetype.txt /*g:lua_folding* +g:lua_subversion filetype.txt /*g:lua_subversion* +g:lua_version filetype.txt /*g:lua_version* g:markdown_fenced_languages syntax.txt /*g:markdown_fenced_languages* g:markdown_minlines syntax.txt /*g:markdown_minlines* g:markdown_syntax_conceal syntax.txt /*g:markdown_syntax_conceal* diff --git a/runtime/ftplugin/lua.vim b/runtime/ftplugin/lua.vim index 22b998627..9687d55e9 100644 --- a/runtime/ftplugin/lua.vim +++ b/runtime/ftplugin/lua.vim @@ -5,13 +5,24 @@ " Contributor: Dorai Sitaram <d...@gte.com> " C.D. MacEachern <craig.daniel.maceach...@gmail.com> " Tyler Miller <tmi...@proton.me> -" Last Change: 2024 Dec 03 +" Ph廕《 B穫nh An <phambinhanctb2...@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 = ' <((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 diff --git a/runtime/syntax/lua.vim b/runtime/syntax/lua.vim index 9c5a49058..f5851d024 100644 --- a/runtime/syntax/lua.vim +++ b/runtime/syntax/lua.vim @@ -2,7 +2,7 @@ " Language: Lua 4.0, Lua 5.0, Lua 5.1, Lua 5.2 and Lua 5.3 " Maintainer: Marcus Aurelius Farias <masserahguard-lua 'at' yahoo com> " First Author: Carlos Augusto Teixeira Mendes <cmendes 'at' inf puc-rio br> -" Last Change: 2022 Sep 07 +" Last Change: 2025 Feb 25 " Options: lua_version = 4 or 5 " lua_subversion = 0 (for 4.0 or 5.0) " or 1, 2, 3 (for 5.1, 5.2 or 5.3) @@ -16,6 +16,7 @@ endif let s:cpo_save = &cpo set cpo&vim +" keep in sync with ftplugin/lua.vim if !exists("lua_version") " Default is lua 5.3 let lua_version = 5 -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tn0d6-00CkzY-Eg%40256bit.org.