diff --git a/README.md b/README.md index e4230c9..5ecfbb5 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ If you need full functionality of any plugin, please use it directly with your p - [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect) - [twig](https://github.com/lumiliet/vim-twig) (syntax, indent, ftplugin) - [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect) -- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect) +- [vala](https://github.com/arrufat/vala.vim) (syntax, indent, ftdetect) - [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax) - [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect) - [vue](https://github.com/posva/vim-vue) (syntax, indent, ftplugin, ftdetect) diff --git a/build b/build index be83c16..a5504ef 100755 --- a/build +++ b/build @@ -187,7 +187,7 @@ PACKS=" toml:cespare/vim-toml twig:lumiliet/vim-twig typescript:leafgarland/typescript-vim - vala:tkztmk/vim-vala + vala:arrufat/vala.vim vbnet:vim-scripts/vbnet.vim vcl:smerrill/vcl-vim-plugin vue:posva/vim-vue diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index f431def..ea6e0fb 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -981,8 +981,7 @@ endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vala') == -1 autocmd BufRead *.vala,*.vapi set efm=%f:%l.%c-%[%^:]%#:\ %t%[%^:]%#:\ %m -au BufRead,BufNewFile *.vala,*.vapi setfiletype vala - +au BufRead,BufNewFile *.vala,*.vapi,*.valadoc setfiletype vala endif diff --git a/indent/vala.vim b/indent/vala.vim index 42babfb..c24adf0 100644 --- a/indent/vala.vim +++ b/indent/vala.vim @@ -1,36 +1,87 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vala') == -1 -" Copyright (c) 2012 Takezoe Tomoaki -" -" Permission is hereby granted, free of charge, to any person obtaining a copy -" of -" this software and associated documentation files (the "Software"), to deal in -" the Software without restriction, including without limitation the rights to -" use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -" of -" the Software, and to permit persons to whom the Software is furnished to do -" so, -" subject to the following conditions: -" -" The above copyright notice and this permission notice shall be included in all -" copies or substantial portions of the Software. -" -" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -" FITNESS -" FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -" COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -" IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -" CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +" Vim indent file +" Language: Vala +" Author: AdriĆ  Arrufat +" Last Change: 2016 Dec 04 -" Vim indent file for Vala. -" It just sets cindent for Vala files... +" Only load this indent file when no other was loaded. if exists("b:did_indent") finish endif let b:did_indent = 1 -setl cin -let b:undo_indent = "setl cin<" +setlocal cindent +setlocal cinoptions=L0,(0,Ws,J1,j1 +setlocal cinkeys=0{,0},!^F,o,O,0[,0] + +" Some preliminary settings +setlocal nolisp " Make sure lisp indenting doesn't supersede us +setlocal autoindent " indentexpr isn't much help otherwise + +setlocal indentexpr=GetValaIndent(v:lnum) + +" Only define the function once. +if exists("*GetValaIndent") + finish +endif + +" Come here when loading the script the first time. + +function GetValaIndent(lnum) + + " Hit the start of the file, use zero indent. + if a:lnum == 0 + return 0 + endif + + " Starting assumption: cindent (called at the end) will do it right + " normally. We just want to fix up a few cases. + + let line = getline(a:lnum) + " Search backwards for the previous non-empty line. + let prevlinenum = prevnonblank(a:lnum - 1) + let prevline = getline(prevlinenum) + while prevlinenum > 1 && prevline !~ '[^[:blank:]]' + let prevlinenum = prevnonblank(prevlinenum - 1) + let prevline = s:getline(prevlinenum) + endwhile + + " If previous line contains a code attribute (e.g. [CCode (...)]) + " don't increase the indentation + if prevline =~? '^\s*\[[A-Za-z]' && prevline =~? '\]$' + return indent(prevlinenum) + endif + + " cindent gets lambda body wrong, as it treats the comma as indicating an + " unfinished statement (fix borrowed from rust.vim indent file): + " + " list.foreach ((entry) => { + " stdout.puts (entry); + " stdout.putc ('\n'); + " if (entry == null) { + " print ("empty entry\n"); + " } + " }); + " + " and we want it to be: + " list.foreach ((entry) => { + " stdout.puts (entry); + " stdout.putc ('\n'); + " if (entry == null) { + " print ("empty entry\n"); + " } + " }); + + if prevline[len(prevline) - 1] == "," + \ && line !~ '^\s*[\[\]{}]' + \ && prevline !~ '([^()]\+,$' + \ && line !~ '^\s*\S\+\s*=>' + return indent(prevlinenum) + endif + + " Fall back on cindent, which does it mostly right + return cindent(a:lnum) +endfunction endif diff --git a/syntax/vala.vim b/syntax/vala.vim index 9583648..52359f8 100644 --- a/syntax/vala.vim +++ b/syntax/vala.vim @@ -6,8 +6,9 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vala') == -1 " Hans Vercammen " pancake " Sebastian Reichel -" Last Change: 2012-02-19 -" Filenames: *.vala *.vapi +" AdriĆ  Arrufat +" Last Change: 2016-10-20 +" Filenames: *.vala *.vapi *.valadoc " " REFERENCES: " [1] http://live.gnome.org/Vala @@ -17,7 +18,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vala') == -1 " - better error checking for known errors " - full support for valadoc " -" add vala in /usr/share/vim/vim73/scripts.vim below ruby +" add vala in /usr/share/vim/vim80/scripts.vim below ruby " to have shebang support if exists("b:current_syntax") @@ -30,7 +31,7 @@ set cpo&vim " Types syn keyword valaType bool char double float size_t ssize_t string unichar void syn keyword valaType int int8 int16 int32 int64 long short -syn keyword valaType uint uint8 uint16 uint32 uint64 ulong ushort +syn keyword valaType uchar uint uint8 uint16 uint32 uint64 ulong ushort " Storage keywords syn keyword valaStorage class delegate enum errordomain interface namespace struct " repeat / condition / label @@ -49,19 +50,26 @@ syn keyword valaConstant false null true syn keyword valaException try catch finally throw " Unspecified Statements syn keyword valaUnspecifiedStatement as base construct delete get in is lock new out params ref sizeof set this throws typeof using value var yield +" Arrays and Lists +syn match valaArray "\(\w\(\w\)*\(\s\+\)\?<\)\+\(\(\s\+\)\?\w\(\w\)*\(?\|\*\)\?\(\,\)\?\)\+>\+" +" Methods +syn match valaMethod "\w\(\w\)*\(\s\+\)\?("he=e-1,me=e-1 +" Operators +syn match valaOperator display "\%(+\|-\|/\|*\|=\|\^\|&\||\|!\|>\|<\|%\|?\)=\?" +" Delimiters +syn match valaDelimiter display "(\|)\|\[\|\]\|,\|;\|:\|{\|}\|\k\@" + syn match valaDocTags contained "@\(return\|deprecated\)\>" syn region valaDocSeeTag contained matchgroup=valaDocTags start="@see\s\+" matchgroup=NONE end="\_."re=e-1 contains=valaDocSeeTagParam syn match valaDocSeeTagParam contained @"\_[^"]\+"\|\|\(\k\|\.\)*\(#\k\+\((\_[^)]\+)\)\=\)\=@ extend endif @@ -80,9 +88,9 @@ if exists("vala_comment_strings") endif else syn region valaCommentL start="//" end="$" keepend contains=@valaCommentGroup,valaSpaceError,@Spell - syn region valaComment matchgroup=valaCommentStart start="/\*" end="\*/" contains=@valaCommentGroup,valaCommentStartError,valaSpaceError,@Spell + syn region valaComment matchgroup=valaCommentStart start="/\*" end="\*/" fold contains=@valaCommentGroup,valaCommentStartError,valaSpaceError,@Spell if !exists("vala_ignore_valadoc") - syn region valaDocComment matchgroup=valaCommentStart start="/\*\*" end="\*/" keepend contains=@valaCommentGroup,@valaDocCommentGroup,valaCommentStartError,valaSpaceError,@Spell + syn region valaDocComment matchgroup=valaCommentStart start="/\*\*" end="\*/" fold keepend contains=@valaCommentGroup,@valaDocCommentGroup,valaCommentStartError,valaSpaceError,@Spell endif endif @@ -103,7 +111,7 @@ syntax match valaCommentStartError display "/\*"me=e-1 contained syn match valaComment "/\*\*/" " Vala Code Attributes -syn region valaAttribute start="^\s*\[" end="\]$" contains=valaComment,valaString keepend +syn region valaAttribute start="^\s*\[" end="\]" contains=valaComment,valaString keepend syn region valaAttribute start="\[CCode" end="\]" contains=valaComment,valaString " Avoid escaped keyword matching @@ -113,8 +121,12 @@ syn match valaUserContent display "@\I*" syn match valaSpecialError contained "\\." syn match valaSpecialCharError contained "[^']" syn match valaSpecialChar contained +\\["\\'0abfnrtvx]+ -syn region valaString start=+"+ end=+"+ end=+$+ contains=valaSpecialChar,valaSpecialError,valaUnicodeNumber,@Spell -syn region valaVerbatimString start=+"""+ end=+"""+ contains=@Spell +syn match valaFormatChar contained +%\(%\|\([-]\)\?\([+]\)\?\([0-9]\+\)\?\(\.\)\?\([0-9]\+\)\?\(l\?[dfiu]\|ll\?[diu]\|c\|g\|hh\?[iu]\|s\)\)+ +syn match valaTemplateVariable contained +\($\w\(\w\)*\)+ +syn region valaTemplateExpression start=+$(+ end=")" +syn region valaString start=+"+ end=+"+ end=+$+ contains=valaSpecialChar,valaSpecialError,valaUnicodeNumber,@Spell,valaFormatChar +syn region valaTemplateString start=+@"+ end=+"+ end=+$+ contains=valaSpecialChar,valaSpecialError,valaUnicodeNumber,@Spell,valaFormatChar,valaTemplateVariable,valaTemplateExpression +syn region valaVerbatimString start=+"""+ end=+"""+ contains=@Spell,valaFormatChar syn match valaUnicodeNumber +\\\(u\x\{4}\|U\x\{8}\)+ contained contains=valaUnicodeSpecifier syn match valaUnicodeSpecifier +\\[uU]+ contained syn match valaCharacter "'[^']*'" contains=valaSpecialChar,valaSpecialCharError @@ -144,6 +156,7 @@ endif exec "syn sync ccomment valaComment minlines=" . b:vala_minlines " code folding +set foldmethod=syntax syn region valaBlock start="{" end="}" transparent fold " The default highlighting. @@ -158,6 +171,10 @@ hi def link valaException Exception hi def link valaUnspecifiedStatement Statement hi def link valaUnspecifiedKeyword Keyword hi def link valaContextualStatement Statement +hi def link valaArray StorageClass +hi def link valaMethod Function +hi def link valaOperator Operator +hi def link valaDelimiter Delimiter hi def link valaCommentError Error hi def link valaCommentStartError Error @@ -179,9 +196,13 @@ hi def link valaAttribute PreCondit hi def link valaCommentString valaString hi def link valaComment2String valaString hi def link valaString String +hi def link valaTemplateString String hi def link valaVerbatimString String hi def link valaCharacter Character hi def link valaSpecialChar SpecialChar +hi def link valaFormatChar SpecialChar +hi def link valaTemplateVariable SpecialChar +hi def link valaTemplateExpression SpecialChar hi def link valaNumber Number hi def link valaUnicodeNumber SpecialChar hi def link valaUnicodeSpecifier SpecialChar