├── ftdetect └── pico8.vim ├── README.md ├── indent └── pico8.vim └── syntax └── pico8.vim /ftdetect/pico8.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.p8 set filetype=pico8 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Vim syntax file for Pico-8. 2 | Just changes the builtin lua syntax file, removing the lua stdlib functions and adding the Pico-8 ones. 3 | 4 | 5 | License 6 | ======= 7 | 8 | Same as Vim, see `:help license`. 9 | -------------------------------------------------------------------------------- /indent/pico8.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: Lua script 3 | " Maintainer: Marcus Aurelius Farias 4 | " First Author: Max Ischenko 5 | " Last Change: 2016 Jan 10 6 | 7 | " Only load this indent file when no other was loaded. 8 | if exists("b:did_indent") 9 | finish 10 | endif 11 | let b:did_indent = 1 12 | 13 | setlocal indentexpr=GetLuaIndent() 14 | 15 | " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until' 16 | " on the current line ('else' is default and includes 'elseif'). 17 | setlocal indentkeys+=0=end,0=until 18 | 19 | setlocal autoindent 20 | 21 | " Only define the function once. 22 | if exists("*GetLuaIndent") 23 | finish 24 | endif 25 | 26 | function! GetLuaIndent() 27 | " Find a non-blank line above the current line. 28 | let prevlnum = prevnonblank(v:lnum - 1) 29 | 30 | " Hit the start of the file, use zero indent. 31 | if prevlnum == 0 32 | return 0 33 | endif 34 | 35 | " Add a 'shiftwidth' after lines that start a block: 36 | " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{' 37 | let ind = indent(prevlnum) 38 | let prevline = getline(prevlnum) 39 | let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') 40 | if midx == -1 41 | let midx = match(prevline, '{\s*$') 42 | if midx == -1 43 | let midx = match(prevline, '\\s*\%(\k\|[.:]\)\{-}\s*(') 44 | endif 45 | endif 46 | 47 | if midx != -1 48 | " Add 'shiftwidth' if what we found previously is not in a comment and 49 | " an "end" or "until" is not present on the same line. 50 | if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\\|\' 51 | let ind = ind + &shiftwidth 52 | endif 53 | endif 54 | 55 | " Subtract a 'shiftwidth' on end, else, elseif, until and '}' 56 | " This is the part that requires 'indentkeys'. 57 | let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\)') 58 | if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment" 59 | let ind = ind - &shiftwidth 60 | endif 61 | 62 | return ind 63 | endfunction 64 | -------------------------------------------------------------------------------- /syntax/pico8.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " For the Pico-8 - modified from the Vim builtin Lua syntax file 3 | 4 | " For version 5.x: Clear all syntax items 5 | " For version 6.x: Quit when a syntax file was already loaded 6 | if version < 600 7 | syntax clear 8 | elseif exists("b:current_syntax") 9 | finish 10 | endif 11 | 12 | if !exists("lua_version") 13 | " Default is lua 5.1 14 | let lua_version = 5 15 | let lua_subversion = 1 16 | elseif !exists("lua_subversion") 17 | " lua_version exists, but lua_subversion doesn't. So, set it to 0 18 | let lua_subversion = 0 19 | endif 20 | 21 | syn case match 22 | 23 | " syncing method 24 | syn sync minlines=100 25 | 26 | " Comments 27 | syn keyword luaTodo contained TODO FIXME XXX 28 | syn match luaComment "--.*$" contains=luaTodo,@Spell 29 | if lua_version == 5 && lua_subversion == 0 30 | syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment,@Spell 31 | syn region luaInnerComment contained transparent start="\[\[" end="\]\]" 32 | elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 33 | " Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc. 34 | syn region luaComment matchgroup=luaComment start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaTodo,@Spell 35 | endif 36 | 37 | " First line may start with #! 38 | syn match luaComment "\%^#!.*" 39 | 40 | " catch errors caused by wrong parenthesis and wrong curly brackets or 41 | " keywords placed outside their respective blocks 42 | 43 | syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaError,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement 44 | syn match luaError ")" 45 | syn match luaError "}" 46 | syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>" 47 | 48 | " Function declaration 49 | syn region luaFunctionBlock transparent matchgroup=luaFunction start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 50 | 51 | " if then else elseif end 52 | syn keyword luaCond contained else 53 | 54 | " then ... end 55 | syn region luaCondEnd contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaRepeat 56 | 57 | " elseif ... then 58 | syn region luaCondElseif contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 59 | 60 | " if ... then 61 | syn region luaCondStart transparent matchgroup=luaCond start="\" end="\"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaCondEnd skipwhite skipempty 62 | 63 | " do ... end 64 | syn region luaBlock transparent matchgroup=luaStatement start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 65 | 66 | " repeat ... until 67 | syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 68 | 69 | " while ... do 70 | syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaBlock skipwhite skipempty 71 | 72 | " for ... do and for ... in ... do 73 | syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd nextgroup=luaBlock skipwhite skipempty 74 | 75 | " Following 'else' example. This is another item to those 76 | " contains=ALLBUT,... because only the 'for' luaRepeatBlock contains it. 77 | syn keyword luaRepeat contained in 78 | 79 | " other keywords 80 | syn keyword luaStatement return local break 81 | syn keyword luaOperator and or not 82 | syn keyword luaConstant nil 83 | if lua_version > 4 84 | syn keyword luaConstant true false 85 | endif 86 | 87 | " Strings 88 | if lua_version < 5 89 | syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}" 90 | elseif lua_version == 5 && lua_subversion == 0 91 | syn match luaSpecial contained "\\[\\abfnrtv\'\"[\]]\|\\\d\{,3}" 92 | syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell 93 | elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 94 | syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}" 95 | syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell 96 | endif 97 | syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell 98 | syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell 99 | 100 | " integer number 101 | syn match luaNumber "\<\d\+\>" 102 | " floating point number, with dot, optional exponent 103 | syn match luaFloat "\<\d\+\.\d*\%(e[-+]\=\d\+\)\=\>" 104 | " floating point number, starting with a dot, optional exponent 105 | syn match luaFloat "\.\d\+\%(e[-+]\=\d\+\)\=\>" 106 | " floating point number, without dot, with exponent 107 | syn match luaFloat "\<\d\+e[-+]\=\d\+\>" 108 | 109 | " hex numbers 110 | if lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 111 | syn match luaNumber "\<0x\x\+\>" 112 | endif 113 | 114 | " tables 115 | syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement 116 | 117 | syn keyword luaFunc clip pget pset sget 118 | syn keyword luaFunc sset fget fset print 119 | syn keyword luaFunc cursor color cls camera 120 | syn keyword luaFunc circ circfill line rect 121 | syn keyword luaFunc rectfill pal palt spr 122 | syn keyword luaFunc sspr add del foreach 123 | syn keyword luaFunc btn btnp sfx music 124 | syn keyword luaFunc mget mset map peek 125 | syn keyword luaFunc poke memcpy reload cstore 126 | syn keyword luaFunc memset max min mid 127 | syn keyword luaFunc flr cos sin atan2 128 | syn keyword luaFunc sqrt abs rnd srand 129 | syn keyword luaFunc band bor bxor bnot 130 | syn keyword luaFunc shl shr sub all pairs 131 | syn keyword luaFunc assert type setmetatable 132 | syn keyword luaFunc cocreate coresume costatus yield 133 | syn keyword luaFunc sgn stat cartdata dget dset 134 | 135 | 136 | " Define the default highlighting. 137 | " For version 5.7 and earlier: only when not done already 138 | " For version 5.8 and later: only when an item doesn't have highlighting yet 139 | if version >= 508 || !exists("did_lua_syntax_inits") 140 | if version < 508 141 | let did_lua_syntax_inits = 1 142 | command -nargs=+ HiLink hi link 143 | else 144 | command -nargs=+ HiLink hi def link 145 | endif 146 | 147 | HiLink luaStatement Statement 148 | HiLink luaRepeat Repeat 149 | HiLink luaString String 150 | HiLink luaString2 String 151 | HiLink luaNumber Number 152 | HiLink luaFloat Float 153 | HiLink luaOperator Operator 154 | HiLink luaConstant Constant 155 | HiLink luaCond Conditional 156 | HiLink luaFunction Function 157 | HiLink luaComment Comment 158 | HiLink luaTodo Todo 159 | HiLink luaTable Structure 160 | HiLink luaError Error 161 | HiLink luaSpecial SpecialChar 162 | HiLink luaFunc Identifier 163 | 164 | delcommand HiLink 165 | endif 166 | 167 | let b:current_syntax = "lua" 168 | 169 | " vim: et ts=8 170 | --------------------------------------------------------------------------------