diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 1 | ||||
| -rwxr-xr-x | build | 1 | ||||
| -rw-r--r-- | ftdetect/polyglot.vim | 6 | ||||
| -rw-r--r-- | indent/fsharp.vim | 253 | ||||
| -rw-r--r-- | syntax/fsharp.vim | 269 | 
5 files changed, 530 insertions, 0 deletions
| @@ -62,6 +62,7 @@ If you need full functionality of any plugin, please use it directly with your p  - [emblem](https://github.com/yalesov/vim-emblem) (syntax, indent, ftplugin)  - [erlang](https://github.com/vim-erlang/vim-erlang-runtime) (syntax, indent)  - [fish](https://github.com/dag/vim-fish) (syntax, indent, compiler, autoload, ftplugin) +- [fsharp](https://github.com/fsharp/vim-fsharp) (syntax, indent)  - [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin)  - [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent)  - [gmpl](https://github.com/maelvalais/gmpl.vim) (syntax) @@ -134,6 +134,7 @@ PACKS="    emblem:yalesov/vim-emblem    erlang:vim-erlang/vim-erlang-runtime    fish:dag/vim-fish +  fsharp:fsharp/vim-fsharp:_BASIC    git:tpope/vim-git    gmpl:maelvalais/gmpl.vim    openscad:sirtaj/vim-openscad diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 784fac46..a88c50e9 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -262,6 +262,12 @@ autocmd BufNewFile ~/.config/fish/functions/*.fish  augroup END  augroup filetypedetect +" fsharp:fsharp/vim-fsharp:_BASIC +" F#, fsharp +autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx set filetype=fsharp +augroup END + +augroup filetypedetect  " git:tpope/vim-git  " Git  autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit diff --git a/indent/fsharp.vim b/indent/fsharp.vim new file mode 100644 index 00000000..bdc3e3f9 --- /dev/null +++ b/indent/fsharp.vim @@ -0,0 +1,253 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fsharp') == -1 +   +" Vim indent file +" Language:     FSharp +" Maintainers:  Jean-Francois Yuen   <jfyuen@happycoders.org> +"               Mike Leary           <leary@nwlink.com> +"               Markus Mottl         <markus.mottl@gmail.com> +"               Rudi Grinberg        <rudi.grinberg@gmail.com> +"               Gregor Uhlenheuer    <kongo2002@gmail.com> +" Last Change:  2013 Jun 29 +"               2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working +"               2005 May 09 - Added an option to not indent OCaml-indents specially (MM) +"               2013 June   - commented textwidth (Marc Weber) +"               2014 August - Ported to F# +"               2014 August - F# specific cleanup +" +" Marc Weber's comment: This file may contain a lot of (very custom) stuff +" which eventually should be moved somewhere else .. + +" Only load this indent file when no other was loaded. + +if exists("b:did_indent") +    finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetFsharpIndent() +setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0) + +" Only define the function once. +if exists("*GetFsharpIndent") +    finish +endif + +" Skipping pattern, for comments +function! s:GetLineWithoutFullComment(lnum) +    let lnum = prevnonblank(a:lnum - 1) +    let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '') +    while lline =~ '^\s*$' && lnum > 0 +        let lnum = prevnonblank(lnum - 1) +        let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '') +    endwhile +    return lnum +endfunction + +" Indent for ';;' to match multiple 'let' +function! s:GetInd(lnum, pat, lim) +    let llet = search(a:pat, 'bW') +    let old = indent(a:lnum) +    while llet > 0 +        let old = indent(llet) +        let nb = s:GetLineWithoutFullComment(llet) +        if getline(nb) =~ a:lim +            return old +        endif +        let llet = search(a:pat, 'bW') +    endwhile +    return old +endfunction + +" Indent pairs +function! s:FindPair(pstart, pmid, pend) +    call search(a:pend, 'bW') +    return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')) +endfunction + +" Indent 'let' +function! s:FindLet(pstart, pmid, pend) +    call search(a:pend, 'bW') +    return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\<in\\s*$" || getline(prevnonblank(".") - 1) =~ s:beflet')) +endfunction + +function! GetFsharpIndent() +    " Find a non-commented line above the current line. +    let lnum = s:GetLineWithoutFullComment(v:lnum) + +    " At the start of the file use zero indent. +    if lnum == 0 +        return 0 +    endif + +    let ind = indent(lnum) +    let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '') + +    " " Return single 'shiftwidth' after lines matching: +    " if lline =~ '^\s*|.*->\s*$' +    "     return ind + &sw +    " endif + +    let line = getline(v:lnum) + +    " Indent if current line begins with 'end': +    if line =~ '^\s*end\>' +        return s:FindPair(s:module, '','\<end\>') + +        " Indent if current line begins with 'done' for 'do': +    elseif line =~ '^\s*done\>' +        return s:FindPair('\<do\>', '','\<done\>') + +        " Indent if current line begins with '}' or '>}': +    elseif line =~ '^\s*\(\|>\)}' +        return s:FindPair('{', '','}') + +        " Indent if current line begins with ']', '|]' or '>]': +    elseif line =~ '^\s*\(\||\|>\)\]' +        return s:FindPair('\[', '','\]') + +        " Indent if current line begins with ')': +    elseif line =~ '^\s*)' +        return s:FindPair('(', '',')') + +        " Indent if current line begins with 'let': +    elseif line =~ '^\s*let\>' +        if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet +            return s:FindLet(s:type, '','\<let\s*$') +        endif + +        " Indent if current line begins with 'class' or 'type': +    elseif line =~ '^\s*\(class\|type\)\>' +        if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim +            return s:FindLet(s:type, '','\<\(class\|type\)\s*$') +        endif + +        " Indent for pattern matching: +    elseif line =~ '^\s*|' +        if lline !~ '^\s*\(|[^\]]\|\(match\|type\|with\)\>\)\|\<\(function\|private\|with\)\s*$' +            call search('|', 'bW') +            return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"')) +        endif + +        " Indent if current line begins with ';;': +    elseif line =~ '^\s*;;' +        if lline !~ ';;\s*$' +            return s:GetInd(v:lnum, s:letpat, s:letlim) +        endif + +        " Indent if current line begins with 'in': +    elseif line =~ '^\s*in\>' +        if lline !~ '^\s*\(let\|and\)\>' +            return s:FindPair('\<let\>', '', '\<in\>') +        endif + +        " Indent if current line begins with 'else': +    elseif line =~ '^\s*else\>' +        if lline !~ '^\s*\(if\|then\)\>' +            return s:FindPair('\<if\>', '', '\<else\>') +        endif + +        " Indent if current line begins with 'then': +    elseif line =~ '^\s*then\>' +        if lline !~ '^\s*\(if\|else\)\>' +            return s:FindPair('\<if\>', '', '\<then\>') +        endif + +        " Indent if current line begins with 'and': +    elseif line =~ '^\s*and\>' +        if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$' +            return ind - &sw +        endif + +        " Indent if current line begins with 'with': +    elseif line =~ '^\s*with\>' +        if lline !~ '^\s*\(match\|try\)\>' +            return s:FindPair('\<\%(match\|try\)\>', '','\<with\>') +        endif + +        " Indent if current line begins with 'exception', 'external', 'include' or +        " 'open': +    elseif line =~ '^\s*\(exception\|external\|include\|open\)\>' +        if lline !~ s:lim . '\|' . s:letlim +            call search(line) +            return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW')) +        endif + +        " Indent if current line begins with 'val': +    elseif line =~ '^\s*val\>' +        if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim +            return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW')) +        endif + +        " Indent if current line begins with 'constraint', 'inherit', 'initializer' +        " or 'method': +    elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>' +        if lline !~ s:obj +            return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw +        endif + +    endif + +    " Add a 'shiftwidth' after lines ending with: +    if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$' +        let ind = ind + &sw + +        " Back to normal indent after lines ending with ';;': +    elseif lline =~ ';;\s*$' && lline !~ '^\s*;;' +        let ind = s:GetInd(v:lnum, s:letpat, s:letlim) + +        " Back to normal indent after lines ending with 'end': +    elseif lline =~ '\<end\s*$' +        let ind = s:FindPair(s:module, '','\<end\>') + +        " Back to normal indent after lines ending with 'in': +    elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>' +        let ind = s:FindPair('\<let\>', '', '\<in\>') + +        " Back to normal indent after lines ending with 'done': +    elseif lline =~ '\<done\s*$' +        let ind = s:FindPair('\<do\>', '','\<done\>') + +        " Back to normal indent after lines ending with '}' or '>}': +    elseif lline =~ '\(\|>\)}\s*$' +        let ind = s:FindPair('{', '','}') + +        " Back to normal indent after lines ending with ']', '|]' or '>]': +    elseif lline =~ '\(\||\|>\)\]\s*$' +        let ind = s:FindPair('\[', '','\]') + +        " Back to normal indent after comments: +    elseif lline =~ '\*)\s*$' +        call search('\*)', 'bW') +        let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) + +        " Back to normal indent after lines ending with ')': +    elseif lline =~ ')\s*$' +        let ind = s:FindPair('(', '',')') + +        " If this is a multiline comment then align '*': +    elseif lline =~ '^\s*(\*' && line =~ '^\s*\*' +        let ind = ind + 1 + +    else +        " Don't change indentation of this line +        " for new lines (indent==0) use indentation of previous line + +        " This is for preventing removing indentation of these args: +        "   let f x = +        "     let y = x + 1 in +        "     Printf.printf +        "       "o"           << here +        "       "oeuth"       << don't touch indentation + +        let i = indent(v:lnum) +        return i == 0 ? ind : i + +    endif + +    return ind + +endfunction + +" vim: sw=4 et sts=4 + +endif diff --git a/syntax/fsharp.vim b/syntax/fsharp.vim new file mode 100644 index 00000000..f66daa01 --- /dev/null +++ b/syntax/fsharp.vim @@ -0,0 +1,269 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fsharp') == -1 +   +" Vim syntax file +" Language:     F# +" Last Change:  Sun 19 Oct 2014 11:11:44 PM CEST +" Maintainer:   Gregor Uhlenheuer <kongo2002@googlemail.com> +" +" Note:         This syntax file is a complete rewrite of the original version +"               of fs.vim from Choy Rim <choy.rim@gmail.com> and a slight +"               modified version from Thomas Schank <ThomasSchank@gmail.com> + +if version < 600 +    syntax clear +elseif exists('b:current_syntax') +    finish +endif + +" F# is case sensitive. +syn case match + +" reset 'iskeyword' setting +setl isk&vim + +" Scripting/preprocessor directives +syn match    fsharpSScript "^\s*#\S\+" transparent contains=fsharpScript,fsharpRegion,fsharpPreCondit + +syn match    fsharpScript contained "#" +syn keyword  fsharpScript contained quitlabels warnings directory cd load use +syn keyword  fsharpScript contained install_printer remove_printer requirethread +syn keyword  fsharpScript contained trace untrace untrace_all print_depth +syn keyword  fsharpScript contained print_length define undef if elif else endif +syn keyword  fsharpScript contained line error warning light nowarn + + +" comments +syn match    fsharpSingleLineComment "//.*$" contains=fsharpTodo,@Spell +syn region   fsharpDocComment start="///" end="$" contains=fsharpTodo,fsharpXml,@Spell keepend oneline +syn region   fsharpXml matchgroup=fsharpXmlDoc start="<[^>]\+>" end="</[^>]\+>" contained contains=fsharpXml + +" Double-backtick identifiers +syn region   fsharpDoubleBacktick start="``" end="``" keepend oneline + + +" symbol names +syn match fsharpSymbol "\%(let\|use\|mutable\|rec\|and\|private\)\@<=!\=\s\+\zs\w\+\ze\s*[^=:]*[=:]" +syn match fsharpSymbol "\%(member\)\@<=\s\+\w\+\.\zs\w\+" + + +" types +syn match    fsharpTypeName   "\%(\<type\s\+\)\@<=\w\+" + + +" errors +syn match    fsharpBraceErr   "}" +syn match    fsharpBrackErr   "\]" +syn match    fsharpParenErr   ")" +syn match    fsharpArrErr     "|]" +syn match    fsharpCommentErr "\*)" + + +" enclosing delimiters +syn region   fsharpEncl transparent matchgroup=fsharpKeyword start="(" matchgroup=fsharpKeyword end=")" contains=ALLBUT,fsharpParenErr,fsharpScript +syn region   fsharpEncl transparent matchgroup=fsharpKeyword start="{" matchgroup=fsharpKeyword end="}"  contains=ALLBUT,fsharpBraceErr,fsharpScript +syn region   fsharpEncl transparent matchgroup=fsharpKeyword start="\[" matchgroup=fsharpKeyword end="\]" contains=ALLBUT,fsharpBrackErr,fsharpScript +syn region   fsharpEncl transparent matchgroup=fsharpKeyword start="\[|" matchgroup=fsharpKeyword end="|\]" contains=ALLBUT,fsharpArrErr,fsharpScript + + +" comments +syn region   fsharpMultiLineComment start="(\*" end="\*)" contains=fsharpTodo +syn keyword  fsharpTodo contained TODO FIXME XXX NOTE + +" keywords +syn keyword fsharpKeyword    abstract as assert base begin class default delegate +syn keyword fsharpKeyword    do done downcast downto elif else end exception +syn keyword fsharpKeyword    extern for fun function global if in inherit inline +syn keyword fsharpKeyword    interface lazy let match member module mutable +syn keyword fsharpKeyword    namespace new of override rec static struct then +syn keyword fsharpKeyword    to type upcast use val void when while with + +syn keyword fsharpKeyword    async atomic break checked component const constraint +syn keyword fsharpKeyword    constructor continue decimal eager event external +syn keyword fsharpKeyword    fixed functor include method mixin object parallel +syn keyword fsharpKeyword    process pure return seq tailcall trait + +" additional operator keywords (Microsoft.FSharp.Core.Operators) +syn keyword fsharpKeyword    box hash sizeof typeof typedefof unbox ref fst snd +syn keyword fsharpKeyword    stdin stdout stderr + +" math operators (Microsoft.FSharp.Core.Operators) +syn keyword fsharpKeyword    abs acos asin atan atan2 ceil cos cosh exp floor log +syn keyword fsharpKeyword    log10 pown round sign sin sinh sqrt tan tanh + +syn keyword fsharpOCaml      asr land lor lsl lsr lxor mod sig + +if !exists('g:fsharp_no_linq') || g:fsharp_no_linq == 0 +    syn keyword fsharpLinq   orderBy select where yield +endif + +" open +syn keyword fsharpOpen       open + +" exceptions +syn keyword fsharpException  try failwith failwithf finally invalid_arg raise +syn keyword fsharpException  rethrow + +" modifiers +syn keyword fsharpModifier   abstract const extern internal override private +syn keyword fsharpModifier   protected public readonly sealed static virtual +syn keyword fsharpModifier   volatile + +" constants +syn keyword fsharpConstant   null +syn keyword fsharpBoolean    false true + +" types +syn keyword  fsharpType      array bool byte char decimal double enum exn float +syn keyword  fsharpType      float32 int int16 int32 int64 lazy_t list nativeint +syn keyword  fsharpType      obj option sbyte single string uint uint32 uint64 +syn keyword  fsharpType      uint16 unativeint unit + +" core classes +syn match    fsharpCore      "\u\a*\." transparent contains=fsharpCoreClass + +syn keyword  fsharpCoreClass Array Async Directory File List Option Path Map Set contained +syn keyword  fsharpCoreClass String Seq Tuple contained + +syn keyword fsharpCoreMethod printf printfn sprintf eprintf eprintfn fprintf +syn keyword fsharpCoreMethod fprintfn + +" options +syn keyword  fsharpOption    Some None + +" operators +syn keyword fsharpOperator   not and or + +syn match   fsharpFormat     display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bscdiuxXoEefFgGMOAat]\|\[\^\=.[^]]*\]\)" contained + +syn match    fsharpCharacter    "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'" +syn match    fsharpCharErr      "'\\\d\d'\|'\\\d'" +syn match    fsharpCharErr      "'\\[^\'ntbr]'" +syn region   fsharpString       start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=fsharpFormat +syn region   fsharpString       start=+"""+ skip=+\\\\\|\\"+ end=+"""+ contains=fsharpFormat +syn region   fsharpString       start=+@"+ skip=+""+ end=+"+ contains=fsharpFormat + +syn match    fsharpFunDef       "->" +syn match    fsharpRefAssign    ":=" +syn match    fsharpTopStop      ";;" +syn match    fsharpOperator     "\^" +syn match    fsharpOperator     "::" + +syn match    fsharpLabel        "\<_\>" + +syn match    fsharpOperator     "&&" +syn match    fsharpOperator     "<" +syn match    fsharpOperator     ">" +syn match    fsharpOperator     "|>" +syn match    fsharpOperator     ":>" +syn match    fsharpOperator     ":?>" +syn match    fsharpOperator     "&&&" +syn match    fsharpOperator     "|||" +syn match    fsharpOperator     "\.\." + +syn match    fsharpKeyChar      "|[^\]]"me=e-1 +syn match    fsharpKeyChar      ";" +syn match    fsharpKeyChar      "\~" +syn match    fsharpKeyChar      "?" +syn match    fsharpKeyChar      "\*" +syn match    fsharpKeyChar      "+" +syn match    fsharpKeyChar      "=" +syn match    fsharpKeyChar      "|" +syn match    fsharpKeyChar      "(\*)" + +syn match    fsharpOperator     "<-" + +syn match    fsharpNumber        "\<\d\+" +syn match    fsharpNumber        "\<-\=\d\(_\|\d\)*\(u\|u\?[yslLn]\|UL\)\?\>" +syn match    fsharpNumber        "\<-\=0[x|X]\(\x\|_\)\+\(u\|u\?[yslLn]\|UL\)\?\>" +syn match    fsharpNumber        "\<-\=0[o|O]\(\o\|_\)\+\(u\|u\?[yslLn]\|UL\)\?\>" +syn match    fsharpNumber        "\<-\=0[b|B]\([01]\|_\)\+\(u\|u\?[yslLn]\|UL\)\?\>" +syn match    fsharpFloat         "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" +syn match    fsharpFloat         "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" +syn match    fsharpFloat         "\<\d\+\.\d*" + +" modules +syn match    fsharpModule     "\%(\<open\s\+\)\@<=[a-zA-Z.]\+" + +" attributes +syn region   fsharpAttrib matchgroup=fsharpAttribute start="\[<" end=">]" + +" regions +syn region   fsharpRegion matchgroup=fsharpPreCondit start="\%(end\)\@<!region.*$" +            \ end="endregion" fold contains=ALL contained + +if version >= 508 || !exists("did_fs_syntax_inits") +    if version < 508 +        let did_fs_syntax_inits = 1 +        command -nargs=+ HiLink hi link <args> +    else +        command -nargs=+ HiLink hi def link <args> +    endif + +    HiLink fsharpBraceErr          Error +    HiLink fsharpBrackErr          Error +    HiLink fsharpParenErr          Error +    HiLink fsharpArrErr            Error +    HiLink fsharpCommentErr        Error + +    HiLink fsharpSingleLineComment Comment +    HiLink fsharpMultiLineComment  Comment +    HiLink fsharpDocComment        Comment +    HiLink fsharpXml               Comment +    HiLink fsharpDoubleBacktick    String + +    HiLink fsharpOpen              Include +    HiLink fsharpModPath           Include +    HiLink fsharpScript            Include +    HiLink fsharpPreCondit         Include + +    HiLink fsharpKeyword           Keyword +    HiLink fsharpCoreMethod        Keyword + +    HiLink fsharpOCaml             Statement +    HiLink fsharpLinq              Statement + +    HiLink fsharpSymbol            Function + +    HiLink fsharpFunDef            Operator +    HiLink fsharpRefAssign         Operator +    HiLink fsharpTopStop           Operator +    HiLink fsharpKeyChar           Operator +    HiLink fsharpOperator          Operator + +    HiLink fsharpBoolean           Boolean +    HiLink fsharpConstant          Constant +    HiLink fsharpCharacter         Character +    HiLink fsharpNumber            Number +    HiLink fsharpFloat             Float + +    HiLink fsharpString            String +    HiLink fsharpFormat            Special + +    HiLink fsharpModifier          StorageClass + +    HiLink fsharpException         Exception + +    HiLink fsharpLabel             Identifier +    HiLink fsharpOption            Identifier +    HiLink fsharpTypeName          Identifier +    HiLink fsharpModule            Identifier + +    HiLink fsharpType              Type + +    HiLink fsharpCoreClass         Typedef +    HiLink fsharpAttrib            Typedef +    HiLink fsharpXmlDoc            Typedef + +    HiLink fsharpTodo              Todo + +    HiLink fsharpEncl              Delimiter +    HiLink fsharpAttribute         Delimiter + +    delcommand HiLink +endif + +let b:current_syntax = 'fsharp' + +" vim: sw=4 et sts=4 + +endif | 
