diff --git a/README.md b/README.md index 62532c0..036d2f9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. -- It **won't affect your startup time**, as scripts are loaded only on demand\*. +- It **won't affect your startup time**, as scripts are loaded only on demand\*. - It **installs 50+ times faster** than 50+ packages it consist of. - Solid syntax and indentation support. Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). @@ -26,10 +26,9 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo ## Language packs - [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent, ftdetect) -- [blade](https://github.com/xsbeats/vim-blade) (syntax, ftdetect) +- [blade](https://github.com/xsbeats/vim-blade) (syntax, indent, ftdetect) - [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax) - [c/c++](https://github.com/vim-jp/cpp-vim) (syntax) -- [c-extensions](https://github.com/kergoth/aftersyntaxc.vim) (syntax) - [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect) - [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect) - [css](https://github.com/JulesWang/css.vim) (syntax) @@ -49,7 +48,8 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo - [jade](https://github.com/digitaltoad/vim-jade) (syntax, indent, ftplugin, ftdetect) - [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect) - [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, ftdetect) -- [json](https://github.com/leshill/vim-json) (syntax, ftdetect) +- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect) +- [json](https://github.com/sheerun/vim-json) (syntax, indent, ftdetect) - [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect) - [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin) - [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect) @@ -70,7 +70,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo - [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect) - [rust](https://github.com/wting/rust.vim) (syntax, indent, compiler, autoload, ftplugin, ftdetect) - [sbt](https://github.com/derekwyatt/vim-sbt) (syntax, ftdetect) -- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, ftplugin, ftdetect) +- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin, ftdetect) - [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftdetect) - [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin, ftdetect) - [systemd](https://github.com/kurayama/systemd-vim-syntax) (syntax, ftdetect) @@ -78,7 +78,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo - [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin, ftdetect) - [tmux](https://github.com/tejr/vim-tmux) (syntax, ftdetect) - [tomdoc](https://github.com/duwanis/tomdoc.vim) (syntax) -- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, compiler, ftplugin, ftdetect) +- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect) - [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax) - [thrift](https://github.com/solarnz/thrift.vim) (syntax, ftdetect) - [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect) diff --git a/build b/build index 82e7743..620ce8f 100755 --- a/build +++ b/build @@ -93,6 +93,7 @@ PACKS=" jade:digitaltoad/vim-jade jasmine:glanotte/vim-jasmine javascript:pangloss/vim-javascript + julia:dcjones/julia-minimalist-vim json:sheerun/vim-json jst:briancollins/vim-jst latex:LaTeX-Box-Team/LaTeX-Box @@ -110,6 +111,7 @@ PACKS=" protobuf:uarun/vim-protobuf python:mitsuhiko/vim-python-combined r-lang:vim-scripts/R.vim + ragel:jneen/ragel.vim rspec:sheerun/rspec.vim ruby:vim-ruby/vim-ruby rust:wting/rust.vim diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index e687fb8..d55b542 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -83,6 +83,8 @@ au BufNewFile,BufRead *.jst set filetype=jst au BufNewFile,BufRead *.djs set filetype=jst au BufNewFile,BufRead *.hamljs set filetype=jst au BufNewFile,BufRead *.ect set filetype=jst +au BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<" +au BufRead,BufNewFile *.jl set filetype=julia autocmd BufNewFile,BufRead *.less setf less au BufNewFile,BufRead *.liquid set ft=liquid au BufNewFile,BufRead */_layouts/*.html,*/_includes/*.html set ft=liquid diff --git a/indent/julia.vim b/indent/julia.vim new file mode 100644 index 0000000..1931420 --- /dev/null +++ b/indent/julia.vim @@ -0,0 +1,198 @@ +" Vim indent file +" Language: Julia +" Maintainer: Carlo Baldassi +" Last Change: 2011 dec 11 +" Notes: based on Bram Moneaar's indent file for vim + +setlocal autoindent + +setlocal indentexpr=GetJuliaIndent() +setlocal indentkeys+==end,=else,=catch,=finally +setlocal indentkeys-=0# +setlocal indentkeys-=: +setlocal indentkeys-=0{ +setlocal indentkeys-=0} +setlocal nosmartindent + +" Only define the function once. +if exists("*GetJuliaIndent") + finish +endif + +let s:skipPatterns = '\' + +function JuliaMatch(lnum, str, regex, st) + let s = a:st + while 1 + let f = match(a:str, a:regex, s) + if f >= 0 + let attr = synIDattr(synID(a:lnum,f+1,1),"name") + if attr =~ s:skipPatterns + let s = f+1 + continue + endif + endif + break + endwhile + return f +endfunction + +function GetJuliaNestingStruct(lnum) + " Auxiliary function to inspect the block structure of a line + let line = getline(a:lnum) + let s = 0 + let blocks_stack = [] + let num_closed_blocks = 0 + while 1 + let fb = JuliaMatch(a:lnum, line, '@\@', s) + let fe = JuliaMatch(a:lnum, line, '@\@', s) + + if fb < 0 && fe < 0 + " No blocks found + break + end + + if fb >= 0 && (fb < fe || fe < 0) + " The first occurrence is an opening block keyword + " Note: some keywords (elseif,else,catch,finally) are both + " closing blocks and opening new ones + + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + call add(blocks_stack, 'if') + continue + endif + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + if len(blocks_stack) > 0 && blocks_stack[-1] == 'if' + let blocks_stack[-1] = 'elseif' + elseif (len(blocks_stack) > 0 && blocks_stack[-1] != 'elseif') || len(blocks_stack) == 0 + call add(blocks_stack, 'elseif') + let num_closed_blocks += 1 + endif + continue + endif + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + if len(blocks_stack) > 0 && blocks_stack[-1] =~ '\<\%(else\)\=if\>' + let blocks_stack[-1] = 'else' + else + call add(blocks_stack, 'else') + let num_closed_blocks += 1 + endif + continue + endif + + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + call add(blocks_stack, 'try') + continue + endif + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + if len(blocks_stack) > 0 && blocks_stack[-1] == 'try' + let blocks_stack[-1] = 'catch' + else + call add(blocks_stack, 'catch') + let num_closed_blocks += 1 + endif + continue + endif + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + if len(blocks_stack) > 0 && (blocks_stack[-1] == 'try' || blocks_stack[-1] == 'catch') + let blocks_stack[-1] = 'finally' + else + call add(blocks_stack, 'finally') + let num_closed_blocks += 1 + endif + continue + endif + + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + if i == 0 + call add(blocks_stack, 'col1module') + else + call add(blocks_stack, 'other') + endif + continue + endif + + let i = JuliaMatch(a:lnum, line, '@\@', s) + if i >= 0 && i == fb + let s = i+1 + call add(blocks_stack, 'other') + continue + endif + + " Note: it should be impossible to get here + break + + else + " The first occurrence is an 'end' + + let s = fe+1 + if len(blocks_stack) == 0 + let num_closed_blocks += 1 + else + call remove(blocks_stack, -1) + endif + continue + + endif + + " Note: it should be impossible to get here + break + endwhile + let num_open_blocks = len(blocks_stack) - count(blocks_stack, 'col1module') + return [num_open_blocks, num_closed_blocks] +endfunction + +function GetJuliaIndent() + let s:save_ignorecase = &ignorecase + set noignorecase + + " Find a non-blank line above the current line. + let lnum = prevnonblank(v:lnum - 1) + + " At the start of the file use zero indent. + if lnum == 0 + let &ignorecase = s:save_ignorecase + unlet s:save_ignorecase + return 0 + endif + + let ind = indent(lnum) + + " Analyse previous line + let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum) + + " Increase indentation for each newly opened block + " in the previous line + while num_open_blocks > 0 + let ind += &sw + let num_open_blocks -= 1 + endwhile + + " Analyse current line + let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(v:lnum) + + " Decrease indentation for each closed block + " in the current line + while num_closed_blocks > 0 + let ind -= &sw + let num_closed_blocks -= 1 + endwhile + + let &ignorecase = s:save_ignorecase + unlet s:save_ignorecase + return ind +endfunction diff --git a/syntax/julia.vim b/syntax/julia.vim new file mode 100644 index 0000000..9dab3c8 --- /dev/null +++ b/syntax/julia.vim @@ -0,0 +1,149 @@ + +if exists("b:current_syntax") + finish +endif + +syn case match + + +syn keyword juliaDirective import importall export using require include + +hi def link juliaDirective Include + +syn region juliaDeclTypeBlock transparent matchgroup=juliaDeclType start="\<\%(type\|immutable\)\>" end="\" contains=ALL +syn keyword juliaTypeAlias typealias +syn keyword juliaDeclAbstract abstract + +hi def link juliaDeclType Structure +hi def link juliaTypeAlias Typedef +hi def link juliaDeclAbstract Structure + +" Module +syn region juliaModuleBlock transparent matchgroup=juliaModule start="\" end="\" contains=ALL + +hi def link juliaModule Structure + + +" Misc. blocks +syn region juliaMiscBlockBlock transparent matchgroup=juliaMiscBlock start="\<\%(quote\|do\|begin\|let\)\>" end="\" contains=ALL + +hi def link juliaMiscBlock Repeat + +" Braces and Brackets +syn region juliaBracketsBlock matchgroup=juliaBrackets start='\[' end='\]' contains=ALLBUT,juliaRepeatBlock contained +syn region juliaBracesBlock matchgroup=juliaBraces start='{' end='}' contains=ALLBUT,juliaRepeatBlock contained + +" Repeat +syn region juliaRepeatBlock transparent matchgroup=juliaRepeat start="\<\%(while\|for\)\>" end="\" contains=@juliaTop + +hi def link juliaRepeat Repeat + +" Conditional +syn keyword juliaElse else elseif +syn region juliaIfBlock transparent matchgroup=juliaIf start="\" end="\" contains=@juliaTop + +hi def link juliaElse Conditional +hi def link juliaIf Conditional + + +" try catch end +syn keyword juliaCatch catch contained +syn region juliaTryBlock transparent matchgroup=juliaTry start="\" end="\" contains=@juliaTop + +hi def link juliaTry Exception +hi def link juliaCatch Exception + + +" one word statements +syn keyword juliaStatement return continue break + +hi def link juliaStatement Statement + +" misc +syn keyword juliaDeclaration const global local +syn keyword juliaComprehensionFor for + +hi def link juliaDeclaration Keyword +hi def link juliaComprehensionFor Keyword + +" Built in types +syn keyword juliaType Uint Uint8 Uint16 Uint32 Uint64 Uint128 +syn keyword juliaType Int Int8 Int16 Int32 Int64 Int128 +syn keyword juliaType Float Float16 Float32 Float64 +syn keyword juliaType AbstractArray AbstractMatrix AbstractVector Array Vector Matrix +syn keyword juliaType String ByteString UTF8String SubString +syn keyword juliaType Bool Nothing Union Type + + +hi def link juliaType Type + + +" Comments +syn keyword juliaTodo contained TODO FIXME XXX +syn cluster juliaCommentGroup contains=juliaTodo +syn region juliaComment start="#" end="$" contains=@juliaCommentGroup,@Spell + +hi def link juliaComment Comment +hi def link juliaTodo Todo + + +" Strings +syn region juliaString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@juliaStringGroup,@Spell +syn region juliaTripleString start=+"""+ end=+"""+ +syn region juliaCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@juliaCharacterGroup + +hi def link juliaString String +hi def link juliaTripleString String +hi def link juliaCharacter Character + + +" Functions +syn region juliaFunctionBlock transparent matchgroup=juliaFunction start="\<\%\(function\|macro\)\>" end="\" contains=@juliaTop +hi def link juliaFunction Function + + +" Numbers +syn match juliaNumber "\<\d\+\([Ee]\d\+\)\?\>" +syn match juliaNumber "\<0x\x\+\>" +syn match juliaNumber "\<0\o\+\>" + +syn match juliaFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>" +syn match juliaFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>" +syn match juliaFloat "\<\d\+[Ee][-+]\d\+\>" +syn keyword juliaFloatSpecial NaN Inf + +hi def link juliaNumber Number +hi def link juliaFloat Float +hi def link juliaFloatSpecial Float + + +" Operators +syn keyword juliaIn in +hi def link juliaIn Operator + + +" Constants +syn keyword juliaBool true false nothing +hi def link juliaBool Boolean + +syn keyword juliaIdentifierSpecial STDOUT, STDIN, STDERR + +hi def link juliaIdentifierSpecial Identifier + + +" Macros +syn match juliaMacro display "@[_[:alpha:]][_[:alnum:]!]*\%(\.[_[:alpha:]][_[:alnum:]!]*\)*" + +hi def link juliaMacro Macro + + +syn cluster juliaTop contains=ALLBUT,juliaComprehensionFor + +" Ragel +syn include @ragel syntax/ragel.vim +syn region ragelLine start="%%" end="$" contains=@ragel + + +let b:current_syntax = "julia" + + diff --git a/syntax/ragel.vim b/syntax/ragel.vim new file mode 100644 index 0000000..67ade16 --- /dev/null +++ b/syntax/ragel.vim @@ -0,0 +1,164 @@ +" Vim syntax file +" +" Language: Ragel +" Author: Adrian Thurston + +syntax clear + +if !exists("g:ragel_default_subtype") + let g:ragel_default_subtype = 'c' +endif + +function! Split(path) abort " {{{1 + if type(a:path) == type([]) | return a:path | endif + let split = split(a:path,'\\\@ReadOnPath(script) + for dir in Split(&rtp) + let filepath = dir.'/'.a:script + if filereadable(filepath) + return join(readfile(filepath), " | ") + endif + endfor +endfun + +" Try to detect the subtype. stolen from eruby.vim +if !exists("b:ragel_subtype") || b:ragel_subtype == '' + " first check for an annotation in the first 5 lines or on the last line + let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") + let b:ragel_subtype = matchstr(s:lines, 'ragel_subtype=\zs\w\+') + + " failing that, check the filename for .*.rl + if b:ragel_subtype == '' + let b:ragel_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.rl\|\.ragel\)\+$','',''),'\.\zs\w\+$') + + " ...and do a couple of transformations if necessary + + " .rb -> ruby + if b:ragel_subtype == 'rb' + let b:ragel_subtype = 'ruby' + + " .m -> objc + elseif b:ragel_subtype == 'm' + let b:ragel_subtype = 'objc' + + " .cxx -> cpp + elseif b:ragel_subtype == 'cxx' + let b:ragel_subtype = 'cpp' + endif + endif + + " default to g:ragel_default_subtype + if b:ragel_subtype == '' + let b:ragel_subtype = g:ragel_default_subtype + endif +endif + +if exists('b:ragel_subtype') && b:ragel_subtype != '' + exec 'runtime! syntax/'.b:ragel_subtype.'.vim' + " source s:subtype_file + unlet! b:current_syntax +endif + +" Identifiers +syntax match anyId "[a-zA-Z_][a-zA-Z_0-9]*" contained + +" Inline code only +syntax keyword fsmType fpc fc fcurs fbuf fblen ftargs fstack contained +syntax keyword fsmKeyword fhold fgoto fcall fret fentry fnext fexec fbreak contained + +syntax cluster rlItems contains=rlComment,rlLiteral,rlAugmentOps,rlOtherOps,rlKeywords,rlWrite,rlCodeCurly,rlCodeSemi,rlNumber,anyId,rlLabelColon,rlExprKeywords + +syntax region machineSpec1 matchgroup=beginRL start="%%{" end="}%%" contains=@rlItems +syntax region machineSpec2 matchgroup=beginRL start="%%[^{]"rs=e-1 end="$" keepend contains=@rlItems +syntax region machineSpec2 matchgroup=beginRL start="%%$" end="$" keepend contains=@rlItems + +" Comments +syntax match rlComment "#.*$" contained + +" Literals +" single quoted strings '...' + syntax match rlLiteral "'\(\\.\|[^'\\]\)*'[i]*" contained +" double quoted strings "..." + syntax match rlLiteral "\"\(\\.\|[^\"\\]\)*\"[i]*" contained +" simple regexes /.../ + syntax match rlLiteral /\/\(\\.\|[^\/\\]\)*\/[i]*/ contained +" char unions [...] + syntax match rlLiteral "\[\(\\.\|[^\]\\]\)*\]" contained + +" Numbers +syntax match rlNumber "[0-9][0-9]*" contained +syntax match rlNumber "0x[0-9a-fA-F][0-9a-fA-F]*" contained + +" Operators +syntax match rlAugmentOps "[>$%@]" contained +syntax match rlAugmentOps "<>\|<" contained +syntax match rlAugmentOps "[>\<$%@][!\^/*~]" contained +syntax match rlAugmentOps "[>$%]?" contained +syntax match rlAugmentOps "<>[!\^/*~]" contained +syntax match rlAugmentOps "=>" contained +syntax match rlOtherOps "->" contained + +syntax match rlOtherOps ":>" contained +syntax match rlOtherOps ":>>" contained +syntax match rlOtherOps "<:" contained + +" Keywords +" FIXME: Enable the range keyword post 5.17. +" syntax keyword rlKeywords machine action context include range contained +syntax keyword rlKeywords machine action context include import export prepush postpop contained +syntax keyword rlExprKeywords when inwhen outwhen err lerr eof from to contained + +" Case Labels +syntax keyword caseLabelKeyword case contained +syntax cluster caseLabelItems contains=caseLabelKeyword,anyId,fsmType,fsmKeyword +syntax match caseLabelColon "case" contains=@caseLabelItems contained +syntax match caseLabelColon "case[\t ]\+.*:$" contains=@caseLabelItems contained +syntax match caseLabelColon "case[\t ]\+.*:[^=:]"me=e-1 contains=@caseLabelItems contained + +syntax match rlLabelColon "[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:$" contained contains=anyLabel +syntax match rlLabelColon "[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:[^=:>]"me=e-1 contained contains=anyLabel +syntax match anyLabel "[a-zA-Z_][a-zA-Z_0-9]*" contained + +" All items that can go in a code block. + +syntax cluster inlineItems contains=TOP add=anyId,fsmType,fsmKeyword,caseLabelColon + +" Blocks of code. rlCodeCurly is recursive. +syntax region rlCodeCurly matchgroup=NONE start="{" end="}" keepend contained contains=TOP +syntax region rlCodeSemi matchgroup=Type start="\" start="\" start="\" start="\" matchgroup=NONE end=";" contained contains=@inlineItems + +syntax region rlWrite matchgroup=Type start="\" matchgroup=NONE end="[;)]" contained contains=rlWriteKeywords,rlWriteOptions + +syntax keyword rlWriteKeywords init data exec exports start error first_final contained +syntax keyword rlWriteOptions noerror nofinal noprefix noend nocs contained + +" +" Sync at the start of machine specs. +" +" Match The ragel delimiters only if there quotes no ahead on the same line. +" On the open marker, use & to consume the leader. +syntax sync match ragelSyncPat grouphere NONE "^[^\'\"%]*%%{&^[^\'\"%]*" +syntax sync match ragelSyncPat grouphere NONE "^[^\'\"%]*%%[^{]&^[^\'\"%]*" +syntax sync match ragelSyncPat grouphere NONE "^[^\'\"]*}%%" + +" +" Specifying Groups +" +hi link rlComment Comment +hi link rlNumber Number +hi link rlLiteral String +hi link rlAugmentOps Keyword +hi link rlExprKeywords Keyword +hi link rlWriteKeywords Keyword +hi link rlWriteOptions Keyword +hi link rlKeywords Type +hi link fsmType Type +hi link fsmKeyword Keyword +hi link anyLabel Label +hi link caseLabelKeyword Keyword +hi link beginRL Type + +let b:current_syntax = "ragel"