Add lua
This commit is contained in:
parent
041ab2d237
commit
f028cfae59
@ -65,6 +65,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
|||||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
||||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
||||||
|
- [lua](https://github.com/tbastos/vim-lua) (syntax, indent)
|
||||||
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin, ftdetect)
|
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax, ftdetect)
|
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax, ftdetect)
|
||||||
- [nginx](https://github.com/othree/nginx-contrib-vim) (syntax, indent, ftdetect)
|
- [nginx](https://github.com/othree/nginx-contrib-vim) (syntax, indent, ftdetect)
|
||||||
|
1
build
1
build
@ -138,6 +138,7 @@ PACKS="
|
|||||||
latex:LaTeX-Box-Team/LaTeX-Box
|
latex:LaTeX-Box-Team/LaTeX-Box
|
||||||
less:groenewege/vim-less
|
less:groenewege/vim-less
|
||||||
liquid:tpope/vim-liquid
|
liquid:tpope/vim-liquid
|
||||||
|
lua:tbastos/vim-lua
|
||||||
mako:sophacles/vim-bundle-mako
|
mako:sophacles/vim-bundle-mako
|
||||||
markdown:plasticboy/vim-markdown:_SYNTAX
|
markdown:plasticboy/vim-markdown:_SYNTAX
|
||||||
nginx:othree/nginx-contrib-vim
|
nginx:othree/nginx-contrib-vim
|
||||||
|
126
indent/lua.vim
Normal file
126
indent/lua.vim
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'lua') == -1
|
||||||
|
|
||||||
|
" Vim indent file
|
||||||
|
" Language: Lua
|
||||||
|
" URL: https://github.com/tbastos/vim-lua
|
||||||
|
|
||||||
|
" Initialization ------------------------------------------{{{1
|
||||||
|
|
||||||
|
if exists("b:did_indent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal nosmartindent
|
||||||
|
|
||||||
|
setlocal indentexpr=GetLuaIndent()
|
||||||
|
setlocal indentkeys+=0=end,0=until,0=elseif,0=else
|
||||||
|
|
||||||
|
" Only define the function once.
|
||||||
|
if exists("*GetLuaIndent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Variables -----------------------------------------------{{{1
|
||||||
|
|
||||||
|
let s:open_patt = '\%(\<\%(function\|if\|repeat\|do\)\>\|(\|{\)'
|
||||||
|
let s:middle_patt = '\<\%(else\|elseif\)\>'
|
||||||
|
let s:close_patt = '\%(\<\%(end\|until\)\>\|)\|}\)'
|
||||||
|
|
||||||
|
let s:anon_func_start = '\S\+\s*[({].*\<function\s*(.*)\s*$'
|
||||||
|
let s:anon_func_end = '\<end\%(\s*[)}]\)\+'
|
||||||
|
|
||||||
|
" Expression used to check whether we should skip a match with searchpair().
|
||||||
|
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ 'luaComment\\|luaString'"
|
||||||
|
|
||||||
|
" Auxiliary Functions -------------------------------------{{{1
|
||||||
|
|
||||||
|
function s:IsInCommentOrString(lnum, col)
|
||||||
|
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ 'luaCommentLong\|luaStringLong'
|
||||||
|
\ && !(getline(a:lnum) =~ '^\s*\%(--\)\?\[=*\[') " opening tag is not considered 'in'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find line above 'lnum' that isn't blank, in a comment or string.
|
||||||
|
function s:PrevLineOfCode(lnum)
|
||||||
|
let lnum = prevnonblank(a:lnum)
|
||||||
|
while s:IsInCommentOrString(lnum, 1)
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
endwhile
|
||||||
|
return lnum
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Gets line contents, excluding trailing comments.
|
||||||
|
function s:GetContents(lnum)
|
||||||
|
return substitute(getline(a:lnum), '\v\m--.*$', '', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" GetLuaIndent Function -----------------------------------{{{1
|
||||||
|
|
||||||
|
function GetLuaIndent()
|
||||||
|
" if the line is in a long comment or string, don't change the indent
|
||||||
|
if s:IsInCommentOrString(v:lnum, 1)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let prev_line = s:PrevLineOfCode(v:lnum - 1)
|
||||||
|
if prev_line == 0
|
||||||
|
" this is the first non-empty line
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let contents_cur = s:GetContents(v:lnum)
|
||||||
|
let contents_prev = s:GetContents(prev_line)
|
||||||
|
|
||||||
|
let original_cursor_pos = getpos(".")
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
|
||||||
|
" check if the previous line opens blocks
|
||||||
|
call cursor(v:lnum, 1)
|
||||||
|
let num_pairs = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||||
|
\ 'mrb', s:skip_expr, prev_line)
|
||||||
|
if num_pairs > 0
|
||||||
|
let i += num_pairs
|
||||||
|
endif
|
||||||
|
|
||||||
|
" special case: call(with, {anon = function() -- should indent only once
|
||||||
|
if num_pairs > 1 && contents_prev =~ s:anon_func_start
|
||||||
|
let i = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" check if current line closes blocks
|
||||||
|
call cursor(prev_line, col([prev_line,'$']))
|
||||||
|
let num_pairs = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||||
|
\ 'mr', s:skip_expr, v:lnum)
|
||||||
|
if num_pairs > 0
|
||||||
|
let i -= num_pairs
|
||||||
|
endif
|
||||||
|
|
||||||
|
" special case: end}) -- end of call with anon func should unindent once
|
||||||
|
if num_pairs > 1 && contents_cur =~ s:anon_func_end
|
||||||
|
let i = -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" if the previous line closed a paren, unindent (except with anon funcs)
|
||||||
|
call cursor(prev_line - 1, col([prev_line - 1, '$']))
|
||||||
|
let num_pairs = searchpair('(', '', ')', 'mr', s:skip_expr, prev_line)
|
||||||
|
if num_pairs > 0 && contents_prev !~ s:anon_func_end
|
||||||
|
let i -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" if this line closed a paren, indent (except with anon funcs)
|
||||||
|
call cursor(prev_line, col([prev_line, '$']))
|
||||||
|
let num_pairs = searchpair('(', '', ')', 'mr', s:skip_expr, v:lnum)
|
||||||
|
if num_pairs > 0 && contents_cur !~ s:anon_func_end
|
||||||
|
let i += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" restore cursor
|
||||||
|
call setpos(".", original_cursor_pos)
|
||||||
|
|
||||||
|
return indent(prev_line) + (&sw * i)
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
216
syntax/lua.vim
Normal file
216
syntax/lua.vim
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'lua') == -1
|
||||||
|
|
||||||
|
" Vim syntax file
|
||||||
|
" Language: Lua
|
||||||
|
" URL: https://github.com/tbastos/vim-lua
|
||||||
|
|
||||||
|
if !exists("main_syntax")
|
||||||
|
if version < 600
|
||||||
|
syntax clear
|
||||||
|
elseif exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let main_syntax = 'lua'
|
||||||
|
endif
|
||||||
|
|
||||||
|
syntax sync fromstart
|
||||||
|
|
||||||
|
" Clusters
|
||||||
|
syntax cluster luaBase contains=luaComment,luaCommentLong,luaConstant,luaNumber,luaString,luaStringLong,luaBuiltIn
|
||||||
|
syntax cluster luaExpr contains=@luaBase,luaTable,luaParen,luaBracket,luaSpecialTable,luaSpecialValue,luaOperator,luaEllipsis,luaComma,luaFunc,luaFuncCall,luaError
|
||||||
|
syntax cluster luaStat contains=@luaExpr,luaIfThen,luaBlock,luaLoop,luaGoto,luaLabel,luaLocal,luaStatement,luaSemiCol
|
||||||
|
|
||||||
|
syntax match luaNoise /\%(\.\|,\|:\|\;\)/
|
||||||
|
|
||||||
|
" Symbols
|
||||||
|
syntax region luaTable transparent matchgroup=luaBraces start="{" end="}" contains=@luaExpr fold
|
||||||
|
syntax region luaParen transparent matchgroup=luaParens start='(' end=')' contains=@luaExpr
|
||||||
|
syntax region luaBracket transparent matchgroup=luaBrackets start="\[" end="\]" contains=@luaExpr
|
||||||
|
syntax match luaComma ","
|
||||||
|
syntax match luaSemiCol ";"
|
||||||
|
syntax match luaOperator "[#<>=~^&|*/%+-]\|\.\."
|
||||||
|
syntax match luaEllipsis "\.\.\."
|
||||||
|
|
||||||
|
" Catch errors caused by unbalanced brackets and keywords
|
||||||
|
syntax match luaError ")"
|
||||||
|
syntax match luaError "}"
|
||||||
|
syntax match luaError "\]"
|
||||||
|
syntax match luaError "\<\%(end\|else\|elseif\|then\|until\)\>"
|
||||||
|
|
||||||
|
" Shebang at the start
|
||||||
|
syntax match luaComment "\%^#!.*"
|
||||||
|
|
||||||
|
" Comments
|
||||||
|
syntax keyword luaCommentTodo contained TODO FIXME XXX TBD
|
||||||
|
syntax match luaComment "--.*$" contains=luaCommentTodo,luaDocTag,@Spell
|
||||||
|
syntax region luaCommentLong matchgroup=luaCommentLongTag start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaCommentTodo,luaDocTag,@Spell fold
|
||||||
|
syntax match luaDocTag contained "\s@\k\+"
|
||||||
|
|
||||||
|
" Function calls
|
||||||
|
syntax match luaFuncCall /\k\+\%(\s*[{('"]\)\@=/
|
||||||
|
|
||||||
|
" Functions
|
||||||
|
syntax region luaFunc transparent matchgroup=luaFuncKeyword start="\<function\>" end="\<end\>" contains=@luaStat,luaFuncSig fold
|
||||||
|
syntax region luaFuncSig contained transparent start="\(\<function\>\)\@<=" end=")" contains=luaFuncId,luaFuncArgs keepend
|
||||||
|
syntax match luaFuncId contained "[^(]*(\@=" contains=luaFuncTable,luaFuncName
|
||||||
|
syntax match luaFuncTable contained /\k\+\%(\s*[.:]\)\@=/
|
||||||
|
syntax match luaFuncName contained "[^(.:]*(\@="
|
||||||
|
syntax region luaFuncArgs contained transparent matchgroup=luaFuncParens start=/(/ end=/)/ contains=@luaBase,luaFuncArgName,luaFuncArgComma,luaEllipsis
|
||||||
|
syntax match luaFuncArgName contained /\k\+/
|
||||||
|
syntax match luaFuncArgComma contained /,/
|
||||||
|
|
||||||
|
" if ... then
|
||||||
|
syntax region luaIfThen transparent matchgroup=luaCond start="\<if\>" end="\<then\>"me=e-4 contains=@luaExpr nextgroup=luaThenEnd skipwhite skipempty
|
||||||
|
|
||||||
|
" then ... end
|
||||||
|
syntax region luaThenEnd contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=@luaStat,luaElseifThen,luaElse fold
|
||||||
|
|
||||||
|
" elseif ... then
|
||||||
|
syntax region luaElseifThen contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=@luaExpr
|
||||||
|
|
||||||
|
" else
|
||||||
|
syntax keyword luaElse contained else
|
||||||
|
|
||||||
|
" do ... end
|
||||||
|
syntax region luaBlock transparent matchgroup=luaRepeat start="\<do\>" end="\<end\>" contains=@luaStat fold
|
||||||
|
|
||||||
|
" repeat ... until
|
||||||
|
syntax region luaLoop transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=@luaStat nextgroup=@luaExpr fold
|
||||||
|
|
||||||
|
" while ... do
|
||||||
|
syntax region luaLoop transparent matchgroup=luaRepeat start="\<while\>" end="\<do\>"me=e-2 contains=@luaExpr nextgroup=luaBlock skipwhite skipempty fold
|
||||||
|
|
||||||
|
" for ... do and for ... in ... do
|
||||||
|
syntax region luaLoop transparent matchgroup=luaRepeat start="\<for\>" end="\<do\>"me=e-2 contains=@luaExpr,luaIn nextgroup=luaBlock skipwhite skipempty
|
||||||
|
syntax keyword luaIn contained in
|
||||||
|
|
||||||
|
" goto and labels
|
||||||
|
syntax keyword luaGoto goto nextgroup=luaGotoLabel skipwhite
|
||||||
|
syntax match luaGotoLabel "\k\+" contained
|
||||||
|
syntax match luaLabel "::\k\+::"
|
||||||
|
|
||||||
|
" Other Keywords
|
||||||
|
syntax keyword luaConstant nil true false
|
||||||
|
syntax keyword luaBuiltIn _ENV self
|
||||||
|
syntax keyword luaLocal local
|
||||||
|
syntax keyword luaOperator and or not
|
||||||
|
syntax keyword luaStatement break return
|
||||||
|
|
||||||
|
" Strings
|
||||||
|
syntax match luaStringSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}#
|
||||||
|
syntax region luaStringLong matchgroup=luaStringLongTag start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell
|
||||||
|
syntax region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaStringSpecial,@Spell
|
||||||
|
syntax region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaStringSpecial,@Spell
|
||||||
|
|
||||||
|
" Decimal constant
|
||||||
|
syntax match luaNumber "\<\d\+\>"
|
||||||
|
" Hex constant
|
||||||
|
syntax match luaNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>"
|
||||||
|
" Floating point constant, with dot, optional exponent
|
||||||
|
syntax match luaFloat "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>"
|
||||||
|
" Floating point constant, starting with a dot, optional exponent
|
||||||
|
syntax match luaFloat "\.\d\+\%([eE][-+]\=\d\+\)\=\>"
|
||||||
|
" Floating point constant, without dot, with exponent
|
||||||
|
syntax match luaFloat "\<\d\+[eE][-+]\=\d\+\>"
|
||||||
|
|
||||||
|
" Special names from the Standard Library
|
||||||
|
syntax keyword luaSpecialTable
|
||||||
|
\ bit32
|
||||||
|
\ coroutine
|
||||||
|
\ debug
|
||||||
|
\ io
|
||||||
|
\ math
|
||||||
|
\ os
|
||||||
|
\ package
|
||||||
|
\ string
|
||||||
|
\ table
|
||||||
|
\ utf8
|
||||||
|
|
||||||
|
syntax keyword luaSpecialValue
|
||||||
|
\ _G
|
||||||
|
\ _VERSION
|
||||||
|
\ assert
|
||||||
|
\ collectgarbage
|
||||||
|
\ dofile
|
||||||
|
\ error
|
||||||
|
\ getfenv
|
||||||
|
\ getmetatable
|
||||||
|
\ ipairs
|
||||||
|
\ load
|
||||||
|
\ loadfile
|
||||||
|
\ loadstring
|
||||||
|
\ module
|
||||||
|
\ next
|
||||||
|
\ pairs
|
||||||
|
\ pcall
|
||||||
|
\ print
|
||||||
|
\ rawequal
|
||||||
|
\ rawget
|
||||||
|
\ rawlen
|
||||||
|
\ rawset
|
||||||
|
\ require
|
||||||
|
\ select
|
||||||
|
\ setfenv
|
||||||
|
\ setmetatable
|
||||||
|
\ tonumber
|
||||||
|
\ tostring
|
||||||
|
\ type
|
||||||
|
\ unpack
|
||||||
|
\ xpcall
|
||||||
|
|
||||||
|
" Define the default highlighting.
|
||||||
|
" For version 5.7 and earlier: only when not done already
|
||||||
|
" For version 5.8 and later: only when an item doesn't have highlighting yet
|
||||||
|
if version >= 508 || !exists("did_lua_syn_inits")
|
||||||
|
if version < 508
|
||||||
|
let did_lua_syn_inits = 1
|
||||||
|
command -nargs=+ HiLink hi link <args>
|
||||||
|
else
|
||||||
|
command -nargs=+ HiLink hi def link <args>
|
||||||
|
endif
|
||||||
|
HiLink luaParens Noise
|
||||||
|
HiLink luaBraces Structure
|
||||||
|
HiLink luaBrackets Noise
|
||||||
|
HiLink luaBuiltIn Special
|
||||||
|
HiLink luaComment Comment
|
||||||
|
HiLink luaCommentLong luaComment
|
||||||
|
HiLink luaCommentTodo Todo
|
||||||
|
HiLink luaCond Conditional
|
||||||
|
HiLink luaConstant Boolean
|
||||||
|
HiLink luaDocTag Underlined
|
||||||
|
HiLink luaEllipsis StorageClass
|
||||||
|
HiLink luaElse Conditional
|
||||||
|
HiLink luaError Error
|
||||||
|
HiLink luaFloat Float
|
||||||
|
HiLink luaFuncTable Function
|
||||||
|
HiLink luaFuncArgName Noise
|
||||||
|
HiLink luaFuncCall PreProc
|
||||||
|
HiLink luaFuncId Function
|
||||||
|
HiLink luaFuncKeyword Type
|
||||||
|
HiLink luaFuncName Function
|
||||||
|
HiLink luaFuncParens Noise
|
||||||
|
HiLink luaGoto luaStatement
|
||||||
|
HiLink luaGotoLabel Noise
|
||||||
|
HiLink luaIn Repeat
|
||||||
|
HiLink luaLabel Label
|
||||||
|
HiLink luaLocal Type
|
||||||
|
HiLink luaNumber Number
|
||||||
|
HiLink luaOperator Operator
|
||||||
|
HiLink luaRepeat Repeat
|
||||||
|
HiLink luaSemiCol Delimiter
|
||||||
|
HiLink luaSpecialTable Special
|
||||||
|
HiLink luaSpecialValue PreProc
|
||||||
|
HiLink luaStatement Statement
|
||||||
|
HiLink luaString String
|
||||||
|
HiLink luaStringLong luaString
|
||||||
|
HiLink luaStringSpecial SpecialChar
|
||||||
|
|
||||||
|
delcommand HiLink
|
||||||
|
end
|
||||||
|
|
||||||
|
let b:current_syntax = "lua"
|
||||||
|
if main_syntax == 'lua'
|
||||||
|
unlet main_syntax
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
Loading…
Reference in New Issue
Block a user