1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-19 16:25:11 +01:00
vim/runtime/ftplugin/lua.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.9 KiB
VimL
Raw Permalink Normal View History

2004-06-13 20:20:40 +00:00
" Vim filetype plugin file.
2022-09-10 13:13:14 +01:00
" Language: Lua
2021-11-16 19:18:26 +00:00
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Max Ischenko <mfi@ukr.net>
2022-09-10 13:13:14 +01:00
" Contributor: Dorai Sitaram <ds26@gte.com>
2022-10-16 13:11:12 +01:00
" C.D. MacEachern <craig.daniel.maceachern@gmail.com>
2023-04-22 22:40:14 +01:00
" Tyler Miller <tmillr@proton.me>
" Last Change: 2024 Dec 03
2004-06-13 20:20:40 +00:00
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
2011-12-14 21:17:39 +01:00
let s:cpo_save = &cpo
set cpo&vim
2023-04-22 22:40:14 +01:00
setlocal comments=:---,:--
2022-09-10 13:13:14 +01:00
setlocal commentstring=--\ %s
2021-11-16 19:18:26 +00:00
setlocal formatoptions-=t formatoptions+=croql
2004-06-13 20:20:40 +00:00
2022-09-10 13:13:14 +01:00
let &l:define = '\<function\|\<local\%(\s\+function\)\='
2022-10-16 13:11:12 +01:00
" TODO: handle init.lua
2022-11-23 23:46:31 +00:00
setlocal includeexpr=tr(v:fname,'.','/')
2004-06-13 20:20:40 +00:00
setlocal suffixesadd=.lua
2022-10-16 13:11:12 +01:00
let b:undo_ftplugin = "setlocal cms< com< def< fo< inex< sua<"
2004-06-13 20:20:40 +00:00
2021-11-16 19:18:26 +00:00
if exists("loaded_matchit") && !exists("b:match_words")
2004-06-13 20:20:40 +00:00
let b:match_ignorecase = 0
let b:match_words =
2022-09-10 13:13:14 +01:00
\ '\<\%(do\|function\|if\)\>:' ..
\ '\<\%(return\|else\|elseif\)\>:' ..
\ '\<end\>,' ..
\ '\<repeat\>:\<until\>,' ..
\ '\%(--\)\=\[\(=*\)\[:]\1]'
let b:undo_ftplugin ..= " | unlet! b:match_words b:match_ignorecase"
2021-11-16 19:18:26 +00:00
endif
2004-06-13 20:20:40 +00:00
2021-11-16 19:18:26 +00:00
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
let b:browsefilter = "Lua Source Files (*.lua)\t*.lua\n"
if has("win32")
let b:browsefilter ..= "All Files (*.*)\t*\n"
else
let b:browsefilter ..= "All Files (*)\t*\n"
endif
2022-09-10 13:13:14 +01:00
let b:undo_ftplugin ..= " | unlet! b:browsefilter"
2021-11-16 19:18:26 +00:00
endif
2011-12-14 21:17:39 +01:00
if has("folding") && get(g:, "lua_folding", 0)
setlocal foldmethod=expr
setlocal foldexpr=LuaFold(v:lnum)
let b:lua_lasttick = -1
let b:undo_ftplugin ..= "|setl foldexpr< foldmethod< | unlet! b:lua_lasttick b:lua_foldlists"
endif
" 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
let s:patterns = [
\ ['do', 'end'],
\ ['if\s+.+\s+then', 'end'],
\ ['repeat', 'until\s+.+'],
\ ['for\s+.+\s+do', 'end'],
\ ['while\s+.+\s+do', 'end'],
\ ['function.+', 'end'],
\ ['return\s+function.+', 'end'],
\ ['local\s+function\s+.+', 'end'],
\ ]
function! LuaFold(lnum) abort
if b:lua_lasttick == b:changedtick
return b:lua_foldlists[a:lnum-1]
endif
let b:lua_lasttick = b:changedtick
let b:lua_foldlists = []
let foldlist = []
let buf = getline(1, '$')
for line in buf
for t in s:patterns
let tagopen = '\v^\s*'..t[0]..'\s*$'
let tagclose = '\v^\s*'..t[1]..'\s*$'
if line =~# tagopen
call add(foldlist, t)
break
elseif line =~# tagclose
if len(foldlist) > 0 && line =~# foldlist[-1][1]
call remove(foldlist, -1)
else
let foldlist = []
endif
break
endif
endfor
call add(b:lua_foldlists, len(foldlist))
endfor
return lua_foldlists[a:lnum-1]
endfunction
2011-12-14 21:17:39 +01:00
let &cpo = s:cpo_save
unlet s:cpo_save
2022-09-10 13:13:14 +01:00
" vim: nowrap sw=2 sts=2 ts=8 noet: