summaryrefslogtreecommitdiffstats
path: root/indent/typescript.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2015-03-10 21:56:33 -0700
committerAdam Stankiewicz <sheerun@sher.pl>2015-03-10 21:56:33 -0700
commitacd7ce59503b22ac7663fc25776efe25e266f1d4 (patch)
tree0a7b4c05f478fa529ddf81a359528cddf70fb4ab /indent/typescript.vim
parentf24fecc338b5129a47c343f61daad2c2fe7a4ab0 (diff)
downloadvim-polyglot-1.13.1.tar.gz
vim-polyglot-1.13.1.zip
Updatev1.13.1
Diffstat (limited to 'indent/typescript.vim')
-rw-r--r--indent/typescript.vim79
1 files changed, 79 insertions, 0 deletions
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 `<variable> : <type>;`
+ " 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 `<variable> : {` 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