From 8b3418cab8eb5267b3a5743e4d5fe5f698d48bc8 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 27 Sep 2017 19:57:29 +0200 Subject: Update --- README.md | 4 +- after/ftplugin/jsx.vim | 2 +- after/ftplugin/terraform.vim | 19 +- after/syntax/c.vim | 8 +- after/syntax/cpp.vim | 67 ++++- after/syntax/javascript/graphql.vim | 21 ++ after/syntax/yaml.vim | 2 +- autoload/crystal_lang.vim | 2 +- autoload/dart.vim | 8 +- autoload/elixir/indent.vim | 298 ++++++++++++++------- autoload/rust.vim | 87 +++--- autoload/rustfmt.vim | 141 +++++----- autoload/xml/html5.vim | 2 +- compiler/cargo.vim | 19 +- compiler/rake.vim | 8 +- compiler/rustc.vim | 3 +- compiler/typescript.vim | 12 +- extras/flow.vim | 45 ++-- extras/jsdoc.vim | 2 +- ftdetect/polyglot.vim | 35 ++- ftplugin/eruby.vim | 4 +- ftplugin/gitrebase.vim | 11 +- ftplugin/graphql.vim | 2 +- ftplugin/ps1.vim | 2 - ftplugin/ps1xml.vim | 2 - ftplugin/purescript.vim | 37 +++ ftplugin/ruby.vim | 1 + ftplugin/rust.vim | 13 +- indent/elixir.vim | 37 +-- indent/eruby.vim | 2 +- indent/graphql.vim | 81 ++++++ indent/haskell.vim | 19 +- indent/html.vim | 44 ++- indent/javascript.vim | 517 ++++++++++++++++++------------------ indent/kotlin.vim | 18 +- indent/lua.vim | 16 +- indent/mako.vim | 5 +- indent/plantuml.vim | 2 +- indent/purescript.vim | 203 +++++++++++--- indent/rust.vim | 15 +- indent/swift.vim | 6 +- indent/terraform.vim | 4 +- indent/vue.vim | 6 +- syntax/ansible.vim | 66 ++++- syntax/cpp.vim | 3 +- syntax/dart.vim | 51 ++-- syntax/elixir.vim | 28 +- syntax/erlang.vim | 6 +- syntax/eruby.vim | 4 +- syntax/glsl.vim | 43 ++- syntax/go.vim | 137 +++++++--- syntax/graphql.vim | 9 +- syntax/haskell.vim | 4 +- syntax/html.vim | 2 +- syntax/javascript.vim | 50 ++-- syntax/kotlin.vim | 10 +- syntax/mako.vim | 25 +- syntax/nginx.vim | 6 +- syntax/php.vim | 33 ++- syntax/plantuml.vim | 58 ++-- syntax/purescript.vim | 22 +- syntax/ruby.vim | 105 +++++--- syntax/rust.vim | 19 +- syntax/swift.vim | 8 +- syntax/terraform.vim | 95 ++++++- syntax/toml.vim | 2 + syntax/vala.vim | 3 +- syntax/vue.vim | 22 +- 68 files changed, 1745 insertions(+), 898 deletions(-) create mode 100644 after/syntax/javascript/graphql.vim create mode 100644 indent/graphql.vim diff --git a/README.md b/README.md index 92c39450..637b22f5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ If you need full functionality of any plugin, please use it directly with your p - [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent) - [gnuplot](https://github.com/vim-scripts/gnuplot-syntax-highlighting) (syntax) - [go](https://github.com/fatih/vim-go) (syntax, compiler, indent) -- [graphql](https://github.com/jparise/vim-graphql) (syntax, ftplugin) +- [graphql](https://github.com/jparise/vim-graphql) (syntax, indent, ftplugin) - [groovy](https://github.com/vim-scripts/groovy.vim) (syntax) - [haml](https://github.com/sheerun/vim-haml) (syntax, indent, compiler, ftplugin) - [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, indent, ftplugin) @@ -103,7 +103,7 @@ If you need full functionality of any plugin, please use it directly with your p - [protobuf](https://github.com/uarun/vim-protobuf) (syntax, indent) - [pug](https://github.com/digitaltoad/vim-pug) (syntax, indent, ftplugin) - [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin) -- [purescript](https://github.com/raichoo/purescript-vim) (syntax, indent, ftplugin) +- [purescript](https://github.com/purescript-contrib/purescript-vim) (syntax, indent, ftplugin) - [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload) - [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent) - [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin) diff --git a/after/ftplugin/jsx.vim b/after/ftplugin/jsx.vim index fc76b19e..a5682895 100644 --- a/after/ftplugin/jsx.vim +++ b/after/ftplugin/jsx.vim @@ -12,7 +12,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1 if exists("loaded_matchit") let b:match_ignorecase = 0 let b:match_words = '(:),\[:\],{:},<:>,' . - \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>' + \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(/\@\|$\):<\@<=/\1>' endif setlocal suffixesadd+=.jsx diff --git a/after/ftplugin/terraform.vim b/after/ftplugin/terraform.vim index add09445..0597b428 100644 --- a/after/ftplugin/terraform.vim +++ b/after/ftplugin/terraform.vim @@ -4,6 +4,10 @@ if !exists('g:terraform_align') let g:terraform_align = 0 endif +if !exists('g:terraform_remap_spacebar') + let g:terraform_remap_spacebar = 0 +endif + if g:terraform_align && exists(':Tabularize') inoremap = =:call terraformalign()a function! s:terraformalign() @@ -31,6 +35,10 @@ function! TerraformFolds() return ">1" elseif match(thisline, '^output') >= 0 return ">1" + elseif match(thisline, '^data') >= 0 + return ">1" + elseif match(thisline, '^terraform') >= 0 + return ">1" else return "=" endif @@ -45,10 +53,13 @@ function! TerraformFoldText() endfunction setlocal foldtext=TerraformFoldText() -"inoremap za -nnoremap za -onoremap za -vnoremap zf +" Re-map the space bar to fold and unfold +if get(g:, "terraform_remap_spacebar", 1) + "inoremap za + nnoremap za + onoremap za + vnoremap zf +endif " Match the identation put in place by Hashicorp and :TerraformFmt, https://github.com/hashivim/vim-terraform/issues/21 if get(g:, "terraform_align", 1) diff --git a/after/syntax/c.vim b/after/syntax/c.vim index 8cec90f6..de14c4db 100644 --- a/after/syntax/c.vim +++ b/after/syntax/c.vim @@ -20,9 +20,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1 " ----------------------------------------------------------------------------- " Highlight function names. " ----------------------------------------------------------------------------- -syn match cCustomParen "(" contains=cParen contains=cCppParen -syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen -hi def link cCustomFunc Function +if !exists('g:cpp_no_function_highlight') + syn match cCustomParen "(" contains=cParen contains=cCppParen + syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen + hi def link cCustomFunc Function +endif " ----------------------------------------------------------------------------- " Highlight member variable names. diff --git a/after/syntax/cpp.vim b/after/syntax/cpp.vim index 4faa0f6b..c1c23987 100644 --- a/after/syntax/cpp.vim +++ b/after/syntax/cpp.vim @@ -36,9 +36,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1 " ----------------------------------------------------------------------------- " Functions -syn match cCustomParen "(" contains=cParen contains=cCppParen -syn match cCustomFunc "\w\+\s*(\@=" -hi def link cCustomFunc Function +if !exists('g:cpp_no_function_highlight') + syn match cCustomParen "(" contains=cParen contains=cCppParen + syn match cCustomFunc "\w\+\s*(\@=" + hi def link cCustomFunc Function +endif " Class and namespace scope if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight @@ -48,6 +50,52 @@ if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight hi def link cCustomClass Function endif +" Clear cppStructure and replace "class" and/or "template" with matches +" based on user configuration +let s:needs_cppstructure_match = 0 +if exists('g:cpp_class_decl_highlight') && g:cpp_class_decl_highlight + let s:needs_cppstructure_match += 1 +endif +if exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_template_highlight + let s:needs_cppstructure_match += 2 +endif + +syn clear cppStructure +if s:needs_cppstructure_match == 0 + syn keyword cppStructure typename namespace template class +elseif s:needs_cppstructure_match == 1 + syn keyword cppStructure typename namespace template +elseif s:needs_cppstructure_match == 2 + syn keyword cppStructure typename namespace class +elseif s:needs_cppstructure_match == 3 + syn keyword cppStructure typename namespace +endif +unlet s:needs_cppstructure_match + + +" Class name declaration +if exists('g:cpp_class_decl_highlight') && g:cpp_class_decl_highlight + syn match cCustomClassKey "\" + hi def link cCustomClassKey cppStructure + + " Clear cppAccess entirely and redefine as matches + syn clear cppAccess + syn match cCustomAccessKey "\" + syn match cCustomAccessKey "\" + syn match cCustomAccessKey "\" + hi def link cCustomAccessKey cppAccess + + " Match the parts of a class declaration + syn match cCustomClassName "\" + \ contains=cCustomClassKey + syn match cCustomClassName "\" + \ contains=cCustomAccessKey + syn match cCustomClassName "\" + \ contains=cCustomAccessKey + syn match cCustomClassName "\" + \ contains=cCustomAccessKey + hi def link cCustomClassName Function +endif " Template functions. " Naive implementation that sorta works in most cases. Should correctly " highlight everything in test/color2.cpp @@ -79,17 +127,12 @@ elseif exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_tem \ contains=cCustomAngleBracketStart,cCustomTemplateFunc hi def link cCustomTemplateClass cCustomClass - - " Remove 'template' from cppStructure and use a custom match - syn clear cppStructure - syn keyword cppStructure class typename namespace - syn match cCustomTemplate "\" hi def link cCustomTemplate cppStructure syn match cTemplateDeclare "\" - \ contains=cppStructure,cCustomTemplate,cCustomAngleBracketStart + \ contains=cppStructure,cCustomTemplate,cCustomClassKey,cCustomAngleBracketStart - " Remove 'operator' from cppStructure and use a custom match + " Remove 'operator' from cppOperator and use a custom match syn clear cppOperator syn keyword cppOperator typeid syn keyword cppOperator and bitor or xor compl bitand and_eq or_eq xor_eq not not_eq @@ -106,7 +149,7 @@ endif "hi def link cCustomFunc Function " Cluster for all the stdlib functions defined below -syn cluster cppSTLgroup contains=cppSTLfunction,cppSTLfunctional,cppSTLconstant,cppSTLnamespace,cppSTLtype,cppSTLexception,cppSTLiterator,cppSTLiterator_tagcppSTLenumcppSTLioscppSTLcast +syn cluster cppSTLgroup contains=cppSTLfunction,cppSTLfunctional,cppSTLconstant,cppSTLnamespace,cppSTLtype,cppSTLexception,cppSTLiterator,cppSTLiterator_tag,cppSTLenum,cppSTLios,cppSTLcast " ----------------------------------------------------------------------------- @@ -184,6 +227,7 @@ syntax keyword cppSTLfunctional binary_negate syntax keyword cppSTLfunctional bit_and syntax keyword cppSTLfunctional bit_not syntax keyword cppSTLfunctional bit_or +syntax keyword cppSTLfunctional bit_xor syntax keyword cppSTLfunctional divides syntax keyword cppSTLfunctional equal_to syntax keyword cppSTLfunctional greater @@ -699,6 +743,7 @@ syntax keyword cppSTLtype slice_array syntax keyword cppSTLtype stack syntax keyword cppSTLtype stream syntax keyword cppSTLtype streambuf +syntax keyword cppSTLtype streamsize syntax keyword cppSTLtype string syntax keyword cppSTLtype stringbuf syntax keyword cppSTLtype stringstream diff --git a/after/syntax/javascript/graphql.vim b/after/syntax/javascript/graphql.vim new file mode 100644 index 00000000..58c1de08 --- /dev/null +++ b/after/syntax/javascript/graphql.vim @@ -0,0 +1,21 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 + +if exists('b:current_syntax') + let s:current_syntax = b:current_syntax + unlet b:current_syntax +endif +syn include @GraphQLSyntax syntax/graphql.vim +if exists('s:current_syntax') + let b:current_syntax = s:current_syntax +endif + +syntax region graphqlTemplateString start=+`+ skip=+\\\(`\|$\)+ end=+`+ contains=@GraphQLSyntax,jsTemplateExpression,jsSpecial extend +exec 'syntax match graphqlTaggedTemplate +\%(' . join(g:graphql_javascript_tags, '\|') . '\)\%(`\)\@=+ nextgroup=graphqlTemplateString' + +hi def link graphqlTemplateString jsTemplateString +hi def link graphqlTaggedTemplate jsTaggedTemplate + +syn cluster jsExpression add=graphqlTaggedTemplate +syn cluster graphqlTaggedTemplate add=graphqlTemplateString + +endif diff --git a/after/syntax/yaml.vim b/after/syntax/yaml.vim index d429da68..89914cbe 100644 --- a/after/syntax/yaml.vim +++ b/after/syntax/yaml.vim @@ -39,7 +39,7 @@ syn keyword yamlConstant TRUE True true YES Yes yes ON On on syn keyword yamlConstant FALSE False false NO No no OFF Off off syn match yamlKey "^\s*\zs[^ \t\"]\+\ze\s*:" -syn match yamlKey "^\s*-\s*\zs[^ \t\"]\+\ze\s*:" +syn match yamlKey "^\s*-\s*\zs[^ \t\"\']\+\ze\s*:" syn match yamlAnchor "&\S\+" syn match yamlAlias "*\S\+" diff --git a/autoload/crystal_lang.vim b/autoload/crystal_lang.vim index 8b1252d2..01244746 100644 --- a/autoload/crystal_lang.vim +++ b/autoload/crystal_lang.vim @@ -310,7 +310,7 @@ function! crystal_lang#format(option_str) abort try call setreg('g', formatted, 'v') - silent normal! ggvG$"gp + silent normal! gg0vG$"gp finally call setreg('g', save_g_reg, save_g_regtype) let &l:selection = sel_save diff --git a/autoload/dart.vim b/autoload/dart.vim index 9f04fcc2..76013172 100644 --- a/autoload/dart.vim +++ b/autoload/dart.vim @@ -24,9 +24,11 @@ function! dart#fmt(q_args) abort let joined_lines = system(printf('dartfmt %s', a:q_args), buffer_content) if 0 == v:shell_error let win_view = winsaveview() - silent % delete _ - silent put=joined_lines - silent 1 delete _ + let lines = split(joined_lines, "\n") + silent keepjumps call setline(1, lines) + if line('$') > len(lines) + silent keepjumps execute string(len(lines)+1).',$ delete' + endif call winrestview(win_view) else let errors = split(joined_lines, "\n")[2:] diff --git a/autoload/elixir/indent.vim b/autoload/elixir/indent.vim index fd2f4a3f..4a8b5435 100644 --- a/autoload/elixir/indent.vim +++ b/autoload/elixir/indent.vim @@ -1,6 +1,51 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1 -function! elixir#indent#debug(str) +if !exists("g:elixir_indent_max_lookbehind") + let g:elixir_indent_max_lookbehind = 30 +endif + +" Return the effective value of 'shiftwidth' +function! s:sw() + return &shiftwidth == 0 ? &tabstop : &shiftwidth +endfunction + +function! elixir#indent#indent(lnum) + let lnum = a:lnum + let text = getline(lnum) + let prev_nb_lnum = prevnonblank(lnum-1) + let prev_nb_text = getline(prev_nb_lnum) + + call s:debug("==> Indenting line " . lnum) + call s:debug("text = '" . text . "'") + + let handlers = [ + \'top_of_file', + \'starts_with_end', + \'starts_with_mid_or_end_block_keyword', + \'following_trailing_do', + \'following_trailing_binary_operator', + \'starts_with_pipe', + \'starts_with_close_bracket', + \'starts_with_binary_operator', + \'inside_nested_construct', + \'starts_with_comment', + \'inside_generic_block', + \'follow_prev_nb' + \] + for handler in handlers + call s:debug('testing handler elixir#indent#handle_'.handler) + let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text) + if indent != -1 + call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent) + return indent + endif + endfor + + call s:debug("defaulting") + return 0 +endfunction + +function! s:debug(str) if exists("g:elixir_indent_debug") && g:elixir_indent_debug echom a:str endif @@ -8,14 +53,14 @@ endfunction " Returns 0 or 1 based on whether or not the text starts with the given " expression and is not a string or comment -function! elixir#indent#starts_with(text, expr, lnum) +function! s:starts_with(text, expr, lnum) let pos = match(a:text, '^\s*'.a:expr) if pos == -1 return 0 else " NOTE: @jbodah 2017-02-24: pos is the index of the match which is " zero-indexed. Add one to make it the column number - if elixir#indent#is_string_or_comment(a:lnum, pos + 1) + if s:is_string_or_comment(a:lnum, pos + 1) return 0 else return 1 @@ -25,12 +70,12 @@ endfunction " Returns 0 or 1 based on whether or not the text ends with the given " expression and is not a string or comment -function! elixir#indent#ends_with(text, expr, lnum) +function! s:ends_with(text, expr, lnum) let pos = match(a:text, a:expr.'\s*$') if pos == -1 return 0 else - if elixir#indent#is_string_or_comment(a:lnum, pos) + if s:is_string_or_comment(a:lnum, pos) return 0 else return 1 @@ -38,14 +83,9 @@ function! elixir#indent#ends_with(text, expr, lnum) end endfunction -" Returns 0 or 1 based on whether or not the text matches the given expression -function! elixir#indent#contains(text, expr) - return a:text =~ a:expr -endfunction - " Returns 0 or 1 based on whether or not the given line number and column " number pair is a string or comment -function! elixir#indent#is_string_or_comment(line, col) +function! s:is_string_or_comment(line, col) return synIDattr(synID(a:line, a:col, 1), "name") =~ '\%(String\|Comment\)' endfunction @@ -59,35 +99,19 @@ function! elixir#indent#searchpair_back_skip() if getline('.')[curr_col-1] == '' let curr_col = curr_col-1 endif - return elixir#indent#is_string_or_comment(line('.'), curr_col) -endfunction - -" DRY up searchpair calls -function! elixir#indent#searchpair_back(start, mid, end) - let line = line('.') - return searchpair(a:start, a:mid, a:end, 'bnW', "line('.') == " . line . " || elixir#indent#searchpair_back_skip()") -endfunction - -" DRY up searchpairpos calls -function! elixir#indent#searchpairpos_back(start, mid, end) - let line = line('.') - return searchpairpos(a:start, a:mid, a:end, 'bnW', "line('.') == " . line . " || elixir#indent#searchpair_back_skip()") + return s:is_string_or_comment(line('.'), curr_col) endfunction " DRY up regex for keywords that 1) makes sure we only look at complete words " and 2) ignores atoms -function! elixir#indent#keyword(expr) +function! s:keyword(expr) return ':\@:\@!' endfunction -function! elixir#indent#starts_with_comment(text) - return match(a:text, '^\s*#') != -1 -endfunction - " Start at the end of text and search backwards looking for a match. Also peek " ahead if we get a match to make sure we get a complete match. This means " that the result should be the position of the start of the right-most match -function! elixir#indent#find_last_pos(lnum, text, match) +function! s:find_last_pos(lnum, text, match) let last = len(a:text) - 1 let c = last @@ -118,13 +142,46 @@ function! elixir#indent#handle_top_of_file(_lnum, _text, prev_nb_lnum, _prev_nb_ end endfunction +function! elixir#indent#handle_follow_prev_nb(_lnum, _text, prev_nb_lnum, prev_nb_text) + return s:get_base_indent(a:prev_nb_lnum, a:prev_nb_text) +endfunction + +" Given the line at `lnum`, returns the indent of the line that acts as the 'base indent' +" for this line. In particular it traverses backwards up things like pipelines +" to find the beginning of the expression +function! s:get_base_indent(lnum, text) + let prev_nb_lnum = prevnonblank(a:lnum - 1) + let prev_nb_text = getline(prev_nb_lnum) + + let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' + let data_structure_close = '\%(\]\|}\|)\)' + let pipe = '|>' + + if s:starts_with(a:text, binary_operator, a:lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_text) + elseif s:starts_with(a:text, pipe, a:lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_text) + elseif s:ends_with(prev_nb_text, binary_operator, prev_nb_lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_text) + elseif s:ends_with(a:text, data_structure_close, a:lnum) + let data_structure_open = '\%(\[\|{\|(\)' + let close_match_idx = match(a:text, data_structure_close . '\s*$') + let _move = cursor(a:lnum, close_match_idx + 1) + let [open_match_lnum, open_match_col] = searchpairpos(data_structure_open, '', data_structure_close, 'bnW') + let open_match_text = getline(open_match_lnum) + return s:get_base_indent(open_match_lnum, open_match_text) + else + return indent(a:lnum) + endif +endfunction + " TODO: @jbodah 2017-03-31: remove function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, prev_nb_text) - if elixir#indent#ends_with(a:prev_nb_text, elixir#indent#keyword('do'), a:prev_nb_lnum) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('end'), a:lnum) + if s:ends_with(a:prev_nb_text, s:keyword('do'), a:prev_nb_lnum) + if s:starts_with(a:text, s:keyword('end'), a:lnum) return indent(a:prev_nb_lnum) else - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() end else return -1 @@ -134,23 +191,31 @@ endfunction function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text) let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' - if elixir#indent#ends_with(a:prev_nb_text, binary_operator, a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw + if s:ends_with(a:prev_nb_text, binary_operator, a:prev_nb_lnum) + return indent(a:prev_nb_lnum) + s:sw() + else + return -1 + endif +endfunction + +function! elixir#indent#handle_following_prev_end(_lnum, _text, prev_nb_lnum, prev_nb_text) + if s:ends_with(a:prev_nb_text, s:keyword('end'), a:prev_nb_lnum) + return indent(a:prev_nb_lnum) else return -1 endif endfunction function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_nb_text) - if elixir#indent#starts_with(a:text, '|>', a:lnum) + if s:starts_with(a:text, '|>', a:lnum) let match_operator = '\%(!\|=\|<\|>\)\@\|\~\)\@!' - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) if pos == -1 return indent(a:prev_nb_lnum) else let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S') if next_word_pos == -1 - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() else return pos + 1 + next_word_pos end @@ -161,7 +226,7 @@ function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_n endfunction function! elixir#indent#handle_starts_with_comment(_lnum, text, prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with_comment(a:text) + if match(a:text, '^\s*#') != -1 return indent(a:prev_nb_lnum) else return -1 @@ -169,8 +234,8 @@ function! elixir#indent#handle_starts_with_comment(_lnum, text, prev_nb_lnum, _p endfunction function! elixir#indent#handle_starts_with_end(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('end'), a:lnum) - let pair_lnum = elixir#indent#searchpair_back(elixir#indent#keyword('do\|fn'), '', elixir#indent#keyword('end').'\zs') + if s:starts_with(a:text, s:keyword('end'), a:lnum) + let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end').'\zs', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -178,8 +243,8 @@ function! elixir#indent#handle_starts_with_end(lnum, text, _prev_nb_lnum, _prev_ endfunction function! elixir#indent#handle_starts_with_mid_or_end_block_keyword(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('catch\|rescue\|after\|else'), a:lnum) - let pair_lnum = elixir#indent#searchpair_back(elixir#indent#keyword('with\|receive\|try\|if\|fn'), elixir#indent#keyword('catch\|rescue\|after\|else').'\zs', elixir#indent#keyword('end')) + if s:starts_with(a:text, s:keyword('catch\|rescue\|after\|else'), a:lnum) + let pair_lnum = searchpair(s:keyword('with\|receive\|try\|if\|fn'), s:keyword('catch\|rescue\|after\|else').'\zs', s:keyword('end'), 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -187,8 +252,8 @@ function! elixir#indent#handle_starts_with_mid_or_end_block_keyword(lnum, text, endfunction function! elixir#indent#handle_starts_with_close_bracket(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, '\%(\]\|}\|)\)', a:lnum) - let pair_lnum = elixir#indent#searchpair_back('\%(\[\|{\|(\)', '', '\%(\]\|}\|)\)') + if s:starts_with(a:text, '\%(\]\|}\|)\)', a:lnum) + let pair_lnum = searchpair('\%(\[\|{\|(\)', '', '\%(\]\|}\|)\)', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -198,15 +263,15 @@ endfunction function! elixir#indent#handle_starts_with_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text) let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' - if elixir#indent#starts_with(a:text, binary_operator, a:lnum) + if s:starts_with(a:text, binary_operator, a:lnum) let match_operator = '\%(!\|=\|<\|>\)\@\|\~\)\@!' - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) if pos == -1 return indent(a:prev_nb_lnum) else let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S') if next_word_pos == -1 - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() else return pos + 1 + next_word_pos end @@ -221,75 +286,116 @@ endfunction " function, etc... so we need to first figure out what the innermost structure " is then forward execution to the proper handler function! elixir#indent#handle_inside_nested_construct(lnum, text, prev_nb_lnum, prev_nb_text) - let start_pattern = '\C\%(\\|\\|\\|\\|\\|\\|{\|\[\|(\)' + let start_pattern = '\C\%(\\|\\|\\|\\|\\|\\|\\|{\|\[\|(\)' let end_pattern = '\C\%(\\|\]\|}\|)\)' - let pair_info = elixir#indent#searchpairpos_back(start_pattern, '', end_pattern) + let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()", max([0, a:lnum - g:elixir_indent_max_lookbehind])) let pair_lnum = pair_info[0] let pair_col = pair_info[1] if pair_lnum != 0 || pair_col != 0 let pair_text = getline(pair_lnum) let pair_char = pair_text[pair_col - 1] if pair_char == 'f' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_fn") - return elixir#indent#do_handle_inside_fn(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_fn") + return s:do_handle_inside_fn(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '[' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_square_brace") - return elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_square_brace") + return s:do_handle_inside_square_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '{' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_curly_brace") - return elixir#indent#do_handle_inside_curly_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_curly_brace") + return s:do_handle_inside_curly_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '(' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_parens") - return elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_parens") + return s:do_handle_inside_parens(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + elseif pair_char == 'w' + call s:debug("testing s:do_handle_inside_with") + return s:do_handle_inside_with(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) else - call elixir#indent#debug("testing elixir#indent#do_handle_inside_keyword_block") - return elixir#indent#do_handle_inside_keyword_block(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_keyword_block") + return s:do_handle_inside_keyword_block(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) end else return -1 end endfunction -function! elixir#indent#do_handle_inside_keyword_block(pair_lnum, _pair_col, _lnum, text, prev_nb_lnum, prev_nb_text) +function! s:do_handle_inside_with(pair_lnum, pair_col, lnum, text, prev_nb_lnum, prev_nb_text) + if a:pair_lnum == a:lnum + " This is the `with` line or an inline `with`/`do` + call s:debug("current line is `with`") + return -1 + else + " Determine if in with/do, do/else|end, or else/end + let start_pattern = '\C\%(\\|\\|\\)' + let end_pattern = '\C\%(\\)' + let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") + let pair_lnum = pair_info[0] + let pair_col = pair_info[1] + + let pair_text = getline(pair_lnum) + let pair_char = pair_text[pair_col - 1] + + if s:starts_with(a:text, '\Cdo:', a:lnum) + call s:debug("current line is do:") + return pair_col - 1 + s:sw() + elseif s:starts_with(a:text, '\Celse:', a:lnum) + call s:debug("current line is else:") + return pair_col - 1 + elseif s:starts_with(a:text, '\C\(\\|\\)', a:lnum) + call s:debug("current line is do/else") + return pair_col - 1 + elseif s:starts_with(pair_text, '\C\(do\|else\):', pair_lnum) + call s:debug("inside do:/else:") + return pair_col - 1 + s:sw() + elseif pair_char == 'w' + call s:debug("inside with/do") + return pair_col + 4 + elseif pair_char == 'd' + call s:debug("inside do/else|end") + return pair_col - 1 + s:sw() + else + call s:debug("inside else/end") + return s:do_handle_inside_pattern_match_block(pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + end + end +endfunction + +function! s:do_handle_inside_keyword_block(pair_lnum, _pair_col, _lnum, text, prev_nb_lnum, prev_nb_text) let keyword_pattern = '\C\%(\\|\\|\\|\\|\\|\\|\\|\\)' if a:pair_lnum - " last line is a "receive" or something - if elixir#indent#starts_with(a:prev_nb_text, keyword_pattern, a:prev_nb_lnum) - call elixir#indent#debug("prev nb line is keyword") - return indent(a:prev_nb_lnum) + &sw - elseif elixir#indent#contains(a:text, '->') - call elixir#indent#debug("contains ->") - " TODO: @jbodah 2017-03-31: test contains ignores str + comments - return indent(a:pair_lnum) + &sw - elseif elixir#indent#contains(a:prev_nb_text, '->') - call elixir#indent#debug("prev nb line contains ->") - return indent(a:prev_nb_lnum) + &sw + " last line is a "receive" or something + if s:starts_with(a:prev_nb_text, keyword_pattern, a:prev_nb_lnum) + call s:debug("prev nb line is keyword") + return indent(a:prev_nb_lnum) + s:sw() else - call elixir#indent#debug("doesnt start with comment or contain ->") - return indent(a:prev_nb_lnum) + return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) end else return -1 endif endfunction -function! elixir#indent#do_handle_inside_fn(pair_lnum, _pair_col, lnum, text, prev_nb_lnum, prev_nb_text) +" Implements indent for pattern-matching blocks (e.g. case, fn, with/else) +function! s:do_handle_inside_pattern_match_block(block_start_lnum, text, prev_nb_lnum, prev_nb_text) + if a:text =~ '->' + call s:debug("current line contains ->") + return indent(a:block_start_lnum) + s:sw() + elseif a:prev_nb_text =~ '->' + call s:debug("prev nb line contains ->") + return indent(a:prev_nb_lnum) + s:sw() + else + return indent(a:prev_nb_lnum) + end +endfunction + +function! s:do_handle_inside_fn(pair_lnum, _pair_col, lnum, text, prev_nb_lnum, prev_nb_text) if a:pair_lnum && a:pair_lnum != a:lnum - if elixir#indent#contains(a:text, '->') - return indent(a:pair_lnum) + &sw - else - if elixir#indent#ends_with(a:prev_nb_text, '->', a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw - else - return indent(a:prev_nb_lnum) - end - end + return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) else return -1 endif endfunction -function! elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) +function! s:do_handle_inside_square_brace(pair_lnum, pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) " If in list... if a:pair_lnum != 0 || a:pair_col != 0 let pair_text = getline(a:pair_lnum) @@ -298,24 +404,24 @@ function! elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, _lnum if indent_pos != -1 return indent_pos + a:pair_col else - return indent(a:pair_lnum) + &sw + return indent(a:pair_lnum) + s:sw() endif else return -1 end endfunction -function! elixir#indent#do_handle_inside_curly_brace(pair_lnum, _pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) - return indent(a:pair_lnum) + &sw +function! s:do_handle_inside_curly_brace(pair_lnum, _pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) + return indent(a:pair_lnum) + s:sw() endfunction -function! elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, _lnum, _text, prev_nb_lnum, prev_nb_text) +function! s:do_handle_inside_parens(pair_lnum, pair_col, _lnum, _text, prev_nb_lnum, prev_nb_text) if a:pair_lnum - if elixir#indent#ends_with(a:prev_nb_text, '(', a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw + if s:ends_with(a:prev_nb_text, '(', a:prev_nb_lnum) + return indent(a:prev_nb_lnum) + s:sw() elseif a:pair_lnum == a:prev_nb_lnum " Align indent (e.g. "def add(a,") - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, '[^(]\+,') + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, '[^(]\+,') if pos == -1 return 0 else @@ -330,14 +436,14 @@ function! elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, _lnum, _tex endfunction function! elixir#indent#handle_inside_generic_block(lnum, _text, prev_nb_lnum, prev_nb_text) - let pair_lnum = searchpair(elixir#indent#keyword('do\|fn'), '', elixir#indent#keyword('end'), 'bW', "line('.') == ".a:lnum." || elixir#indent#is_string_or_comment(line('.'), col('.'))") + let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end'), 'bW', "line('.') == ".a:lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:lnum - g:elixir_indent_max_lookbehind])) if pair_lnum " TODO: @jbodah 2017-03-29: this should probably be the case in *all* " blocks - if elixir#indent#ends_with(a:prev_nb_text, ',', a:prev_nb_lnum) - return indent(pair_lnum) + 2 * &sw + if s:ends_with(a:prev_nb_text, ',', a:prev_nb_lnum) + return indent(pair_lnum) + 2 * s:sw() else - return indent(pair_lnum) + &sw + return indent(pair_lnum) + s:sw() endif else return -1 diff --git a/autoload/rust.vim b/autoload/rust.vim index fe7ddff8..6edc48f7 100644 --- a/autoload/rust.vim +++ b/autoload/rust.vim @@ -3,6 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Author: Kevin Ballard " Description: Helper functions for Rust commands/mappings " Last Modified: May 27, 2014 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim " Jump {{{1 @@ -366,53 +367,57 @@ endfunction " gist.vim available under the BSD license, available at " http://github.com/mattn/gist-vim function! s:has_webapi() - if !exists("*webapi#http#post") - try - call webapi#http#post() - catch - endtry - endif - return exists("*webapi#http#post") + if !exists("*webapi#http#post") + try + call webapi#http#post() + catch + endtry + endif + return exists("*webapi#http#post") endfunction function! rust#Play(count, line1, line2, ...) abort - redraw - - let l:rust_playpen_url = get(g:, 'rust_playpen_url', 'https://play.rust-lang.org/') - let l:rust_shortener_url = get(g:, 'rust_shortener_url', 'https://is.gd/') - - if !s:has_webapi() - echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None - return - endif - - let bufname = bufname('%') - if a:count < 1 - let content = join(getline(a:line1, a:line2), "\n") - else - let save_regcont = @" - let save_regtype = getregtype('"') - silent! normal! gvy - let content = @" - call setreg('"', save_regcont, save_regtype) - endif - - let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content) - - if strlen(body) > 5000 - echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None - return - endif - - let payload = "format=simple&url=".webapi#http#encodeURI(body) - let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {}) - let url = res.content - - redraw | echomsg 'Done: '.url + redraw + + let l:rust_playpen_url = get(g:, 'rust_playpen_url', 'https://play.rust-lang.org/') + let l:rust_shortener_url = get(g:, 'rust_shortener_url', 'https://is.gd/') + + if !s:has_webapi() + echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None + return + endif + + let bufname = bufname('%') + if a:count < 1 + let content = join(getline(a:line1, a:line2), "\n") + else + let save_regcont = @" + let save_regtype = getregtype('"') + silent! normal! gvy + let content = @" + call setreg('"', save_regcont, save_regtype) + endif + + let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content) + + if strlen(body) > 5000 + echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None + return + endif + + let payload = "format=simple&url=".webapi#http#encodeURI(body) + let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {}) + let url = res.content + + if exists('g:rust_clip_command') + call system(g:rust_clip_command, url) + endif + + redraw | echomsg 'Done: '.url endfunction " }}}1 -" vim: set noet sw=4 ts=4: +" vim: set noet sw=8 ts=8: endif diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index a43c07cc..307fead7 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -3,108 +3,109 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Author: Stephen Sugden " " Adapted from https://github.com/fatih/vim-go +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim if !exists("g:rustfmt_autosave") - let g:rustfmt_autosave = 0 + let g:rustfmt_autosave = 0 endif if !exists("g:rustfmt_command") - let g:rustfmt_command = "rustfmt" + let g:rustfmt_command = "rustfmt" endif if !exists("g:rustfmt_options") - let g:rustfmt_options = "" + let g:rustfmt_options = "" endif if !exists("g:rustfmt_fail_silently") - let g:rustfmt_fail_silently = 0 + let g:rustfmt_fail_silently = 0 endif let s:got_fmt_error = 0 function! s:RustfmtCommandRange(filename, line1, line2) - let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} - return printf("%s %s --write-mode=overwrite --file-lines '[%s]'", g:rustfmt_command, g:rustfmt_options, json_encode(l:arg)) + let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} + return printf("%s %s --write-mode=overwrite --file-lines '[%s]'", g:rustfmt_command, g:rustfmt_options, json_encode(l:arg)) endfunction function! s:RustfmtCommand(filename) - return g:rustfmt_command . " --write-mode=overwrite " . g:rustfmt_options . " " . shellescape(a:filename) + return g:rustfmt_command . " --write-mode=overwrite " . g:rustfmt_options . " " . shellescape(a:filename) endfunction function! s:RunRustfmt(command, curw, tmpname) - if exists("*systemlist") - let out = systemlist(a:command) - else - let out = split(system(a:command), '\r\?\n') - endif - - if v:shell_error == 0 || v:shell_error == 3 - " remove undo point caused via BufWritePre - try | silent undojoin | catch | endtry - - " Replace current file with temp file, then reload buffer - call rename(a:tmpname, expand('%')) - silent edit! - let &syntax = &syntax - - " only clear location list if it was previously filled to prevent - " clobbering other additions - if s:got_fmt_error - let s:got_fmt_error = 0 - call setloclist(0, []) - lwindow - endif - elseif g:rustfmt_fail_silently == 0 - " otherwise get the errors and put them in the location list - let errors = [] - - for line in out - " src/lib.rs:13:5: 13:10 error: expected `,`, or `}`, found `value` - let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\):\s*\(\d\+:\d\+\s*\)\?\s*error: \(.*\)') - if !empty(tokens) - call add(errors, {"filename": @%, - \"lnum": tokens[2], - \"col": tokens[3], - \"text": tokens[5]}) - endif - endfor - - if empty(errors) - % | " Couldn't detect rustfmt error format, output errors - endif - - if !empty(errors) - call setloclist(0, errors, 'r') - echohl Error | echomsg "rustfmt returned error" | echohl None - endif - - let s:got_fmt_error = 1 - lwindow - " We didn't use the temp file, so clean up - call delete(a:tmpname) - endif - - call winrestview(a:curw) + if exists("*systemlist") + let out = systemlist(a:command) + else + let out = split(system(a:command), '\r\?\n') + endif + + if v:shell_error == 0 || v:shell_error == 3 + " remove undo point caused via BufWritePre + try | silent undojoin | catch | endtry + + " Replace current file with temp file, then reload buffer + call rename(a:tmpname, expand('%')) + silent edit! + let &syntax = &syntax + + " only clear location list if it was previously filled to prevent + " clobbering other additions + if s:got_fmt_error + let s:got_fmt_error = 0 + call setloclist(0, []) + lwindow + endif + elseif g:rustfmt_fail_silently == 0 + " otherwise get the errors and put them in the location list + let errors = [] + + for line in out + " src/lib.rs:13:5: 13:10 error: expected `,`, or `}`, found `value` + let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\):\s*\(\d\+:\d\+\s*\)\?\s*error: \(.*\)') + if !empty(tokens) + call add(errors, {"filename": @%, + \"lnum": tokens[2], + \"col": tokens[3], + \"text": tokens[5]}) + endif + endfor + + if empty(errors) + % | " Couldn't detect rustfmt error format, output errors + endif + + if !empty(errors) + call setloclist(0, errors, 'r') + echohl Error | echomsg "rustfmt returned error" | echohl None + endif + + let s:got_fmt_error = 1 + lwindow + " We didn't use the temp file, so clean up + call delete(a:tmpname) + endif + + call winrestview(a:curw) endfunction function! rustfmt#FormatRange(line1, line2) - let l:curw = winsaveview() - let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" - call writefile(getline(1, '$'), l:tmpname) + let l:curw = winsaveview() + let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" + call writefile(getline(1, '$'), l:tmpname) - let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2) + let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2) - call s:RunRustfmt(command, l:curw, l:tmpname) + call s:RunRustfmt(command, l:curw, l:tmpname) endfunction function! rustfmt#Format() - let l:curw = winsaveview() - let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" - call writefile(getline(1, '$'), l:tmpname) + let l:curw = winsaveview() + let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" + call writefile(getline(1, '$'), l:tmpname) - let command = s:RustfmtCommand(l:tmpname) + let command = s:RustfmtCommand(l:tmpname) - call s:RunRustfmt(command, l:curw, l:tmpname) + call s:RunRustfmt(command, l:curw, l:tmpname) endfunction endif diff --git a/autoload/xml/html5.vim b/autoload/xml/html5.vim index 982fe29a..4123dbe0 100644 --- a/autoload/xml/html5.vim +++ b/autoload/xml/html5.vim @@ -587,7 +587,7 @@ let g:xmldata_html5 = { \ ], \ 'input': [ \ [], - \ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']}) + \ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']}) \ ], \ 'ins': [ \ flow_elements, diff --git a/compiler/cargo.vim b/compiler/cargo.vim index 160d214e..8e3c6212 100644 --- a/compiler/cargo.vim +++ b/compiler/cargo.vim @@ -4,21 +4,25 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Compiler: Cargo Compiler " Maintainer: Damien Radtke " Latest Revision: 2014 Sep 24 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim if exists('current_compiler') - finish + finish endif runtime compiler/rustc.vim let current_compiler = "cargo" +let s:save_cpo = &cpo +set cpo&vim + if exists(':CompilerSet') != 2 - command -nargs=* CompilerSet setlocal + command -nargs=* CompilerSet setlocal endif if exists('g:cargo_makeprg_params') - execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*' + execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*' else - CompilerSet makeprg=cargo\ $* + CompilerSet makeprg=cargo\ $* endif " Ignore general cargo progress messages @@ -27,6 +31,11 @@ CompilerSet errorformat+= \%-G%\\s%#Compiling%.%#, \%-G%\\s%#Finished%.%#, \%-G%\\s%#error:\ Could\ not\ compile\ %.%#, - \%-G%\\s%#To\ learn\ more\\,%.%# + \%-G%\\s%#To\ learn\ more\\,%.%#, + \%-Gnote:\ Run\ with\ \`RUST_BACKTRACE=%.%#, + \%.%#panicked\ at\ \\'%m\\'\\,\ %f:%l + +let &cpo = s:save_cpo +unlet s:save_cpo endif diff --git a/compiler/rake.vim b/compiler/rake.vim index 3ed1472b..e304f8fa 100644 --- a/compiler/rake.vim +++ b/compiler/rake.vim @@ -24,10 +24,10 @@ CompilerSet errorformat= \%D(in\ %f), \%\\s%#from\ %f:%l:%m, \%\\s%#from\ %f:%l:, - \%\\s%##\ %f:%l:%m%\\&%.%#%\\D:%.%#, - \%\\s%##\ %f:%l%\\&%.%#%\\D:%.%#, - \%\\s%#[%f:%l:\ %#%m%\\&%.%#%\\D:%.%#, - \%\\s%#%f:%l:\ %#%m%\\&%.%#%\\D:%.%#, + \%\\s%##\ %f:%l:%m%\\&%.%#%\\D:%\\d%#:%.%#, + \%\\s%##\ %f:%l%\\&%.%#%\\D:%\\d%#, + \%\\s%#[%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%#:%.%#, + \%\\s%#%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%#:%.%#, \%\\s%#%f:%l:, \%m\ [%f:%l]:, \%+Erake\ aborted!, diff --git a/compiler/rustc.vim b/compiler/rustc.vim index 5c02dd28..7b691b31 100644 --- a/compiler/rustc.vim +++ b/compiler/rustc.vim @@ -4,9 +4,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Compiler: Rust Compiler " Maintainer: Chris Morgan " Latest Revision: 2013 Jul 12 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim if exists("current_compiler") - finish + finish endif let current_compiler = "rustc" diff --git a/compiler/typescript.vim b/compiler/typescript.vim index b4137943..9ba313fe 100644 --- a/compiler/typescript.vim +++ b/compiler/typescript.vim @@ -17,8 +17,18 @@ if exists(":CompilerSet") != 2 command! -nargs=* CompilerSet setlocal endif -let &l:makeprg = g:typescript_compiler_binary . ' ' . g:typescript_compiler_options . ' $* %' +let s:cpo_save = &cpo +set cpo-=C + +execute 'CompilerSet makeprg=' + \ . escape(g:typescript_compiler_binary, ' ') + \ . '\ ' + \ . escape(g:typescript_compiler_options, ' ') + \ . '\ $*\ %' CompilerSet errorformat=%+A\ %#%f\ %#(%l\\\,%c):\ %m,%C%m +let &cpo = s:cpo_save +unlet s:cpo_save + endif diff --git a/extras/flow.vim b/extras/flow.vim index 6f9ef7f4..bbb84496 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -2,9 +2,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\|=>\@!\)\@=/ contains=@jsFlowCluster -syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster -syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster -syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster +syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowExactObject contained matchgroup=jsFlowNoise start=/{|/ end=/|}/ contains=@jsFlowCluster,jsComment fold +syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster keepend fold syntax match jsFlowNoise contained /[:;,<>]/ syntax keyword jsFlowType contained boolean number string null void any mixed JSON array Function object array bool class syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType @@ -12,18 +13,18 @@ syntax match jsFlowTypeCustom contained /[0-9a-zA-Z_.]*/ skipwhite skipemp syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens -syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject syntax match jsFlowOrOperator contained /|/ skipwhite skipempty nextgroup=@jsFlowCluster syntax keyword jsFlowImportType contained type skipwhite skipempty nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup syntax match jsFlowWildcard contained /*/ -syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster -syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp -syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp -syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster,jsFlowArrow,jsFlowReturnParens +syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold +syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold +syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp,jsFlowReturnArrow fold +syntax match jsFlowReturnArrow contained /=>/ skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock,jsFlowReturnOrOp -syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword +syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword,jsFlowReturnObject syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp syntax match jsFlowReturnOrOp contained /\s*|\s*/ skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax match jsFlowWildcardReturn contained /*/ skipwhite skipempty nextgroup=jsFuncBlock @@ -32,7 +33,8 @@ syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock syntax region jsFlowTypeStatement start=/type\%(\s\+\k\)\@=/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend -syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression,jsFlowGroup,jsFlowMaybe +syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/=/ end=/[\n;]/ contains=@jsFlowCluster,jsFlowGroup,jsFlowMaybe +syntax match jsFlowTypeOperator contained /=/ containedin=jsFlowTypeValue syntax match jsFlowTypeOperator contained /=/ syntax keyword jsFlowTypeKeyword contained type @@ -42,12 +44,18 @@ syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\) syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster -syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise +syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise fold -syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend +" NOTE: It appears the nextgroup was causing a ton of breakages... testing it +" witout a nextgroup, but keeping this arround for reference incase something breaks +" syntax match jsFlowMaybe contained /?/ nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject extend keepend +syntax match jsFlowMaybe contained /?/ +syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend fold -syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn -syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard +syntax region jsFlowParenAnnotation contained start=/:/ end=/[,=)]\@=/ containedin=jsParen contains=@jsFlowCluster + +syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn,jsFlowReturnArrow +syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowExactObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard if version >= 508 || !exists("did_javascript_syn_inits") if version < 508 @@ -64,9 +72,11 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowTypeof PreProc HiLink jsFlowArray PreProc HiLink jsFlowObject PreProc + HiLink jsFlowExactObject PreProc HiLink jsFlowParens PreProc HiLink jsFlowGroup PreProc HiLink jsFlowReturn PreProc + HiLink jsFlowParenAnnotation PreProc HiLink jsFlowReturnObject jsFlowReturn HiLink jsFlowReturnArray jsFlowArray HiLink jsFlowReturnParens jsFlowParens @@ -75,9 +85,10 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowClassGroup PreProc HiLink jsFlowArrowArguments PreProc HiLink jsFlowArrow PreProc + HiLink jsFlowReturnArrow PreProc HiLink jsFlowTypeStatement PreProc HiLink jsFlowTypeKeyword PreProc - HiLink jsFlowTypeOperator PreProc + HiLink jsFlowTypeOperator Operator HiLink jsFlowMaybe PreProc HiLink jsFlowReturnMaybe PreProc HiLink jsFlowClassProperty jsClassProperty @@ -86,10 +97,12 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowInterface PreProc HiLink jsFlowNoise Noise HiLink jsFlowObjectKey jsObjectKey - HiLink jsFlowOrOperator PreProc + HiLink jsFlowOrOperator jsOperator HiLink jsFlowReturnOrOp jsFlowOrOperator HiLink jsFlowWildcard PreProc HiLink jsFlowWildcardReturn PreProc + HiLink jsFlowImportType PreProc + HiLink jsFlowTypeValue PreProc delcommand HiLink endif diff --git a/extras/jsdoc.vim b/extras/jsdoc.vim index c4ed7181..ca4069cb 100644 --- a/extras/jsdoc.vim +++ b/extras/jsdoc.vim @@ -12,7 +12,7 @@ syntax match jsDocTags contained "@\(callback\|define\|enum\|external\| " tags containing references syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag " other tags (no extra syntax) -syntax match jsDocTags contained "@\(abstract\|access\|accessor\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>" +syntax match jsDocTags contained "@\(abstract\|access\|accessor\|async\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>" syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index ebe17f4b..8f2f926f 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -287,9 +287,9 @@ augroup filetypedetect " Language: OpenGL Shading Language " Maintainer: Sergey Tikhomirov -" Extensions supported by Khronos reference compiler +" Extensions supported by Khronos reference compiler (with one exception, ".glsl") " https://github.com/KhronosGroup/glslang -autocmd! BufNewFile,BufRead *.vert,*.tesc,*.tese,*.geom,*.frag,*.comp set filetype=glsl +autocmd! BufNewFile,BufRead *.vert,*.tesc,*.tese,*.glsl,*.geom,*.frag,*.comp set filetype=glsl " vim:set sts=2 sw=2 : augroup END @@ -335,7 +335,7 @@ augroup END augroup filetypedetect " graphql:jparise/vim-graphql -au BufRead,BufNewFile *.graphql,*.gql setfiletype graphql +au BufRead,BufNewFile *.graphql,*.graphqls,*.gql setfiletype graphql augroup END augroup filetypedetect @@ -387,7 +387,7 @@ augroup END augroup filetypedetect " javascript:pangloss/vim-javascript:_JAVASCRIPT -au BufNewFile,BufRead *.{js,jsm,es,es6},Jakefile setf javascript +au BufNewFile,BufRead *.{js,mjs,jsm,es,es6},Jakefile setf javascript fun! s:SourceFlowSyntax() if !exists('javascript_plugin_flow') && !exists('b:flow_active') && @@ -442,15 +442,16 @@ if !exists('g:jsx_pragma_required') let g:jsx_pragma_required = 0 endif -if g:jsx_pragma_required - " Look for the @jsx pragma. It must be included in a docblock comment before - " anything else in the file (except whitespace). - let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/' - let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw') -endif +let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/' " Whether to set the JSX filetype on *.js files. fu! EnableJSX() + if g:jsx_pragma_required && !exists('b:jsx_ext_found') + " Look for the @jsx pragma. It must be included in a docblock comment + " before anything else in the file (except whitespace). + let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw') + endif + if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif return 1 @@ -524,6 +525,16 @@ augroup END augroup filetypedetect " mako:sophacles/vim-bundle-mako +if !exists("g:mako_detect_lang_from_ext") + let g:mako_detect_lang_from_ext = 1 +endif +if g:mako_detect_lang_from_ext + au BufNewFile *.*.mako execute "do BufNewFile filetypedetect " . expand(":r") | let b:mako_outer_lang = &filetype + " it's important to get this before any of the normal BufRead autocmds execute + " for this file, otherwise a mako tag at the start of the file can cause the + " filetype to be set to mason + au BufReadPre *.*.mako execute "do BufRead filetypedetect " . expand(":r") | let b:mako_outer_lang = &filetype +endif au BufRead,BufNewFile *.mako set filetype=mako augroup END @@ -703,7 +714,7 @@ au! BufRead,BufNewFile Puppetfile setfiletype ruby augroup END augroup filetypedetect -" purescript:raichoo/purescript-vim +" purescript:purescript-contrib/purescript-vim au BufNewFile,BufRead *.purs setf purescript au FileType purescript let &l:commentstring='{--%s--}' augroup END @@ -755,7 +766,7 @@ augroup filetypedetect " Support functions {{{ function! s:setf(filetype) abort - if &filetype !=# a:filetype + if &filetype !~# '\<'.a:filetype.'\>' let &filetype = a:filetype endif endfunction diff --git a/ftplugin/eruby.vim b/ftplugin/eruby.vim index 21e22696..bf380e8a 100644 --- a/ftplugin/eruby.vim +++ b/ftplugin/eruby.vim @@ -29,7 +29,7 @@ elseif !exists("b:eruby_subtype") let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+') if b:eruby_subtype == '' - let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') + let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') endif if b:eruby_subtype == 'rhtml' let b:eruby_subtype = 'html' @@ -47,7 +47,7 @@ elseif !exists("b:eruby_subtype") endif endif -if exists("b:eruby_subtype") && b:eruby_subtype != '' +if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby' exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim" else runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim diff --git a/ftplugin/gitrebase.vim b/ftplugin/gitrebase.vim index e3e015bb..032aba31 100644 --- a/ftplugin/gitrebase.vim +++ b/ftplugin/gitrebase.vim @@ -28,11 +28,12 @@ function! s:cycle() call s:choose(get({'s':'edit','p':'squash','e':'reword','r':'fixup'},getline('.')[0],'pick')) endfunction -command! -buffer -bar Pick :call s:choose('pick') -command! -buffer -bar Squash :call s:choose('squash') -command! -buffer -bar Edit :call s:choose('edit') -command! -buffer -bar Reword :call s:choose('reword') -command! -buffer -bar Fixup :call s:choose('fixup') +command! -buffer -bar -range Pick :,call s:choose('pick') +command! -buffer -bar -range Squash :,call s:choose('squash') +command! -buffer -bar -range Edit :,call s:choose('edit') +command! -buffer -bar -range Reword :,call s:choose('reword') +command! -buffer -bar -range Fixup :,call s:choose('fixup') +command! -buffer -bar -range Drop :,call s:choose('drop') command! -buffer -bar Cycle :call s:cycle() " The above are more useful when they are mapped; for example: "nnoremap S :Cycle diff --git a/ftplugin/graphql.vim b/ftplugin/graphql.vim index d82d9abb..42d96e6c 100644 --- a/ftplugin/graphql.vim +++ b/ftplugin/graphql.vim @@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 " Language: GraphQL " Maintainer: Jon Parise -if (exists("b:did_ftplugin")) +if (exists('b:did_ftplugin')) finish endif let b:did_ftplugin = 1 diff --git a/ftplugin/ps1.vim b/ftplugin/ps1.vim index 9a980834..a88fe019 100644 --- a/ftplugin/ps1.vim +++ b/ftplugin/ps1.vim @@ -19,8 +19,6 @@ setlocal formatoptions=tcqro " Enable autocompletion of hyphenated PowerShell commands, " e.g. Get-Content or Get-ADUser setlocal iskeyword+=- -" MS applications (including PowerShell) require a Byte Order Mark (BOM) for UTF-8. -setlocal bomb " Change the browse dialog on Win32 to show mainly PowerShell-related files if has("gui_win32") diff --git a/ftplugin/ps1xml.vim b/ftplugin/ps1xml.vim index e2616a00..11815d2d 100644 --- a/ftplugin/ps1xml.vim +++ b/ftplugin/ps1xml.vim @@ -16,8 +16,6 @@ let b:did_ftplugin = 1 setlocal tw=0 setlocal commentstring=#%s setlocal formatoptions=tcqro -" MS applications (including PowerShell) require a Byte Order Mark (BOM) for UTF-8. -setlocal bomb " Change the browse dialog on Win32 to show mainly PowerShell-related files if has("gui_win32") diff --git a/ftplugin/purescript.vim b/ftplugin/purescript.vim index 4e40143f..695a4108 100644 --- a/ftplugin/purescript.vim +++ b/ftplugin/purescript.vim @@ -1,5 +1,42 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1 setlocal comments=s1fl:{-,mb:\ \ ,ex:-},:-- +setlocal include=^import +setlocal includeexpr=printf('%s.purs',substitute(v:fname,'\\.','/','g')) + +let s:PS = [] +fun! InitPureScript() + let dirs = map( + \ findfile("psc-package.json", expand("%:p:h") . ";/", -1), + \ { idx, val -> fnamemodify(val, ":p:h") } + \ ) + if empty(dirs) + let dirs = map( + \ findfile("bower.json", expand("%:p:h") . ";/", -1), + \ { idx, val -> fnamemodify(val, ":p:h") } + \ ) + if empty(dirs) + return + endif + endif + + let path = expand("%:p") + for p in s:PS + if stridx(path, p[0], 0) == 0 + let &l:path=p[1] + return + endif + endfor + + let dir = dirs[len(dirs) - 1] + let gp = globpath(dir, "src/**/*.purs", v:true, v:true) + if empty(gp) + return + endif + + let &l:path=join([dir, dir . "/bower_components/**", dir . "/src/**"], ",") + call add(s:PS, [dir, &l:path]) +endfun +call InitPureScript() endif diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 24576de0..9189730b 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -365,6 +365,7 @@ function! RubyCursorFile() abort let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : '' if s:synid() ==# hlID('rubyConstant') let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','') + let cfile = substitute(cfile,'^::','','') let cfile = substitute(cfile,'::','/','g') let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g') let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g') diff --git a/ftplugin/rust.vim b/ftplugin/rust.vim index b945fab7..d1765d07 100644 --- a/ftplugin/rust.vim +++ b/ftplugin/rust.vim @@ -1,10 +1,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Language: Rust -" Description: Vim syntax file for Rust +" Description: Vim ftplugin for Rust " Maintainer: Chris Morgan " Maintainer: Kevin Ballard " Last Change: June 08, 2016 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim if exists("b:did_ftplugin") finish @@ -193,19 +194,13 @@ endif augroup END -" %-matching. <:> is handy for generics. set matchpairs+=<:> -" There are two minor issues with it; (a) comparison operators in expressions, -" where a less-than may match a greater-than later on—this is deemed a trivial -" issue—and (b) `Fn() -> X` syntax. This latter issue is irremediable from the -" highlighting perspective (built into Vim), but the actual % functionality -" can be fixed by this use of matchit.vim. +" For matchit.vim (rustArrow stops `Fn() -> X` messing things up) let b:match_skip = 's:comment\|string\|rustArrow' -source $VIMRUNTIME/macros/matchit.vim let &cpo = s:save_cpo unlet s:save_cpo -" vim: set noet sw=4 ts=4: +" vim: set noet sw=8 ts=8: endif diff --git a/indent/elixir.vim b/indent/elixir.vim index 0ddaec44..5882565f 100644 --- a/indent/elixir.vim +++ b/indent/elixir.vim @@ -7,42 +7,13 @@ let b:did_indent = 1 setlocal indentexpr=elixir#indent(v:lnum) -setlocal indentkeys+=0=end,0=catch,0=rescue,0=after,0=else,=->,0},0],0),0=\|>,0=<> +setlocal indentkeys+==after,=catch,=do,=else,=end,=rescue, +setlocal indentkeys+=*,=->,=\|>,=<>,0},0],0) + " TODO: @jbodah 2017-02-27: all operators should cause reindent when typed function! elixir#indent(lnum) - let lnum = a:lnum - let text = getline(lnum) - let prev_nb_lnum = prevnonblank(lnum-1) - let prev_nb_text = getline(prev_nb_lnum) - - call elixir#indent#debug("==> Indenting line " . lnum) - call elixir#indent#debug("text = '" . text . "'") - - let handlers = [ - \'top_of_file', - \'starts_with_end', - \'starts_with_mid_or_end_block_keyword', - \'following_trailing_do', - \'following_trailing_binary_operator', - \'starts_with_pipe', - \'starts_with_close_bracket', - \'starts_with_binary_operator', - \'inside_nested_construct', - \'starts_with_comment', - \'inside_generic_block' - \] - for handler in handlers - call elixir#indent#debug('testing handler elixir#indent#handle_'.handler) - let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text) - if indent != -1 - call elixir#indent#debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent) - return indent - endif - endfor - - call elixir#indent#debug("defaulting") - return 0 + return elixir#indent#indent(a:lnum) endfunction endif diff --git a/indent/eruby.vim b/indent/eruby.vim index 5b21ab91..6fd76600 100644 --- a/indent/eruby.vim +++ b/indent/eruby.vim @@ -14,7 +14,7 @@ runtime! indent/ruby.vim unlet! b:did_indent setlocal indentexpr= -if exists("b:eruby_subtype") +if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby' exe "runtime! indent/".b:eruby_subtype.".vim" else runtime! indent/html.vim diff --git a/indent/graphql.vim b/indent/graphql.vim new file mode 100644 index 00000000..ed9cfaa2 --- /dev/null +++ b/indent/graphql.vim @@ -0,0 +1,81 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 + +" Vim indent file +" Language: GraphQL +" Maintainer: Jon Parise + +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +setlocal autoindent +setlocal nocindent +setlocal nolisp +setlocal nosmartindent + +setlocal indentexpr=GetGraphQLIndent() +setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O,e + +" If our indentation function already exists, we have nothing more to do. +if exists('*GetGraphQLIndent') + finish +endif + +let s:cpo_save = &cpoptions +set cpoptions&vim + +" Check if the character at lnum:col is inside a string. +function s:InString(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') is# 'graphqlString' +endfunction + +function GetGraphQLIndent() + " If this is the first non-blank line, we have nothing more to do because + " all of our indentation rules are based on matching against earlier lines. + let l:prevlnum = prevnonblank(v:lnum - 1) + if l:prevlnum == 0 + return 0 + endif + + let l:line = getline(v:lnum) + + " If this line contains just a closing bracket, find its matching opening + " bracket and indent the closing backet to match. + let l:col = matchend(l:line, '^\s*[]})]') + if l:col > 0 && !s:InString(v:lnum, l:col) + let l:bracket = l:line[l:col - 1] + call cursor(v:lnum, l:col) + + if l:bracket is# '}' + let l:matched = searchpair('{', '', '}', 'bW') + elseif l:bracket is# ']' + let l:matched = searchpair('\[', '', '\]', 'bW') + elseif l:bracket is# ')' + let l:matched = searchpair('(', '', ')', 'bW') + else + let l:matched = -1 + endif + + return l:matched > 0 ? indent(l:matched) : virtcol('.') - 1 + endif + + " If we're inside of a multiline string, continue with the same indentation. + if s:InString(v:lnum, matchend(l:line, '^\s*') + 1) + return indent(v:lnum) + endif + + " If the previous line contained an opening bracket, and we are still in it, + " add indent depending on the bracket type. + if getline(l:prevlnum) =~# '[[{(]\s*$' + return indent(l:prevlnum) + shiftwidth() + endif + + " Default to the existing indentation level. + return indent(l:prevlnum) +endfunction + +let &cpoptions = s:cpo_save +unlet s:cpo_save + +endif diff --git a/indent/haskell.vim b/indent/haskell.vim index e63515ce..5c33e550 100644 --- a/indent/haskell.vim +++ b/indent/haskell.vim @@ -36,9 +36,18 @@ endif if !exists('g:haskell_indent_let') " let x = 0 in " >>>>x + " + " let x = 0 + " y = 1 let g:haskell_indent_let = 4 endif +if !exists('g:haskell_indent_let_no_in') + " let x = 0 + " x + let g:haskell_indent_let_no_in = 4 +endif + if !exists('g:haskell_indent_where') " where f :: Int -> Int " >>>>>>f x = x @@ -210,6 +219,9 @@ function! GetHaskellIndent() " " let x = 1 " >>>>y = 2 + " + " let x = 1 + " y 2 if l:prevline =~ '\C\\s\+.\+$' if l:line =~ '\C^\s*\' let l:s = match(l:prevline, '\C\') @@ -221,11 +233,16 @@ function! GetHaskellIndent() if s:isSYN('haskellLet', v:lnum - 1, l:s + 1) return l:s + g:haskell_indent_in endif - else + elseif l:line =~ '\s=\s' let l:s = match(l:prevline, '\C\') if s:isSYN('haskellLet', v:lnum - 1, l:s + 1) return l:s + g:haskell_indent_let endif + else + let l:s = match(l:prevline, '\C\') + if s:isSYN('haskellLet', v:lnum - 1, l:s + 1) + return l:s + g:haskell_indent_let_no_in + endif endif endif diff --git a/indent/html.vim b/indent/html.vim index 0cbc3b17..1e5691f7 100644 --- a/indent/html.vim +++ b/indent/html.vim @@ -260,20 +260,28 @@ let s:html_indent_tags = '[a-z_][a-z0-9_.-]*' let s:cpo_save = &cpo set cpo-=C -" [-- count indent-increasing tags of line a:lnum --] -fun! HtmlIndentOpen(lnum, pattern) - let s = substitute('x'.getline(a:lnum), - \ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g') +func! HtmlIndentPatternCount(content, pattern) + let s = substitute('x'.a:content, a:pattern, "\1", 'g') let s = substitute(s, "[^\1].*$", '', '') return strlen(s) endfun +" [-- count indent-increasing tags of line a:lnum --] +fun! HtmlIndentOpen(lnum, pattern) + return HtmlIndentPatternCount(getline(a:lnum), + \ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)') +endfun + " [-- count indent-decreasing tags of line a:lnum --] fun! HtmlIndentClose(lnum, pattern) - let s = substitute('x'.getline(a:lnum), - \ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g') - let s = substitute(s, "[^\1].*$", '', '') - return strlen(s) + return HtmlIndentPatternCount(getline(a:lnum), + \ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)') +endfun + +" [-- count self close tags of line a:lnum --] +fun! HtmlIndentSelfClose(lnum, pattern) + return HtmlIndentPatternCount(getline(a:lnum), + \ '.\{-}\(\(<\('.a:pattern.'\).*\)\@\)') endfun " [-- count indent-increasing '{' of (java|css) line a:lnum --] @@ -292,8 +300,9 @@ fun! HtmlIndentSum(lnum, style) if a:style == match(getline(a:lnum), '^\s*') let open = HtmlIndentOpen(a:lnum, s:html_indent_tags) - HtmlIndentOpen(a:lnum, s:html_noindent_tags) let close = HtmlIndentClose(a:lnum, s:html_indent_tags) - HtmlIndentClose(a:lnum, s:html_noindent_tags) - if 0 != open || 0 != close - return open - close + let self_close = HtmlIndentSelfClose(a:lnum, s:html_noindent_tags) + if 0 != open || 0 != close || 0 != self_close + return open - close - self_close endif endif endif @@ -310,6 +319,13 @@ fun! HtmlIndentSum(lnum, style) endfun fun! HtmlIndentGet(lnum) + " Get shiftwidth value. + if exists('*shiftwidth') + let sw = shiftwidth() + else + let sw = &sw + endif + " Find a non-empty line above the current line. let lnum = prevnonblank(a:lnum - 1) @@ -396,7 +412,7 @@ fun! HtmlIndentGet(lnum) endif if 0 == match(getline(a:lnum), '^\s*' " let close_tags_exp = '' " if getline(a:lnum) =~ tags_exp - " let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW') + " let block_start = search('^'.repeat(' ', lind + (sw * ind - 1)).'\S' , 'bnW') " let prev_tag = search(tags_exp, 'bW', block_start) " let prev_closetag = search(close_tags_exp, 'W', a:lnum) " if prev_tag && !prev_closetag @@ -426,7 +442,7 @@ fun! HtmlIndentGet(lnum) " endif " if getline(a:lnum) =~ '' - " let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW') + " let block_start = search('^'.repeat(' ', lind + (sw * ind - 1)).'\S' , 'bnW') " let prev_tag = search(tags_exp, 'bW', block_start) " let prev_closetag = search(close_tags_exp, 'W', a:lnum) " if prev_tag && !prev_closetag @@ -439,7 +455,7 @@ fun! HtmlIndentGet(lnum) setlocal noic endif - return lind + (&sw * ind) + return lind + (sw * ind) endfun let &cpo = s:cpo_save diff --git a/indent/javascript.vim b/indent/javascript.vim index 8f922eca..100efbc5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: May 16, 2017 +" Last Change: September 18, 2017 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -57,343 +57,295 @@ endif " matches before pos. let s:z = has('patch-7.4.984') ? 'z' : '' -let s:syng_com = 'comment\|doc' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "s:syn_at(line('.'),col('.')) =~? b:syng_strcom" +let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom" +let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'" +let s:rel = has('reltime') " searchpair() wrapper -if has('reltime') - function s:GetPair(start,end,flags,skip,time,...) - return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time) +if s:rel + function s:GetPair(start,end,flags,skip) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200) endfunction else - function s:GetPair(start,end,flags,skip,...) - return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 1000,get(a:000,1)])) + function s:GetPair(start,end,flags,skip) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1) endfunction endif -function s:syn_at(l,c) - let pos = join([a:l,a:c],',') - if has_key(s:synId_cache,pos) - return s:synId_cache[pos] +function s:SynAt(l,c) + let byte = line2byte(a:l) + a:c - 1 + let pos = index(s:synid_cache[0], byte) + if pos == -1 + let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]] endif - let s:synId_cache[pos] = synIDattr(synID(a:l,a:c,0),'name') - return s:synId_cache[pos] + return s:synid_cache[1][pos] endfunction -function s:parse_cino(f) - let [cin, divider, n] = [strridx(&cino,a:f), 0, ''] - if cin == -1 - return - endif - let [sign, cstr] = &cino[cin+1] ==# '-' ? [-1, &cino[cin+2:]] : [1, &cino[cin+1:]] +function s:ParseCino(f) + let [divider, n, cstr] = [0] + matchlist(&cino, + \ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2] for c in split(cstr,'\zs') - if c ==# '.' && !divider + if c == '.' && !divider let divider = 1 elseif c ==# 's' - if n is '' - let n = s:W - else - let n = str2nr(n) * s:W + if n !~ '\d' + return n . s:sw() + 0 endif + let n = str2nr(n) * s:sw() break - elseif c =~ '\d' - let [n, divider] .= [c, 0] else - break + let [n, divider] .= [c, 0] endif endfor - return sign * str2nr(n) / max([str2nr(divider),1]) + return str2nr(n) / max([str2nr(divider),1]) endfunction -" Optimized {skip} expr, used only once per GetJavascriptIndent() call -function s:skip_func() - if s:topCol == 1 || line('.') < s:scriptTag - return {} " E728, used as limit condition for loops and searchpair() +" Optimized {skip} expr, only callable from the search loop which +" GetJavascriptIndent does to find the containing [[{(] (side-effects) +function s:SkipFunc() + if s:top_col == 1 + throw 'out of bounds' endif - let s:topCol = col('.') - if getline('.') =~ '\%<'.s:topCol.'c\/.\{-}\/\|\%>'.s:topCol.'c[''"]\|\\$' + let s:top_col = 0 + if s:check_in if eval(s:skip_expr) - let s:topCol = 0 + return 1 endif - return !s:topCol - elseif s:checkIn || search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) - let s:checkIn = eval(s:skip_expr) - if s:checkIn - let s:topCol = 0 + let s:check_in = 0 + elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' + if eval(s:skip_expr) + return 1 endif + elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr) + let s:check_in = 1 + return 1 endif - let s:looksyn = line('.') - return s:checkIn + let [s:looksyn, s:top_col] = getpos('.')[1:2] endfunction -function s:alternatePair() - let [l:pos, pat, l:for] = [getpos('.'), '[][(){};]', 3] - while search('\m'.pat,'bW') - if s:skip_func() | continue | endif - let idx = stridx('])};',s:looking_at()) - if idx is 3 - if l:for is 1 - return s:GetPair('{','}','bW','s:skip_func()',2000) > 0 || setpos('.',l:pos) - endif - let [pat, l:for] = ['[{}();]', l:for - 1] - elseif idx + 1 - if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000) < 1 +function s:AlternatePair() + let [pat, l:for] = ['[][(){};]', 2] + while s:SearchLoop(pat,'bW','s:SkipFunc()') + if s:LookingAt() == ';' + if !l:for + if s:GetPair('{','}','bW','s:SkipFunc()') + return + endif break + else + let [pat, l:for] = ['[{}();]', l:for - 1] endif else - return + let idx = stridx('])}',s:LookingAt()) + if idx == -1 + return + elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') + break + endif endif endwhile - call setpos('.',l:pos) + throw 'out of bounds' endfunction -function s:looking_at() +function s:Nat(int) + return a:int * (a:int > 0) +endfunction + +function s:LookingAt() return getline('.')[col('.')-1] endfunction -function s:token() - return s:looking_at() =~ '\k' ? expand('') : s:looking_at() +function s:Token() + return s:LookingAt() =~ '\k' ? expand('') : s:LookingAt() endfunction -function s:previous_token() - let l:pos = getpos('.') +function s:PreviousToken() + let l:col = col('.') if search('\m\k\{1,}\|\S','ebW') - if (strpart(getline('.'),col('.')-2,2) == '*/' || line('.') != l:pos[1] && - \ getline('.')[:col('.')-1] =~ '\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com - while search('\m\S\ze\_s*\/[/*]','bW') - if s:syn_at(line('.'),col('.')) !~? s:syng_com - return s:token() - endif - endwhile + if search('\m\*\%#\/\|\/\/\%<'.a:firstline.'l','nbW',line('.')) && eval(s:in_comm) + if s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) + return s:Token() + endif + call cursor(a:firstline, l:col) else - return s:token() + return s:Token() endif - call setpos('.',l:pos) endif return '' endfunction -for s:__ in ['__previous_token','__IsBlock'] - function s:{s:__}(...) - let l:pos = getpos('.') - try - return call('s:'.matchstr(expand(''),'.*__\zs\w\+'),a:000) - catch - finally - call setpos('.',l:pos) - endtry - endfunction -endfor +function s:Pure(f,...) + return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]") +endfunction -function s:expr_col() - if getline('.')[col('.')-2] == ':' - return 1 - endif - let [bal, l:pos] = [0, getpos('.')] - while bal < 1 && search('\m[{}?:;]','bW',s:scriptTag) - if eval(s:skip_expr) - continue - elseif s:looking_at() == ':' - let bal -= strpart(getline('.'),col('.')-2,3) !~ '::' - elseif s:looking_at() == '?' +function s:SearchLoop(pat,flags,expr) + return s:GetPair(a:pat,'\_$.',a:flags,a:expr) +endfunction + +function s:ExprCol() + let bal = 0 + while s:SearchLoop('[{}?]\|\_[^:]\zs::\@!','bW',s:skip_expr) + if s:LookingAt() == ':' + let bal -= 1 + elseif s:LookingAt() == '?' let bal += 1 - elseif s:looking_at() == '{' && getpos('.')[1:2] != b:js_cache[1:] && !s:IsBlock() - let bal = 1 - elseif s:looking_at() != '}' || s:GetPair('{','}','bW',s:skip_expr,200) < 1 + if bal == 1 + break + endif + elseif s:LookingAt() == '{' + let bal = !s:IsBlock() + break + elseif !s:GetPair('{','}','bW',s:skip_expr) break endif endwhile - call setpos('.',l:pos) - return max([bal,0]) + return s:Nat(bal) endfunction " configurable regexes that define continuation lines, not including (, {, or [. let s:opfirst = '^' . get(g:,'javascript_opfirst', - \ '\C\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)') + \ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)') let s:continuation = get(g:,'javascript_continuation', \ '\C\%([<=,.~!?/*^%|&:]\|+\@\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$' -function s:continues(ln,con) - let token = matchstr(a:con[-15:],s:continuation) - if strlen(token) - call cursor(a:ln,strlen(a:con)) - if token =~ '[/>]' - return s:syn_at(a:ln,col('.')) !~? (token == '>' ? 'jsflow\|^html' : 'regex') - elseif token =~ '\l' - return s:previous_token() != '.' - elseif token == ':' - return s:expr_col() - endif - return 1 +function s:Continues(ln,con) + let tok = matchstr(a:con[-15:],s:continuation) + if tok =~ '[a-z:]' + call cursor(a:ln, len(a:con)) + return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.' + elseif tok !~ '[/>]' + return tok isnot '' endif -endfunction - -function s:Trim(ln) - let pline = substitute(getline(a:ln),'\s*$','','') - let l:max = max([strridx(pline,'//'), strridx(pline,'/*')]) - while l:max != -1 && s:syn_at(a:ln, strlen(pline)) =~? s:syng_com - let pline = pline[: l:max] - let l:max = max([strridx(pline,'//'), strridx(pline,'/*')]) - let pline = substitute(pline[:-2],'\s*$','','') - endwhile - return pline -endfunction - -" Find line above 'lnum' that isn't empty or in a comment -function s:PrevCodeLine(lnum) - let l:n = prevnonblank(a:lnum) - while l:n - if getline(l:n) =~ '^\s*\/[/*]' - if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') && - \ s:syn_at(l:n,1) =~? b:syng_str - break - endif - let l:n = prevnonblank(l:n-1) - elseif stridx(getline(l:n), '*/') + 1 && s:syn_at(l:n,1) =~? s:syng_com - let l:pos = getpos('.') - call cursor(l:n,1) - let l:n = search('\m\S\_s*\/\*','nbW') - call setpos('.',l:pos) - else - break - endif - endwhile - return l:n + return s:SynAt(a:ln, len(a:con)) !~? (tok == '>' ? 'jsflow\|^html' : 'regex') endfunction " Check if line 'lnum' has a balanced amount of parentheses. function s:Balanced(lnum) - let l:open = 0 - let l:line = getline(a:lnum) - let pos = match(l:line, '[][(){}]', 0) + let [l:open, l:line] = [0, getline(a:lnum)] + let pos = match(l:line, '[][(){}]') while pos != -1 - if s:syn_at(a:lnum,pos + 1) !~? b:syng_strcom + if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom let l:open += match(' ' . l:line[pos],'[[({]') if l:open < 0 return endif endif - let pos = match(l:line, (l:open ? - \ '['.matchstr(['][','()','{}'],l:line[pos]).']' : - \ '[][(){}]'), pos + 1) + let pos = match(l:line, !l:open ? '[][(){}]' : '()' =~ l:line[pos] ? + \ '[()]' : '{}' =~ l:line[pos] ? '[{}]' : '[][]', pos + 1) endwhile return !l:open endfunction -function s:OneScope(lnum) - let pline = s:Trim(a:lnum) - call cursor(a:lnum,strlen(pline)) - let kw = 'else do' - if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 - if s:previous_token() =~# '^\%(await\|each\)$' - call s:previous_token() - let kw = 'for' - else - let kw = 'for if let while with' - endif +function s:OneScope() + if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr) + let tok = s:PreviousToken() + return (count(split('for if let while with'),tok) || + \ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') && + \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile()) + elseif s:Token() =~# '^else$\|^do$' + return s:Pure('s:PreviousToken') != '.' endif - return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 && - \ s:__previous_token() != '.' && !s:doWhile() + return strpart(getline('.'),col('.')-2,2) == '=>' endfunction -function s:doWhile() - if expand('') ==# 'while' - let [bal, l:pos] = [0, getpos('.')] - call search('\m\<','cbW') - while bal < 1 && search('\m\C[{}]\|\<\%(do\|while\)\>','bW') - if eval(s:skip_expr) - continue - elseif s:looking_at() ==# 'd' - let bal += s:__IsBlock(1) - elseif s:looking_at() ==# 'w' - let bal -= s:__previous_token() != '.' - elseif s:looking_at() != '}' || s:GetPair('{','}','bW',s:skip_expr,200) < 1 - break - endif - endwhile - call setpos('.',l:pos) - return max([bal,0]) +function s:DoWhile() + let cpos = searchpos('\m\<','cbW') + if s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr) + if s:{s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) ? + \ 'Previous' : ''}Token() ==# 'do' && s:IsBlock() + return 1 + endif + call call('cursor',cpos) endif endfunction -" returns braceless levels started by 'i' and above lines * &sw. 'num' is the -" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is -" a continued expression, which could have started in a braceless context -function s:iscontOne(i,num,cont) - let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0] - let pind = a:num ? indent(l:num) + s:W : 0 - let ind = indent(l:i) + (a:cont ? 0 : s:W) - while l:i >= l:num && (ind > pind || l:i == l:num) - if indent(l:i) < ind && s:OneScope(l:i) - let bL += s:W - let l:i = line('.') - elseif !a:cont || bL || ind < indent(a:i) +" returns total offset from braceless contexts. 'num' is the lineNr which +" encloses the entire context, 'cont' if whether a:firstline is a continued +" expression, which could have started in a braceless context +function s:IsContOne(num,cont) + let [l:num, b_l] = [a:num + !a:num, 0] + let pind = a:num ? indent(a:num) + s:sw() : 0 + let ind = indent('.') + !a:cont + while line('.') > l:num && ind > pind || line('.') == l:num + if indent('.') < ind && s:OneScope() + let b_l += 1 + elseif !a:cont || b_l || ind < indent(a:firstline) + break + else + call cursor(0,1) + endif + let ind = min([ind, indent('.')]) + if s:PreviousToken() is '' break endif - let ind = min([ind, indent(l:i)]) - let l:i = s:PrevCodeLine(l:i - 1) endwhile - return bL + return b_l +endfunction + +function s:IsSwitch() + call call('cursor',b:js_cache[1:]) + return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z) endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader -function s:IsBlock(...) - if a:0 || s:looking_at() == '{' - let l:n = line('.') - let char = s:previous_token() - if match(s:stack,'\cxml\|jsx') + 1 && s:syn_at(line('.'),col('.')-1) =~? 'xml\|jsx' - return char != '{' - elseif char =~ '\k' - if char ==# 'type' - return s:__previous_token() !~# '^\%(im\|ex\)port$' - endif - return index(split('return const let import export extends yield default delete var await void typeof throw case new of in instanceof') - \ ,char) < (line('.') != l:n) || s:__previous_token() == '.' - elseif char == '>' - return getline('.')[col('.')-2] == '=' || s:syn_at(line('.'),col('.')) =~? 'jsflow\|^html' - elseif char == '*' - return s:__previous_token() == ':' - elseif char == ':' - return !s:expr_col() - elseif char == '/' - return s:syn_at(line('.'),col('.')) =~? 'regex' +function s:IsBlock() + let tok = s:PreviousToken() + if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx' + return tok != '{' + elseif tok =~ '\k' + if tok ==# 'type' + return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'") + elseif tok ==# 'of' + return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||" + \ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'") endif - return char !~ '[=~!<,.?^%|&([]' && - \ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char) + return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof') + \ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.' + elseif tok == '>' + return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html' + elseif tok == '*' + return s:Pure('s:PreviousToken') == ':' + elseif tok == ':' + return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()") + elseif tok == '/' + return s:SynAt(line('.'),col('.')) =~? 'regex' + elseif tok !~ '[=~!<,.?^%|&([]' + return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok endif endfunction - function GetJavascriptIndent() let b:js_cache = get(b:,'js_cache',[0,0,0]) - let s:synId_cache = {} - " Get the current line. - call cursor(v:lnum,1) - let l:line = getline('.') + let s:synid_cache = [[],[]] + let l:line = getline(v:lnum) " use synstack as it validates syn state and works in an empty line - let s:stack = map(synstack(v:lnum,1),"synIDattr(v:val,'name')") - let syns = get(s:stack,-1,'') + let s:stack = [''] + map(synstack(v:lnum,1),"synIDattr(v:val,'name')") " start with strings,comments,etc. - if syns =~? s:syng_com + if s:stack[-1] =~? 'comment\|doc' if l:line =~ '^\s*\*' return cindent(v:lnum) elseif l:line !~ '^\s*\/[/*]' return -1 endif - elseif syns =~? b:syng_str + elseif s:stack[-1] =~? b:syng_str if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1) let b:js_cache[0] = v:lnum endif return -1 endif - let l:lnum = s:PrevCodeLine(v:lnum - 1) - if !l:lnum + + let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000), + \ get(get(b:,'hi_indent',{}),'blocklnr')]) + call cursor(v:lnum,1) + if s:PreviousToken() is '' return endif + let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]] let l:line = substitute(l:line,'^\s*','','') + let l:line_raw = l:line if l:line[:1] == '/*' let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','') endif @@ -402,57 +354,94 @@ function GetJavascriptIndent() endif " the containing paren, bracket, or curly. Many hacks for performance - let [ s:scriptTag, idx ] = [ get(get(b:,'hi_indent',{}),'blocklnr'), - \ index([']',')','}'],l:line[0]) ] - if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && - \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) - call call('cursor',b:js_cache[2] ? b:js_cache[1:] : [0,0]) + call cursor(v:lnum,1) + let idx = index([']',')','}'],l:line[0]) + if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum || + \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum) + call call('cursor',b:js_cache[1:]) else - let [s:looksyn, s:checkIn, s:topCol] = [v:lnum - 1, 0, 0] - if idx + 1 - call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:skip_func()',2000) - elseif getline(v:lnum) !~ '^\S' && syns =~? 'block' - call s:GetPair('{','}','bW','s:skip_func()',2000) - else - call s:alternatePair() - endif + let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0, + \ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])] + try + if idx != -1 + call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') + elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$' + call s:GetPair('{','}','bW','s:SkipFunc()') + else + call s:AlternatePair() + endif + catch /^\Cout of bounds$/ + call cursor(v:lnum,1) + endtry + let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2] endif - let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [s:scriptTag,0] : getpos('.')[1:2]) - let num = b:js_cache[1] + let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]] - let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0] - if !b:js_cache[2] || s:IsBlock() + let [num_ind, is_op, b_l, l:switch_offset] = [s:Nat(indent(num)),0,0,0] + if !num || s:LookingAt() == '{' && s:IsBlock() let ilnum = line('.') - let pline = s:Trim(l:lnum) - if b:js_cache[2] && s:looking_at() == ')' && s:GetPair('(',')','bW',s:skip_expr,100) > 0 - let num = ilnum == num ? line('.') : num - if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.' - let switch_offset = &cino !~ ':' ? s:W : max([-indent(num),s:parse_cino(':')]) + if num && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) + if ilnum == num + let [num, num_ind] = [line('.'), indent('.')] + endif + if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch() + let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':') if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>' - return indent(num) + switch_offset + return s:Nat(num_ind + l:switch_offset) + elseif &cino =~ '=' + let l:case_offset = s:ParseCino('=') endif endif endif - if idx < 0 && pline[-1:] !~ '[{;]' - let isOp = (l:line =~# s:opfirst || s:continues(l:lnum,pline)) * s:W - let bL = s:iscontOne(l:lnum,b:js_cache[1],isOp) - let bL -= (bL && l:line[0] == '{') * s:W + if idx == -1 && pline[-1:] !~ '[{;]' + let sol = matchstr(l:line,s:opfirst) + if sol is '' || sol == '/' && s:SynAt(v:lnum, + \ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex' + if s:Continues(l:lnum,pline) + let is_op = s:sw() + endif + elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' + call cursor(l:lnum, len(pline)) + if s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) && + \ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) && + \ (s:PreviousToken() == ']' || s:Token() =~ '\k' && + \ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function') + return num_ind + s:sw() + endif + let is_op = s:sw() + else + let is_op = s:sw() + endif + call cursor(l:lnum, len(pline)) + let b_l = s:Nat(s:IsContOne(b:js_cache[1],is_op) - (!is_op && l:line =~ '^{')) * s:sw() endif - elseif idx < 0 && getline(b:js_cache[1])[b:js_cache[2]-1] == '(' && &cino =~ '(' - let pval = s:parse_cino('(') - return !pval || !search('\m\S','nbW',num) && !s:parse_cino('U') ? - \ (s:parse_cino('w') ? 0 : -!!search('\m\S','W'.s:z,num)) + virtcol('.') : - \ max([indent('.') + pval + s:GetPair('(',')','nbrmW',s:skip_expr,100,num) * s:W,0]) + elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U')) + let pval = s:ParseCino('(') + if !pval + let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')] + if search('\m\S','W',num) + return s:ParseCino('w') ? vcol : virtcol('.')-1 + endif + return Wval ? s:Nat(num_ind + Wval) : vcol + endif + return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw()) endif " main return if l:line =~ '^[])}]\|^|}' - return max([indent(num),0]) + if l:line_raw[0] == ')' && getline(num)[b:js_cache[2]-1] == '(' + if s:ParseCino('M') + return indent(l:lnum) + elseif &cino =~# 'm' && !s:ParseCino('m') + return virtcol('.') - 1 + endif + endif + return num_ind elseif num - return indent(num) + s:W + switch_offset + bL + isOp + return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op) endif - return bL + isOp + return b_l + is_op endfunction let &cpo = s:cpo_save diff --git a/indent/kotlin.vim b/indent/kotlin.vim index 20bc1ee9..aacf3edb 100644 --- a/indent/kotlin.vim +++ b/indent/kotlin.vim @@ -3,13 +3,14 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'kotlin') == -1 " Vim indent file " Language: Kotlin " Maintainer: Alexander Udalov -" Latest Revision: 27 June 2015 +" Latest Revision: 15 July 2017 if exists("b:did_indent") finish endif let b:did_indent = 1 +setlocal cinoptions& cinoptions+=j1,L0 setlocal indentexpr=GetKotlinIndent() setlocal indentkeys=0},0),!^F,o,O,e, setlocal autoindent " TODO ? @@ -25,6 +26,21 @@ function! GetKotlinIndent() let prev_indent = indent(prev_num) let cur = getline(v:lnum) + if cur =~ '^\s*\*' + return cindent(v:lnum) + endif + + if prev =~ '^\s*\*/' + let st = prev + while st > 1 + if getline(st) =~ '^\s*/\*' + break + endif + let st = st - 1 + endwhile + return indent(st) + endif + let prev_open_paren = prev =~ '^.*(\s*$' let cur_close_paren = cur =~ '^\s*).*$' diff --git a/indent/lua.vim b/indent/lua.vim index 901ac854..3c33c032 100644 --- a/indent/lua.vim +++ b/indent/lua.vim @@ -24,21 +24,21 @@ 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:open_patt = '\C\%(\<\%(function\|if\|repeat\|do\)\>\|(\|{\)' +let s:middle_patt = '\C\<\%(else\|elseif\)\>' +let s:close_patt = '\C\%(\<\%(end\|until\)\>\|)\|}\)' let s:anon_func_start = '\S\+\s*[({].*\ 1 && contents_prev =~ s:anon_func_start + if num_pairs > 1 && contents_prev =~# s:anon_func_start let i = 1 endif @@ -98,7 +98,7 @@ function GetLuaIndent() endif " special case: end}) -- end of call with anon func should unindent once - if num_pairs > 1 && contents_cur =~ s:anon_func_end + if num_pairs > 1 && contents_cur =~# s:anon_func_end let i = -1 endif diff --git a/indent/mako.vim b/indent/mako.vim index bd6120a5..e3971197 100644 --- a/indent/mako.vim +++ b/indent/mako.vim @@ -44,8 +44,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mako') == -1 " 0.1 - 06 June 2009 " - Initial public release of mako indent file -let sw=2 " default shiftwidth of 2 spaces - if exists("b:did_indent") finish endif @@ -55,6 +53,9 @@ setlocal nosmartindent setlocal noautoindent setlocal nocindent setlocal nolisp +setlocal expandtab +setlocal softtabstop=2 +setlocal shiftwidth=2 setlocal indentexpr=GetMakoIndent() setlocal indentkeys+=*,<>>,,end,: diff --git a/indent/plantuml.vim b/indent/plantuml.vim index a5e6fcdf..1cfc91b7 100644 --- a/indent/plantuml.vim +++ b/indent/plantuml.vim @@ -19,7 +19,7 @@ let s:incIndent = \ '^\s*[hr]\?note\>\%(\%("[^"]*" \\)\@![^:]\)*$\|' . \ '^\s*title\s*$\|' . \ '^\s*skinparam\>.*{\s*$\|' . - \ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\)\>.*{' + \ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\|object\)\>.*{' let s:decIndent = '^\s*\%(end\|else\|}\)' diff --git a/indent/purescript.vim b/indent/purescript.vim index c456c608..c22da095 100644 --- a/indent/purescript.vim +++ b/indent/purescript.vim @@ -37,9 +37,16 @@ if !exists('g:purescript_indent_let') let g:purescript_indent_let = 4 endif +if !exists('g:purescript_indent_in') + " let x = 0 + " >in + let g:purescript_indent_in = 1 +endif + if !exists('g:purescript_indent_where') - " where f :: Int -> Int - " >>>>>>f x = x + " where + " >>f :: Int -> Int + " >>f x = x let g:purescript_indent_where = 6 endif @@ -49,16 +56,29 @@ if !exists('g:purescript_indent_do') let g:purescript_indent_do = 3 endif +if !exists('g:purescript_indent_dot') + " f + " :: forall a + " >. String + " -> String + let g:purescript_indent_dot = 1 +endif + setlocal indentexpr=GetPurescriptIndent() -setlocal indentkeys=!^F,o,O,},=where,=in +setlocal indentkeys=!^F,o,O,},=where,=in,=::,=->,=→,==>,=⇒ + +function! s:GetSynStack(lnum, col) + return map(synstack(a:lnum, a:col), { key, val -> synIDattr(val, "name") }) +endfunction function! GetPurescriptIndent() + let ppline = getline(v:lnum - 2) let prevline = getline(v:lnum - 1) let line = getline(v:lnum) if line =~ '^\s*\' - let s = match(prevline, '\S') - return s + 2 + let s = indent(v:lnum - 1) + return max([s, &l:shiftwidth]) endif if line =~ '^\s*\' @@ -67,72 +87,191 @@ function! GetPurescriptIndent() while s <= 0 && n > 0 let n = n - 1 - let s = match(getline(n),'\') + let s = match(getline(n), '\') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') != -1 + let s = -1 + endif endwhile - return s + 1 + return s + g:purescript_indent_in + endif + + let s = match(prevline, '^\s*\zs\(--\|import\)') + if s >= 0 + " comments + " imports + return s + endif + + if prevline =~ '^\S.*::' && line !~ '^\s*\(\.\|->\|→\|=>\|⇒\)' && !~ '^instance' + " f :: String + " -> String + return 0 + endif + + let s = match(prevline, '[[:alnum:][:blank:]]\@<=|[[:alnum:][:blank:]$]') + if s >= 0 && prevline !~ '^class\>' && index(s:GetSynStack(v:lnum - 1, s), "purescriptFunctionDecl") == -1 + " ident pattern guards but not if we are in a type declaration + " what we detect using syntax groups + if prevline =~ '|\s*otherwise\>' + return indent(search('^\s*\k', 'bnW')) + " somehow this pattern does not work :/ + " return indent(search('^\(\s*|\)\@!', 'bnW')) + else + return s + endif + endif + + let s = match(line, '\%(\\.\{-}\)\@<=->') + if s >= 0 + " inline lambda + return indent(v:lnum) + endif + + " indent rules for -> (lambdas and case expressions) + let s = match(line, '->') + let p = match(prevline, '\\') + " protect that we are not in a type signature + " and not in a case expression + if s >= 0 && index(s:GetSynStack(s == 0 ? v:lnum - 1 : v:lnum, max([1, s])), "purescriptFunctionDecl") == -1 + \ && p >= 0 && index(s:GetSynStack(v:lnum - 1, p), "purescriptString") == -1 + return p + endif + + if prevline =~ '^\S' + " start typing signature, function body, data & newtype on next line + return &l:shiftwidth endif - if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$' + if ppline =~ '^\S' && prevline =~ '^\s*$' + return 0 + endif + + if line =~ '^\s*\%(::\|∷\)' + return match(prevline, '\S') + &l:shiftwidth + endif + + if prevline =~ '^\s*\(::\|∷\)\s*forall' + return match(prevline, '\S') + g:purescript_indent_dot + endif + + let s = match(prevline, '^\s*\zs\%(::\|∷\|=>\|⇒\|->\|→\)') + let r = match(prevline, '^\s*\zs\.') + if s >= 0 || r >= 0 + if s >= 0 + if line !~ '^\s*\%(::\|∷\|=>\|⇒\|->\|→\)' && line !~ '^\s*$' + return s - 2 + else + return s + endif + elseif r >= 0 + if line !~ '^\s\%(::\|∷\|=>\|⇒\|->\|→\)' + return r - g:purescript_indent_dot + else + return r + endif + endif + endif + + if prevline =~ '[!#$%&*+./<>?@\\^~-]\s*$' let s = match(prevline, '=') if s > 0 - return s + 2 + return s + &l:shiftwidth endif - let s = match(prevline, ':') + let s = match(prevline, '\<:\>') if s > 0 - return s + 3 + return s + &l:shiftwidth else - return match(prevline, '\S') + return match(prevline, '\S') + &l:shiftwidth endif endif if prevline =~ '[{([][^})\]]\+$' + echom "return 1" return match(prevline, '[{([]') endif - if prevline =~ '\\s\+.\+\(\\)\?\s*$' + let s = match(prevline, '\\s\+\zs\S') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return s + endif + + let s = match(prevline, '\\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return s + g:purescript_indent_let + endif + + let s = match(prevline, '\\s\+.\+\(\\)\?\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 return match(prevline, '\') + g:purescript_indent_let endif - if prevline !~ '\' - let s = match(prevline, '\.*\&.*\zs\') - if s > 0 - return s + let s = searchpairpos('\%(--.\{-}\)\@', '\', '\.*\zs$', 'bnrc')[0] + if s > 0 + " this rule ensures that using `=` in visual mode will correctly indent + " `if then else`, but it does not handle lines after `then` and `else` + if line =~ '\<\%(then\|else\)\>' + return match(getline(s), '\') + &l:shiftwidth endif + endif - let s = match(prevline, '\') - if s > 0 - return s + g:purescript_indent_if - endif + let p = match(prevline, '\\%(.\{-}\.\{-}\\)\@!') + if p > 0 + return p + &l:shiftwidth + endif + + let s = match(prevline, '=\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return match(prevline, '\S') + &l:shiftwidth + endif + + let s = match(prevline, '[{([]\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return match(prevline, '\S') + (line !~ '^\s*[})]]' ? 0 : &l:shiftwidth) + endif + + if prevline =~ '^class' + return &l:shiftwidth + endif + + let s = match(prevline, '\\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return match(prevline, '\S') + g:purescript_indent_where endif - if prevline =~ '\(\\|\\|=\|[{([]\)\s*$' - return match(prevline, '\S') + &shiftwidth + let s = match(prevline, '\\s\+\zs\S\+.*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return s endif - if prevline =~ '\\s\+\S\+.*$' - return match(prevline, '\') + g:purescript_indent_where + let s = match(prevline, '\\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return match(prevline, '\S') + g:purescript_indent_do endif - if prevline =~ '\\s\+\S\+.*$' - return match(prevline, '\') + g:purescript_indent_do + let s = match(prevline, '\\s\+\zs\S\+.*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return s endif - if prevline =~ '^\s*\\s\+[^=]\+\s\+=\s\+\S\+.*$' + let s = match(prevline, '^\s*\\s\+[^=]\+\s\+=\s\+\S\+.*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 return match(prevline, '=') endif - if prevline =~ '\\s\+.\+\\s*$' + let s = match(prevline, '\\s\+.\+\\s*$') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 return match(prevline, '\') + g:purescript_indent_case endif if prevline =~ '^\s*\<\data\>\s\+\S\+\s*$' - return match(prevline, '\') + &shiftwidth + return match(prevline, '\') + &l:shiftwidth endif - if (line =~ '^\s*}\s*' && prevline !~ '^\s*;') - return match(prevline, '\S') - &shiftwidth + let s = match(prevline, '^\s*[}\]]') + if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 + return match(prevline, '\S') - &l:shiftwidth endif return match(prevline, '\S') diff --git a/indent/rust.vim b/indent/rust.vim index fec789de..042e2ab5 100644 --- a/indent/rust.vim +++ b/indent/rust.vim @@ -3,11 +3,12 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Vim indent file " Language: Rust " Author: Chris Morgan -" Last Change: 2016 Jul 15 +" Last Change: 2017 Mar 21 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim " Only load this indent file when no other was loaded. if exists("b:did_indent") - finish + finish endif let b:did_indent = 1 @@ -15,7 +16,7 @@ setlocal cindent setlocal cinoptions=L0,(0,Ws,J1,j1 setlocal cinkeys=0{,0},!^F,o,O,0[,0] " Don't think cinwords will actually do anything at all... never mind -setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern +setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern,macro " Some preliminary settings setlocal nolisp " Make sure lisp indenting doesn't supersede us @@ -27,9 +28,12 @@ setlocal indentexpr=GetRustIndent(v:lnum) " Only define the function once. if exists("*GetRustIndent") - finish + finish endif +let s:save_cpo = &cpo +set cpo&vim + " Come here when loading the script the first time. function! s:get_line_trimmed(lnum) @@ -207,4 +211,7 @@ function GetRustIndent(lnum) return cindent(a:lnum) endfunction +let &cpo = s:save_cpo +unlet s:save_cpo + endif diff --git a/indent/swift.vim b/indent/swift.vim index 773e6451..92df0fc8 100644 --- a/indent/swift.vim +++ b/indent/swift.vim @@ -51,7 +51,7 @@ endfunction function! s:IsCommentLine(lnum) return synIDattr(synID(a:lnum, - \ match(getline(a:lnum), "\S") + 1, 0), "name") + \ match(getline(a:lnum), "\\S") + 1, 0), "name") \ ==# "swiftComment" endfunction @@ -227,8 +227,8 @@ function! SwiftIndent(...) if numOpenParens > 0 let savePosition = getcurpos() " Must be at EOL because open paren has to be above (left of) the cursor - call cursor(previousNum, col("$")) - let previousParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()") + call cursor(previousNum, [previousNum, col("$")]) + let previousParen = searchpair("(", "", ")", "cbWn", "s:IsExcludedFromIndent()") call setpos(".", savePosition) return indent(previousParen) + shiftwidth() endif diff --git a/indent/terraform.vim b/indent/terraform.vim index 30c78229..5a29dfb4 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -30,7 +30,7 @@ function! TerraformIndent(lnum) let thisindent = previndent " block open? - if prevline =~ '[\[{]\s*$' + if prevline =~ '[\[{\(]\s*$' let thisindent += &sw endif @@ -38,7 +38,7 @@ function! TerraformIndent(lnum) let thisline = substitute(getline(a:lnum), '//.*$', '', '') " block close? - if thisline =~ '^\s*[\]}]' + if thisline =~ '^\s*[\)\]}]' let thisindent -= &sw endif diff --git a/indent/vue.vim b/indent/vue.vim index 038996ba..226c6522 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -25,10 +25,10 @@ let s:languages = [ \ { 'name': 'javascript', 'pairs': [''] }, \ ] -for language in s:languages +for s:language in s:languages " Set 'indentexpr' if the user has an indent file installed for the language - if strlen(globpath(&rtp, 'indent/'. language.name .'.vim')) - let language.indentexpr = s:get_indentexpr(language.name) + if strlen(globpath(&rtp, 'indent/'. s:language.name .'.vim')) + let s:language.indentexpr = s:get_indentexpr(s:language.name) endif endfor diff --git a/syntax/ansible.vim b/syntax/ansible.vim index 36167b65..c610c41d 100644 --- a/syntax/ansible.vim +++ b/syntax/ansible.vim @@ -47,6 +47,58 @@ highlight link yamlFlowString NONE " but it does make sense we visualize quotes easily highlight link yamlFlowStringDelimiter Delimiter +fun! s:normal_keywords_highlight(name) + if a:name == 'Comment' + highlight link ansible_normal_keywords Comment + elseif a:name == 'Constant' + highlight link ansible_normal_keywords Constant + elseif a:name == 'Identifier' + highlight link ansible_normal_keywords Identifier + elseif a:name == 'Statement' + highlight link ansible_normal_keywords Statement + elseif a:name == 'PreProc' + highlight link ansible_normal_keywords PreProc + elseif a:name == 'Type' + highlight link ansible_normal_keywords Type + elseif a:name == 'Special' + highlight link ansible_normal_keywords Special + elseif a:name == 'Underlined' + highlight link ansible_normal_keywords Underlined + elseif a:name == 'Ignore' + highlight link ansible_normal_keywords Ignore + elseif a:name == 'Error' + highlight link ansible_normal_keywords Error + elseif a:name == 'Todo' + highlight link ansible_normal_keywords Todo + endif +endfun + +fun! s:with_keywords_highlight(name) + if a:name == 'Comment' + highlight link ansible_with_keywords Comment + elseif a:name == 'Constant' + highlight link ansible_with_keywords Constant + elseif a:name == 'Identifier' + highlight link ansible_with_keywords Identifier + elseif a:name == 'Statement' + highlight link ansible_with_keywords Statement + elseif a:name == 'PreProc' + highlight link ansible_with_keywords PreProc + elseif a:name == 'Type' + highlight link ansible_with_keywords Type + elseif a:name == 'Special' + highlight link ansible_with_keywords Special + elseif a:name == 'Underlined' + highlight link ansible_with_keywords Underlined + elseif a:name == 'Ignore' + highlight link ansible_with_keywords Ignore + elseif a:name == 'Error' + highlight link ansible_with_keywords Error + elseif a:name == 'Todo' + highlight link ansible_with_keywords Todo + endif +endfun + fun! s:attribute_highlight(attributes) if a:attributes =~ 'a' syn match ansible_attributes "\v\w+\=" containedin=yamlPlainScalar @@ -85,11 +137,19 @@ if exists("g:ansible_extra_keywords_highlight") highlight link ansible_extra_special_keywords Statement endif -syn keyword ansible_special_keywords include until retries delay when only_if become become_user block rescue always notify containedin=yamlBlockMappingKey contained -highlight link ansible_special_keywords Statement +syn keyword ansible_normal_keywords include include_tasks import_tasks until retries delay when only_if become become_user block rescue always notify containedin=yamlBlockMappingKey contained +if exists("g:ansible_normal_keywords_highlight") + call s:normal_keywords_highlight(g:ansible_normal_keywords_highlight) +else + highlight link ansible_normal_keywords Statement +endif syn match ansible_with_keywords "\vwith_.+" containedin=yamlBlockMappingKey contained -highlight link ansible_with_keywords Statement +if exists("g:ansible_with_keywords_highlight") + call s:with_keywords_highlight(g:ansible_with_keywords_highlight) +else + highlight link ansible_with_keywords Statement +endif let b:current_syntax = "ansible" diff --git a/syntax/cpp.vim b/syntax/cpp.vim index ff0c7ec2..67e3e5ac 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -4,7 +4,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c/c++') == -1 " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2016 Oct 28 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -50,7 +49,7 @@ endif if !exists("cpp_no_cpp14") syn case ignore syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>" syn case match endif diff --git a/syntax/dart.vim b/syntax/dart.vim index 21749b45..460c74a1 100644 --- a/syntax/dart.vim +++ b/syntax/dart.vim @@ -18,6 +18,8 @@ endif " Ensure long multiline strings are highlighted. syntax sync fromstart +syntax case match + " keyword definitions syntax keyword dartConditional if else switch syntax keyword dartRepeat do while for @@ -26,14 +28,14 @@ syntax keyword dartConstant null syntax keyword dartTypedef this super class typedef enum syntax keyword dartOperator new is as in syntax match dartOperator "+=\=\|-=\=\|*=\=\|/=\=\|%=\=\|\~/=\=\|<<=\=\|>>=\=\|[<>]=\=\|===\=\|\!==\=\|&=\=\|\^=\=\||=\=\|||\|&&\|\[\]=\=\|=>\|!\|\~\|?\|:" -syntax keyword dartType void var bool int double num dynamic +syntax keyword dartType void var bool int double num dynamic covariant syntax keyword dartStatement return syntax keyword dartStorageClass static abstract final const factory syntax keyword dartExceptions throw rethrow try on catch finally syntax keyword dartAssert assert syntax keyword dartClassDecl extends with implements syntax keyword dartBranch break continue nextgroup=dartUserLabelRef skipwhite -syntax keyword dartKeyword get set operator call external async await yield sync +syntax keyword dartKeyword get set operator call external async await yield sync native syntax match dartUserLabelRef "\k\+" contained syntax region dartLabelRegion transparent matchgroup=dartLabel start="\" matchgroup=NONE end=":" @@ -47,6 +49,24 @@ syntax match dartLibrary "^\(library\|part of\|part\)\>" syntax match dartMetadata "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>" +" Numbers +syntax match dartNumber "\<\d\+\(\.\d\+\)\=\>" + +" Core libraries +if !exists('dart_corelib_highlight') || dart_corelib_highlight + syntax keyword dartCoreClasses BidirectionalIterator Comparable DateTime + \ Duration Expando Function Invocation Iterable Iterator List Map Match + \ Object Pattern RegExp RuneIterator Runes Set StackTrace Stopwatch String + \ StringBuffer StringSink Symbol Type + syntax keyword dartCoreTypedefs Comparator + syntax keyword dartCoreExceptions AbstractClassInstantiationError + \ ArgumentError AssertionError CastError ConcurrentModificationError + \ Error Exception FallThroughError FormatException + \ IntegerDivisionByZeroException NoSuchMethodError NullThrownError + \ OutOfMemoryError RangeError RuntimeError StackOverflowError StateError + \ TypeError UnimplementedError UnsupportedError +endif + " Comments syntax keyword dartTodo contained TODO FIXME XXX syntax region dartComment start="/\*" end="\*/" contains=dartComment,dartTodo,dartDocLink,@Spell @@ -55,21 +75,18 @@ syntax match dartLineDocComment "///.*" contains=dartTodo,dartDocLink,@Spell syntax region dartDocLink oneline contained start=+\[+ end=+\]+ " Strings -syntax region dartString start=+\z(["']\)+ end=+\z1+ contains=@Spell,dartInterpolation,dartSpecialChar -syntax region dartRawString start=+r\z(["']\)+ end=+\z1+ contains=@Spell -syntax region dartMultilineString start=+\z("\{3\}\|'\{3\}\)+ end=+\z1+ contains=@Spell,dartInterpolation,dartSpecialChar -syntax region dartRawMultilineString start=+r\z("\{3\}\|'\{3\}\)+ end=+\z1+ contains=@Spell -syntax match dartInterpolation contained "\$\(\w\+\|{[^}]\+}\)" -syntax match dartSpecialChar contained "\\\(u\x\{4\}\|u{\x\+}\|x\x\x\|x{\x\+}\|.\)" - -" Numbers -syntax match dartNumber "\<\d\+\(\.\d\+\)\=\>" - -" TODO(antonm): consider conditional highlighting of corelib classes. -syntax keyword dartCoreClasses BidirectionalIterator Comparable DateTime Duration Expando Function Invocation Iterable Iterator List Map Match Object Pattern RegExp RuneIterator Runes Set StackTrace Stopwatch String StringBuffer StringSink Symbol Type -syntax keyword dartCoreTypedefs Comparator -syntax keyword dartCoreExceptions AbstractClassInstantiationError ArgumentError AssertionError CastError ConcurrentModificationError Error Exception FallThroughError FormatException IntegerDivisionByZeroException NoSuchMethodError NullThrownError OutOfMemoryError RangeError RuntimeError StackOverflowError StateError TypeError UnimplementedError UnsupportedError - +syntax cluster dartRawStringContains contains=@Spell +if exists('dart_html_in_strings') && dart_html_in_strings + syntax include @HTML syntax/html.vim + syntax cluster dartRawStringContains add=@HTML +endif +syntax cluster dartStringContains contains=@dartRawStringContains,dartInterpolation,dartSpecialChar +syntax region dartString oneline start=+\z(["']\)+ end=+\z1+ contains=@dartStringContains keepend +syntax region dartRawString oneline start=+r\z(["']\)+ end=+\z1+ contains=@dartRawStringContains keepend +syntax region dartMultilineString start=+\z("\{3\}\|'\{3\}\)+ end=+\z1+ contains=@dartStringContains +syntax region dartRawMultilineString start=+r\z("\{3\}\|'\{3\}\)+ end=+\z1+ contains=@dartSRawtringContains +syntax match dartInterpolation contained "\$\(\w\+\|{[^}]\+}\)" extend +syntax match dartSpecialChar contained "\\\(u\x\{4\}\|u{\x\+}\|x\x\x\|x{\x\+}\|.\)" extend " The default highlighting. highlight default link dartBranch Conditional diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 8fe0bf11..beb1317d 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -18,26 +18,27 @@ syn cluster elixirDeclaration contains=elixirFunctionDeclaration,elixirModuleDec syn match elixirComment '#.*' contains=elixirTodo,@Spell syn keyword elixirTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained -syn match elixirId '\<[_a-zA-Z]\w*[!?]\?\>' +syn match elixirId '\<[_a-zA-Z]\w*[!?]\?\>' contains=elixirUnusedVariable,elixirKernelFunction syn match elixirKeyword '\(\.\)\@' syn match elixirKeyword '\(\.\)\@' syn match elixirKeyword '\(\.\)\@' " Kernel functions -syn match elixirKernelFunction contained containedin=elixirGuard '\<\(is_atom\|is_binary\|is_bitstring\|is_boolean\|is_float\|is_function\|is_integer\|is_list\|is_map\|is_nil\|is_number\|is_pid\|is_port\)\>\([ (]\)\@=' -syn match elixirKernelFunction contained containedin=elixirGuard '\<\(is_record\|is_reference\|is_tuple\|is_exception\|abs\|bit_size\|byte_size\|div\|elem\|hd\|length\|map_size\|node\|rem\|round\|tl\|trunc\|tuple_size\)\>\([ (]\)\@=' - -syn match elixirGuard '.*when.*' contains=ALLBUT,@elixirNotTop +syn keyword elixirKernelFunction contained is_atom is_binary is_bitstring is_boolean is_float +syn keyword elixirKernelFunction contained is_function is_integer is_list is_map is_nil +syn keyword elixirKernelFunction contained is_number is_pid is_port is_reference is_tuple +syn keyword elixirKernelFunction contained abs binary_part bit_size byte_size div elem hd length +syn keyword elixirKernelFunction contained map_size node rem round tl trunc tuple_size syn keyword elixirInclude import require alias use syn keyword elixirSelf self " This unfortunately also matches function names in function calls -syn match elixirUnusedVariable contained '\<_\w*\>' +syn match elixirUnusedVariable contained '\v%(^|[^.])@<=<_\w*>' -syn keyword elixirOperator and not or in +syn match elixirOperator '\v\.@' syn match elixirOperator '!==\|!=\|!' syn match elixirOperator '=\~\|===\|==\|=' syn match elixirOperator '<<<\|<<\|<=\|<-\|<' @@ -54,8 +55,6 @@ syn match elixirAtom '\(:\)\@=]\@!\)\?\|<>\|===\ syn match elixirAtom '\(:\)\@\|&&\?\|%\(()\|\[\]\|{}\)\|++\?\|--\?\|||\?\|!\|//\|[%&`/|]\)' syn match elixirAtom "\%([a-zA-Z_]\w*[?!]\?\):\(:\)\@!" -syn match elixirBlockInline "\<\(do\|else\)\>:\@=" - syn match elixirAlias '\([a-z]\)\@:\@!" end="\" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold syn region elixirAnonymousFunction matchgroup=elixirBlockDefinition start="\" end="\" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold -syn region elixirArguments start="(" end=")" contained contains=elixirOperator,elixirAtom,elixirPseudoVariable,elixirAlias,elixirBoolean,elixirVariable,elixirUnusedVariable,elixirNumber,elixirDocString,elixirAtomInterpolated,elixirRegex,elixirString,elixirStringDelimiter,elixirRegexDelimiter,elixirInterpolationDelimiter,elixirSigilDelimiter,elixirAnonymousFunction +syn region elixirArguments start="(" end=")" contained contains=elixirOperator,elixirAtom,elixirPseudoVariable,elixirAlias,elixirBoolean,elixirVariable,elixirUnusedVariable,elixirNumber,elixirDocString,elixirAtomInterpolated,elixirRegex,elixirString,elixirStringDelimiter,elixirRegexDelimiter,elixirInterpolationDelimiter,elixirSigil,elixirAnonymousFunction syn match elixirDelimEscape "\\[(<{\[)>}\]/\"'|]" transparent display contained contains=NONE @@ -174,7 +173,6 @@ syn match elixirExUnitMacro "\(^\s*\)\@<=\<\(test\|describe\|setup\|setup_all\| syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(assert\|assert_in_delta\|assert_raise\|assert_receive\|assert_received\|catch_error\)\>" syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(catch_exit\|catch_throw\|flunk\|refute\|refute_in_delta\|refute_receive\|refute_received\)\>" -hi def link elixirBlockInline Keyword hi def link elixirBlockDefinition Keyword hi def link elixirDefine Define hi def link elixirPrivateDefine Define diff --git a/syntax/erlang.vim b/syntax/erlang.vim index c01c0b2f..c6794a01 100644 --- a/syntax/erlang.vim +++ b/syntax/erlang.vim @@ -118,14 +118,14 @@ syn keyword erlangBIF garbage_collect get get_keys group_leader contained syn keyword erlangBIF halt hd integer_to_binary integer_to_list contained syn keyword erlangBIF iolist_to_binary iolist_size is_alive contained syn keyword erlangBIF is_atom is_binary is_bitstring is_boolean contained -syn keyword erlangBIF is_float is_function is_integer is_list contained +syn keyword erlangBIF is_float is_function is_integer is_list is_map contained syn keyword erlangBIF is_number is_pid is_port is_process_alive contained syn keyword erlangBIF is_record is_reference is_tuple length link contained syn keyword erlangBIF list_to_atom list_to_binary contained syn keyword erlangBIF list_to_bitstring list_to_existing_atom contained syn keyword erlangBIF list_to_float list_to_integer list_to_pid contained -syn keyword erlangBIF list_to_tuple load_module make_ref max min contained -syn keyword erlangBIF module_loaded monitor monitor_node node contained +syn keyword erlangBIF list_to_tuple load_module make_ref map_size max contained +syn keyword erlangBIF min module_loaded monitor monitor_node node contained syn keyword erlangBIF nodes now open_port pid_to_list port_close contained syn keyword erlangBIF port_command port_connect pre_loaded contained syn keyword erlangBIF process_flag process_flag process_info contained diff --git a/syntax/eruby.vim b/syntax/eruby.vim index e152e071..75354042 100644 --- a/syntax/eruby.vim +++ b/syntax/eruby.vim @@ -24,7 +24,7 @@ elseif !exists("b:eruby_subtype") && main_syntax == 'eruby' let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$") let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+') if b:eruby_subtype == '' - let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') + let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') endif if b:eruby_subtype == 'rhtml' let b:eruby_subtype = 'html' @@ -49,7 +49,7 @@ if !b:eruby_nest_level let b:eruby_nest_level = 1 endif -if exists("b:eruby_subtype") && b:eruby_subtype != '' +if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby' exe "runtime! syntax/".b:eruby_subtype.".vim" unlet! b:current_syntax endif diff --git a/syntax/glsl.vim b/syntax/glsl.vim index e77354bb..73c2afa1 100644 --- a/syntax/glsl.vim +++ b/syntax/glsl.vim @@ -13,7 +13,7 @@ syn keyword glslRepeat for while do syn keyword glslStatement discard return break continue " Comments -syn keyword glslTodo contained TODO FIXME XXX +syn keyword glslTodo contained TODO FIXME XXX NOTE syn region glslCommentL start="//" skip="\\$" end="$" keepend contains=glslTodo,@Spell syn region glslComment matchgroup=glslCommentStart start="/\*" end="\*/" extend contains=glslTodo,@Spell @@ -28,15 +28,15 @@ syn region glslPreProc start="^\s*#\s*\(error\|pragma\|extension\|versi syn keyword glslBoolean true false " Integer Numbers -syn match glslDecimalInt display "\(0\|[1-9]\d*\)[uU]\?" -syn match glslOctalInt display "0\o\+[uU]\?" -syn match glslHexInt display "0[xX]\x\+[uU]\?" +syn match glslDecimalInt display "\<\(0\|[1-9]\d*\)[uU]\?" +syn match glslOctalInt display "\<0\o\+[uU]\?" +syn match glslHexInt display "\<0[xX]\x\+[uU]\?" " Float Numbers -syn match glslFloat display "\d\+\.\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" -syn match glslFloat display "\.\d\+\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" -syn match glslFloat display "\d\+[eE][+-]\=\d\+\(lf\|LF\|f\|F\)\=" -syn match glslFloat display "\d\+\.\d\+\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" +syn match glslFloat display "\<\d\+\.\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" +syn match glslFloat display "\<\.\d\+\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" +syn match glslFloat display "\<\d\+[eE][+-]\=\d\+\(lf\|LF\|f\|F\)\=" +syn match glslFloat display "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=\(lf\|LF\|f\|F\)\=" " Swizzles syn match glslSwizzle display /\.[xyzw]\{1,4\}\>/ @@ -44,10 +44,9 @@ syn match glslSwizzle display /\.[rgba]\{1,4\}\>/ syn match glslSwizzle display /\.[stpq]\{1,4\}\>/ " Structure -syn keyword glslStructure struct +syn keyword glslStructure struct nextgroup=glslIdentifier skipwhite skipempty -" This prevents numbers at ends of identifies from being highlighted as numbers -syn match glslIdentifier display "\I\i*" +syn match glslIdentifier contains=glslIdentifierPrime "\%([a-zA-Z_]\)\%([a-zA-Z0-9_]\)*" display contained " Types syn keyword glslType atomic_uint @@ -171,6 +170,7 @@ syn keyword glslType vec4 syn keyword glslType void " Qualifiers +syn keyword glslQualifier align syn keyword glslQualifier attribute syn keyword glslQualifier binding syn keyword glslQualifier buffer @@ -276,16 +276,22 @@ syn keyword glslQualifier varying syn keyword glslQualifier vertices syn keyword glslQualifier volatile syn keyword glslQualifier writeonly +syn keyword glslQualifier xfb_buffer +syn keyword glslQualifier xfb_stride +syn keyword glslQualifier xfb_offset " Built-in Constants +syn keyword glslBuiltinConstant gl_CullDistance syn keyword glslBuiltinConstant gl_MaxAtomicCounterBindings syn keyword glslBuiltinConstant gl_MaxAtomicCounterBufferSize syn keyword glslBuiltinConstant gl_MaxClipDistances syn keyword glslBuiltinConstant gl_MaxClipPlanes syn keyword glslBuiltinConstant gl_MaxCombinedAtomicCounterBuffers syn keyword glslBuiltinConstant gl_MaxCombinedAtomicCounters +syn keyword glslBuiltinConstant gl_MaxCombinedClipAndCullDistances syn keyword glslBuiltinConstant gl_MaxCombinedImageUniforms syn keyword glslBuiltinConstant gl_MaxCombinedImageUnitsAndFragmentOutputs +syn keyword glslBuiltinConstant gl_MaxCombinedShaderOutputResources syn keyword glslBuiltinConstant gl_MaxCombinedTextureImageUnits syn keyword glslBuiltinConstant gl_MaxComputeAtomicCounterBuffers syn keyword glslBuiltinConstant gl_MaxComputeAtomicCounters @@ -294,6 +300,7 @@ syn keyword glslBuiltinConstant gl_MaxComputeTextureImageUnits syn keyword glslBuiltinConstant gl_MaxComputeUniformComponents syn keyword glslBuiltinConstant gl_MaxComputeWorkGroupCount syn keyword glslBuiltinConstant gl_MaxComputeWorkGroupSize +syn keyword glslBuiltinConstant gl_MaxCullDistances syn keyword glslBuiltinConstant gl_MaxDrawBuffers syn keyword glslBuiltinConstant gl_MaxFragmentAtomicCounterBuffers syn keyword glslBuiltinConstant gl_MaxFragmentAtomicCounters @@ -317,6 +324,7 @@ syn keyword glslBuiltinConstant gl_MaxImageUnits syn keyword glslBuiltinConstant gl_MaxLights syn keyword glslBuiltinConstant gl_MaxPatchVertices syn keyword glslBuiltinConstant gl_MaxProgramTexelOffset +syn keyword glslBuiltinConstant gl_MaxSamples syn keyword glslBuiltinConstant gl_MaxTessControlAtomicCounterBuffers syn keyword glslBuiltinConstant gl_MaxTessControlAtomicCounters syn keyword glslBuiltinConstant gl_MaxTessControlImageUniforms @@ -337,6 +345,8 @@ syn keyword glslBuiltinConstant gl_MaxTessPatchComponents syn keyword glslBuiltinConstant gl_MaxTextureCoords syn keyword glslBuiltinConstant gl_MaxTextureImageUnits syn keyword glslBuiltinConstant gl_MaxTextureUnits +syn keyword glslBuiltinConstant gl_MaxTransformFeedbackBuffers +syn keyword glslBuiltinConstant gl_MaxTransformFeedbackInterleavedComponents syn keyword glslBuiltinConstant gl_MaxVaryingComponents syn keyword glslBuiltinConstant gl_MaxVaryingFloats syn keyword glslBuiltinConstant gl_MaxVaryingVectors @@ -382,6 +392,7 @@ syn keyword glslBuiltinVariable gl_FrontLightProduct syn keyword glslBuiltinVariable gl_FrontMaterial syn keyword glslBuiltinVariable gl_FrontSecondaryColor syn keyword glslBuiltinVariable gl_GlobalInvocationID +syn keyword glslBuiltinVariable gl_HelperInvocation syn keyword glslBuiltinVariable gl_InstanceID syn keyword glslBuiltinVariable gl_InvocationID syn keyword glslBuiltinVariable gl_Layer @@ -483,7 +494,11 @@ syn keyword glslBuiltinFunction cos syn keyword glslBuiltinFunction cosh syn keyword glslBuiltinFunction cross syn keyword glslBuiltinFunction dFdx +syn keyword glslBuiltinFunction dFdxCoarse +syn keyword glslBuiltinFunction dFdxFine syn keyword glslBuiltinFunction dFdy +syn keyword glslBuiltinFunction dFdyCoarse +syn keyword glslBuiltinFunction dFdyFine syn keyword glslBuiltinFunction degrees syn keyword glslBuiltinFunction determinant syn keyword glslBuiltinFunction distance @@ -502,6 +517,8 @@ syn keyword glslBuiltinFunction fract syn keyword glslBuiltinFunction frexp syn keyword glslBuiltinFunction ftransform syn keyword glslBuiltinFunction fwidth +syn keyword glslBuiltinFunction fwidthCoarse +syn keyword glslBuiltinFunction fwidthFine syn keyword glslBuiltinFunction greaterThan syn keyword glslBuiltinFunction greaterThanEqual syn keyword glslBuiltinFunction groupMemoryBarrier @@ -643,13 +660,15 @@ hi def link glslOctalInt glslInteger hi def link glslHexInt glslInteger hi def link glslInteger Number hi def link glslFloat Float +hi def link glslIdentifierPrime glslIdentifier +hi def link glslIdentifier Identifier hi def link glslStructure Structure hi def link glslType Type hi def link glslQualifier StorageClass hi def link glslBuiltinConstant Constant hi def link glslBuiltinFunction Function hi def link glslBuiltinVariable Identifier -hi def link glslSwizzle SpecialChar +hi def link glslSwizzle Identifier if !exists("b:current_syntax") let b:current_syntax = "glsl" diff --git a/syntax/go.vim b/syntax/go.vim index 3ea87319..69c2b011 100644 --- a/syntax/go.vim +++ b/syntax/go.vim @@ -5,36 +5,13 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1 " license that can be found in the LICENSE file. " " go.vim: Vim syntax file for Go. -" -" Options: -" There are some options for customizing the highlighting; the recommended -" settings are the default values, but you can write: -" let OPTION_NAME = 0 -" in your ~/.vimrc file to disable particular options. You can also write: -" let OPTION_NAME = 1 -" to enable particular options. At present, all options default to off: -" -" - go_highlight_array_whitespace_error -" Highlights white space after "[]". -" - go_highlight_chan_whitespace_error -" Highlights white space around the communications operator that don't follow -" the standard style. -" - go_highlight_extra_types -" Highlights commonly used library types (io.Reader, etc.). -" - go_highlight_space_tab_error -" Highlights instances of tabs following spaces. -" - go_highlight_trailing_whitespace_error -" Highlights trailing white space. -" - go_highlight_string_spellcheck -" Specifies that strings should be spell checked -" - go_highlight_format_strings -" Highlights printf-style operators inside string literals. " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") finish endif +" Set settings to default values. if !exists("g:go_highlight_array_whitespace_error") let g:go_highlight_array_whitespace_error = 0 endif @@ -91,12 +68,52 @@ if !exists("g:go_highlight_generate_tags") let g:go_highlight_generate_tags = 0 endif +if !exists("g:go_highlight_variable_assignments") + let g:go_highlight_variable_assignments = 0 +endif + +if !exists("g:go_highlight_variable_declarations") + let g:go_highlight_variable_declarations = 0 +endif + +let s:fold_block = 1 +let s:fold_import = 1 +let s:fold_varconst = 1 +let s:fold_package_comment = 1 +let s:fold_comment = 0 + +if exists("g:go_fold_enable") + " Enabled by default. + if index(g:go_fold_enable, 'block') == -1 + let s:fold_block = 0 + endif + if index(g:go_fold_enable, 'import') == -1 + let s:fold_import = 0 + endif + if index(g:go_fold_enable, 'varconst') == -1 + let s:fold_varconst = 0 + endif + if index(g:go_fold_enable, 'package_comment') == -1 + let s:fold_package_comment = 0 + endif + + " Disabled by default. + if index(g:go_fold_enable, 'comment') > -1 + let s:fold_comment = 1 + endif +endif + syn case match -syn keyword goDirective package import -syn keyword goDeclaration var const +syn keyword goPackage package +syn keyword goImport import contained +syn keyword goVar var contained +syn keyword goConst const contained -hi def link goDirective Statement +hi def link goPackage Statement +hi def link goImport Statement +hi def link goVar Keyword +hi def link goConst Keyword hi def link goDeclaration Keyword " Keywords within functions @@ -137,8 +154,14 @@ hi def link goPredefinedIdentifiers goBoolean " Comments; their contents syn keyword goTodo contained TODO FIXME XXX BUG syn cluster goCommentGroup contains=goTodo -syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell + syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell +if s:fold_comment + syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell fold + syn match goComment "\v(^\s*//.*\n)+" contains=goGenerate,@goCommentGroup,@Spell fold +else + syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell +endif hi def link goComment Comment hi def link goTodo Todo @@ -191,8 +214,35 @@ syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains= hi def link goCharacter Character " Regions -syn region goBlock start="{" end="}" transparent fold syn region goParen start='(' end=')' transparent +if s:fold_block + syn region goBlock start="{" end="}" transparent fold +else + syn region goBlock start="{" end="}" transparent +endif + +" import +if s:fold_import + syn region goImport start='import (' end=')' transparent fold contains=goImport,goString,goComment +else + syn region goImport start='import (' end=')' transparent contains=goImport,goString,goComment +endif + +" var, const +if s:fold_varconst + syn region goVar start='var (' end='^\s*)$' transparent fold + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + syn region goConst start='const (' end='^\s*)$' transparent fold + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar +else + syn region goVar start='var (' end='^\s*)$' transparent + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + syn region goConst start='const (' end='^\s*)$' transparent + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar +endif + +" Single-line var, const, and import. +syn match goSingleDecl /\(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst " Integers syn match goDecimalInt "\<-\=\d\+\%([Ee][-+]\=\d\+\)\=\>" @@ -323,10 +373,10 @@ hi def link goField Identifier " Structs & Interfaces; if g:go_highlight_types != 0 - syn match goTypeConstructor /\<\w\+{/he=e-1 + syn match goTypeConstructor /\<\w\+{\@=/ syn match goTypeDecl /\/ nextgroup=goTypeName skipwhite skipnl syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl - syn match goDeclType /\/ skipwhite skipnl + syn match goDeclType /\<\(interface\|struct\)\>/ skipwhite skipnl hi def link goReceiverType Type else syn keyword goDeclType struct interface @@ -337,6 +387,18 @@ hi def link goTypeName Type hi def link goTypeDecl Keyword hi def link goDeclType Keyword +" Variable Assignments +if g:go_highlight_variable_assignments != 0 + syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/ + hi def link goVarAssign Special +endif + +" Variable Declarations +if g:go_highlight_variable_declarations != 0 + syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/ + hi def link goVarDefs Special +endif + " Build Constraints if g:go_highlight_build_constraints != 0 syn match goBuildKeyword display contained "+build" @@ -358,15 +420,22 @@ if g:go_highlight_build_constraints != 0 hi def link goBuildCommentStart Comment hi def link goBuildDirectives Type hi def link goBuildKeyword PreProc +endif +if g:go_highlight_build_constraints != 0 || s:fold_package_comment " One or more line comments that are followed immediately by a "package" " declaration are treated like package documentation, so these must be " matched as comments to avoid looking like working build constraints. " The he, me, and re options let the "package" itself be highlighted by " the usual rules. - syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/ - \ end=/\v\n\s*package/he=e-7,me=e-7,re=e-7 - \ contains=@goCommentGroup,@Spell + exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/' + \ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7' + \ . ' contains=@goCommentGroup,@Spell' + \ . (s:fold_package_comment ? ' fold' : '') + exe 'syn region goPackageComment start=/\v\/\*.*\n(.*\n)*\s*\*\/\npackage/' + \ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7' + \ . ' contains=@goCommentGroup,@Spell' + \ . (s:fold_package_comment ? ' fold' : '') hi def link goPackageComment Comment endif diff --git a/syntax/graphql.vim b/syntax/graphql.vim index 71dc766a..8a7f07c5 100644 --- a/syntax/graphql.vim +++ b/syntax/graphql.vim @@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 " Language: GraphQL " Maintainer: Jon Parise -if exists("b:current_syntax") +if exists('b:current_syntax') finish endif @@ -20,9 +20,11 @@ syn keyword graphqlNull null syn match graphqlNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" syn region graphqlString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ +syn keyword graphqlKeyword on nextgroup=graphqlType skipwhite + syn keyword graphqlStructure enum scalar type union nextgroup=graphqlType skipwhite syn keyword graphqlStructure input interface subscription nextgroup=graphqlType skipwhite -syn keyword graphqlStructure implements on nextgroup=graphqlType skipwhite +syn keyword graphqlStructure implements nextgroup=graphqlType skipwhite syn keyword graphqlStructure query mutation fragment nextgroup=graphqlIdentifier skipwhite syn keyword graphqlStructure directive nextgroup=graphqlDirective skipwhite syn keyword graphqlStructure extend nextgroup=graphqlStructure skipwhite @@ -53,12 +55,13 @@ hi def link graphqlConstant Constant hi def link graphqlDirective PreProc hi def link graphqlIdentifier Identifier hi def link graphqlMetaFields Special +hi def link graphqlKeyword Keyword hi def link graphqlStructure Structure hi def link graphqlType Type hi def link graphqlVariable Identifier syn sync minlines=500 -let b:current_syntax = "graphql" +let b:current_syntax = 'graphql' endif diff --git a/syntax/haskell.vim b/syntax/haskell.vim index 1a26d1c0..bd5c02ce 100644 --- a/syntax/haskell.vim +++ b/syntax/haskell.vim @@ -20,14 +20,14 @@ endif syn spell notoplevel syn match haskellRecordField contained containedin=haskellBlock - \ "[_a-z][a-zA-Z0-9_']*\(,\s*[_a-z][a-zA-Z0-9_']*\)*\_s\+::\s" + \ "[_a-z][a-zA-Z0-9_']*\(,\s*[_a-z][a-zA-Z0-9_']*\)*\_s\+::\_s" \ contains= \ haskellIdentifier, \ haskellOperators, \ haskellSeparator, \ haskellParens syn match haskellTypeSig - \ "^\s*\(where\s\+\|let\s\+\|default\s\+\)\?[_a-z][a-zA-Z0-9_']*\(,\s*[_a-z][a-zA-Z0-9_']*\)*\_s\+::\s" + \ "^\s*\(where\s\+\|let\s\+\|default\s\+\)\?[_a-z][a-zA-Z0-9_']*#\?\(,\s*[_a-z][a-zA-Z0-9_']*#\?\)*\_s\+::\_s" \ contains= \ haskellWhere, \ haskellLet, diff --git a/syntax/html.vim b/syntax/html.vim index 9ae35217..e494e404 100644 --- a/syntax/html.vim +++ b/syntax/html.vim @@ -106,7 +106,7 @@ syn keyword htmlArg contained form autocomplete autofocus list min max step syn keyword htmlArg contained formaction autofocus formenctype formmethod formtarget formnovalidate syn keyword htmlArg contained required placeholder pattern " ,
,