From acd7ce59503b22ac7663fc25776efe25e266f1d4 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 10 Mar 2015 21:56:33 -0700 Subject: Update --- ftdetect/polyglot.vim | 1 + ftplugin/scala/tagbar.vim | 34 +++++-------------- ftplugin/typescript.vim | 17 ++++++++++ indent/typescript.vim | 79 +++++++++++++++++++++++++++++++++++++++++++ syntax/typescript.vim | 86 ++++++++++++++++++++++++----------------------- 5 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 indent/typescript.vim diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index cb0d263d..3cec93cf 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -197,6 +197,7 @@ au BufNewFile,BufRead *.timer set filetype=systemd au BufRead,BufNewFile *.textile set filetype=textile au BufNewFile,BufRead *.thrift setlocal filetype=thrift autocmd BufNewFile,BufRead {.,}tmux.conf{.*,} setlocal filetype=tmux +autocmd BufNewFile,BufRead {.,}tmux.conf{.*,} setlocal commentstring=#\ %s autocmd BufNewFile,BufRead *.toml set filetype=toml autocmd BufNewFile,BufRead Cargo.lock set filetype=toml autocmd BufNewFile,BufRead *.twig set filetype=twig diff --git a/ftplugin/scala/tagbar.vim b/ftplugin/scala/tagbar.vim index 19353ef1..5e1f2af6 100644 --- a/ftplugin/scala/tagbar.vim +++ b/ftplugin/scala/tagbar.vim @@ -10,35 +10,19 @@ endif let g:tagbar_type_scala = { \ 'ctagstype' : 'scala', + \ 'sro' : '.', \ 'kinds' : [ - \ 'p:packages:1', - \ 'V:values', - \ 'v:variables', - \ 'T:types', + \ 'p:packages', + \ 'T:types:1', \ 't:traits', \ 'o:objects', - \ 'a:aclasses', + \ 'O:case objects', \ 'c:classes', - \ 'r:cclasses', - \ 'm:methods' - \ ], - \ 'sro' : '.', - \ 'kind2scope' : { - \ 'T' : 'type', - \ 't' : 'trait', - \ 'o' : 'object', - \ 'a' : 'abstract class', - \ 'c' : 'class', - \ 'r' : 'case class' - \ }, - \ 'scope2kind' : { - \ 'type' : 'T', - \ 'trait' : 't', - \ 'object' : 'o', - \ 'abstract class' : 'a', - \ 'class' : 'c', - \ 'case class' : 'r' - \ } + \ 'C:case classes', + \ 'm:methods', + \ 'V:values:1', + \ 'v:variables:1' + \ ] \ } " In case you've updated/customized your ~/.ctags and prefer to use it. diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index 9e98e790..ed1b8aae 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -1,2 +1,19 @@ +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpo +set cpo-=C + compiler typescript setlocal commentstring=//\ %s + +" Set 'formatoptions' to break comment lines but not other lines, +" " and insert the comment leader when hitting or using "o". +setlocal formatoptions-=t formatoptions+=croql + +let b:undo_ftplugin = "setl fo< ofu< com< cms<" + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/indent/typescript.vim b/indent/typescript.vim new file mode 100644 index 00000000..f498298b --- /dev/null +++ b/indent/typescript.vim @@ -0,0 +1,79 @@ +" Vim indent file, taken from indent/java.vim +" Language: Typescript +" Maintainer: None! Wanna improve this? +" Last Change: 2015 Mar 07 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" Use javascript cindent options +setlocal cindent cinoptions& cinoptions+=j1,J1 +setlocal indentkeys& + +" Load typescript indent function +setlocal indentexpr=GetTypescriptIndent() + +let b:undo_indent = "setl cin< cino< indentkeys< indentexpr<" + +" Only define the function once +if exists("*GetTypescriptIndent") + finish +endif + +" Make sure we have vim capabilities +let s:keepcpo = &cpo +set cpo&vim + +function! TypescriptPrevNonBlankOrComment(lnum) + let pnum = prevnonblank(a:lnum) + " skip any comments (either `//`, `/*` or `*`) + while getline(pnum) =~ '^\s*\(\/\/\|\/\*\|\*\)' + let pnum = prevnonblank(pnum-1) + endwhile + return pnum +endfunction + +function GetTypescriptIndent() + + " default value: trust cindent + let ind = cindent(v:lnum) + + if getline(v:lnum) =~ '^\s*[{}\*]' + return ind + endif + + " The last non-empty line + let prev = TypescriptPrevNonBlankOrComment(v:lnum-1) + + " Check if the previous line consists of a single ` : ;` + " declaration (e.g. in interface definitions) + if getline(prev) =~ '^\s*\w\+\s*:[^{]\+;\s*$' + return indent(prev) + endif + + " Try to find out whether the last `}` ended a ` : {` block + if getline(prev) =~ '};\s*$' + " jump to matching `{` bracket + call cursor(prev, 1) + silent normal % + + " See if current line is type annotation without closing ';' but open + " `{` bracket + let lnum = line('.') + if getline(lnum) =~ '^\s*\w\+\s*:[^;]\+{' + let ind = indent(lnum) + endif + endif + + return ind + +endfunction + +" Restore compatibility mode +let &cpo = s:keepcpo +unlet s:keepcpo + +" vim: et diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 9d48d480..79a11974 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -57,8 +57,8 @@ syntax case match "" Syntax in the typeScript code"{{{ syn match typeScriptSpecial "\\\d\d\d\|\\." -syn region typeScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=typeScriptSpecial,@htmlPreproc -syn region typeScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=typeScriptSpecial,@htmlPreproc +syn region typeScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=typeScriptSpecial,@htmlPreproc +syn region typeScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=typeScriptSpecial,@htmlPreproc syn match typeScriptSpecialCharacter "'\\.'" syn match typeScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" @@ -72,28 +72,28 @@ syntax match typeScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\ " syntax match typeScriptLabel /\(?\s*\)\@\|>=\|<=\|++\|+=\|--\|-=" +syn match typeScriptBraces "[{}\[\]]" +syn match typeScriptParens "[()]" +syn match typeScriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=" syn match typeScriptEndColons "[;,]" syn match typeScriptLogicSymbols "\(&&\)\|\(||\)" @@ -204,7 +205,7 @@ syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend setl foldtext=FoldText() endfunction -au FileType typeScript call TypeScriptFold() +au FileType typescript call TypeScriptFold() " }}} @@ -250,7 +251,7 @@ if version >= 508 || !exists("did_typeScript_syn_inits") HiLink typeScriptIdentifier Identifier HiLink typeScriptRepeat Repeat HiLink typeScriptStatement Statement - HiLink typeScriptFuncKeyword Type + HiLink typeScriptFuncKeyword Function HiLink typeScriptMessage Keyword HiLink typeScriptDeprecated Exception HiLink typeScriptError Error @@ -280,28 +281,29 @@ if version >= 508 || !exists("did_typeScript_syn_inits") HiLink typeScriptHtmlElemFuncs PreProc HiLink typeScriptCssStyles Label -" Ajax Highlighting -HiLink typeScriptBrowserObjects Constant -HiLink typeScriptDOMObjects Constant -HiLink typeScriptDOMMethods Exception -HiLink typeScriptDOMProperties Type + " Ajax Highlighting + HiLink typeScriptBrowserObjects Constant -HiLink typeScriptAjaxObjects htmlH1 -HiLink typeScriptAjaxMethods Exception -HiLink typeScriptAjaxProperties Type + HiLink typeScriptDOMObjects Constant + HiLink typeScriptDOMMethods Function + HiLink typeScriptDOMProperties Special -HiLink typeScriptFuncDef Title - HiLink typeScriptFuncArg Special - HiLink typeScriptFuncComma Operator + HiLink typeScriptAjaxObjects Constant + HiLink typeScriptAjaxMethods Function + HiLink typeScriptAjaxProperties Special -HiLink typeScriptHtmlEvents Special -HiLink typeScriptHtmlElemProperties Type + HiLink typeScriptFuncDef Title + HiLink typeScriptFuncArg Special + HiLink typeScriptFuncComma Operator -HiLink typeScriptEventListenerKeywords Keyword + HiLink typeScriptHtmlEvents Special + HiLink typeScriptHtmlElemProperties Special -HiLink typeScriptNumber Number -HiLink typeScriptPropietaryObjects Constant + HiLink typeScriptEventListenerKeywords Keyword + + HiLink typeScriptNumber Number + HiLink typeScriptPropietaryObjects Constant delcommand HiLink endif @@ -312,8 +314,8 @@ endif syntax cluster htmltypeScript contains=@typeScriptAll,typeScriptBracket,typeScriptParen,typeScriptBlock,typeScriptParenError syntax cluster typeScriptExpression contains=@typeScriptAll,typeScriptBracket,typeScriptParen,typeScriptBlock,typeScriptParenError,@htmlPreproc -let b:current_syntax = "typeScript" -if main_syntax == 'typeScript' +let b:current_syntax = "typescript" +if main_syntax == 'typescript' unlet main_syntax endif -- cgit v1.2.3