Mercurial > vim
annotate runtime/indent/typescript.vim @ 17676:14ac8c31e598 v8.1.1835
patch 8.1.1835: cannot use printf() as a method
commit https://github.com/vim/vim/commit/fd8ca21b3ff207e44891aef922935d4adcd140cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 10 00:13:30 2019 +0200
patch 8.1.1835: cannot use printf() as a method
Problem: Cannot use printf() as a method.
Solution: Pass the base as the second argument to printf().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Aug 2019 00:15:05 +0200 |
parents | e18b1c654d09 |
children | 6d11fc4aa683 |
rev | line source |
---|---|
16971
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Vim indent file |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 " Language: TypeScript |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 " Maintainer: See https://github.com/HerringtonDarkholme/yats.vim |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 " Last Change: 2019 Jun 06 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 " 0. Initialization {{{1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 " ================= |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 " Only load this indent file when no other was loaded. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 if exists("b:did_indent") |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 finish |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 let b:did_indent = 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 setlocal nosmartindent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 " Now, set up our indentation expression and keys that trigger it. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 setlocal indentexpr=GetTypescriptIndent() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 setlocal formatexpr=Fixedgq(v:lnum,v:count) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 " Only define the function once. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 if exists("*GetTypescriptIndent") |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 finish |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 let s:cpo_save = &cpo |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 set cpo&vim |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 " 1. Variables {{{1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 " ============ |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 let s:js_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 " Regex of syntax group names that are or delimit string or are comments. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 let s:syng_strcom = 'string\|regex\|comment\c' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 " Regex of syntax group names that are strings. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 let s:syng_string = 'regex\c' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 " Regex of syntax group names that are strings or documentation. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 let s:syng_multiline = 'comment\c' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 " Regex of syntax group names that are line comment. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 let s:syng_linecom = 'linecomment\c' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 " Expression used to check whether we should skip a match with searchpair(). |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 let s:line_term = '\s*\%(\%(\/\/\).*\)\=$' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 " Regex that defines continuation lines, not including (, {, or [. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 " Regex that defines continuation lines. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 " TODO: this needs to deal with if ...: and so on |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 let s:msl_regex = s:continuation_regex |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 " Regex that defines blocks. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 let s:var_stmt = '^\s*var' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 let s:comma_first = '^\s*,' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 let s:comma_last = ',\s*$' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 let s:ternary = '^\s\+[?|:]' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 let s:ternary_q = '^\s\+?' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 " 2. Auxiliary Functions {{{1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 " ====================== |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 " Check if the character at lnum:col is inside a string, comment, or is ascii. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 function s:IsInStringOrComment(lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 " Check if the character at lnum:col is inside a string. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 function s:IsInString(lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 " Check if the character at lnum:col is inside a multi-line comment. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 function s:IsInMultilineComment(lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 " Check if the character at lnum:col is a line comment. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 function s:IsLineComment(lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 " Find line above 'lnum' that isn't empty, in a comment, or in a string. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 function s:PrevNonBlankNonString(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 let in_block = 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 let lnum = prevnonblank(a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 while lnum > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 " Go in and out of blocks comments as necessary. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 " If the line isn't empty (with opt. comment) or in a string, end search. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 let line = getline(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 if line =~ '/\*' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 if in_block |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 let in_block = 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 break |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 elseif !in_block && line =~ '\*/' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 let in_block = 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line))) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 break |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 let lnum = prevnonblank(lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 return lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 " Find line above 'lnum' that started the continuation 'lnum' may be part of. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 function s:GetMSL(lnum, in_one_line_scope) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 " Start on the line we're at and use its indent. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 let msl = a:lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 let lnum = s:PrevNonBlankNonString(a:lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 while lnum > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 " If we have a continuation line, or we're in a string, use line as MSL. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 " Otherwise, terminate search as we have found our MSL already. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 let line = getline(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 let col = match(line, s:msl_regex) + 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 let msl = lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 " Don't use lines that are part of a one line scope as msl unless the |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 " flag in_one_line_scope is set to 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 " |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 if a:in_one_line_scope |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 break |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 end |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 let msl_one_line = s:Match(lnum, s:one_line_scope_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 if msl_one_line == 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 break |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 let lnum = s:PrevNonBlankNonString(lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 return msl |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 function s:RemoveTrailingComments(content) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 let single = '\/\/\(.*\)\s*$' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 let multi = '\/\*\(.*\)\*\/\s*$' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 return substitute(substitute(a:content, single, '', ''), multi, '', '') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 " Find if the string is inside var statement (but not the first string) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 function s:InMultiVarStatement(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 let lnum = s:PrevNonBlankNonString(a:lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 " let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 " loop through previous expressions to find a var statement |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 while lnum > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 let line = getline(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 " if the line is a js keyword |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 if (line =~ s:js_keywords) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 " check if the line is a var stmt |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 " if the line has a comma first or comma last then we can assume that we |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 " are in a multiple var statement |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 if (line =~ s:var_stmt) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 return lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 " other js keywords, not a var |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 let lnum = s:PrevNonBlankNonString(lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 " beginning of program, not a var |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 " Find line above with beginning of the var statement or returns 0 if it's not |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 " this statement |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 function s:GetVarIndent(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 let lvar = s:InMultiVarStatement(a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 if lvar |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 let line = s:RemoveTrailingComments(getline(prev_lnum)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 " if the previous line doesn't end in a comma, return to regular indent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 if (line !~ s:comma_last) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 return indent(prev_lnum) - shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 return indent(lvar) + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 return -1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 " Check if line 'lnum' has more opening brackets than closing ones. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 function s:LineHasOpeningBrackets(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 let open_0 = 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 let open_2 = 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 let open_4 = 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 let line = getline(a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 let pos = match(line, '[][(){}]', 0) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 while pos != -1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 if !s:IsInStringOrComment(a:lnum, pos + 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 let idx = stridx('(){}[]', line[pos]) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 if idx % 2 == 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 let open_{idx} = open_{idx} + 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 let open_{idx - 1} = open_{idx - 1} - 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 let pos = match(line, '[][(){}]', pos + 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 function s:Match(lnum, regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 let col = match(getline(a:lnum), a:regex) + 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 function s:IndentWithContinuation(lnum, ind, width) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 " Set up variables to use and search for MSL to the previous line. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 let p_lnum = a:lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 let lnum = s:GetMSL(a:lnum, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 let line = getline(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 " If the previous line wasn't a MSL and is continuation return its indent. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 " TODO: the || s:IsInString() thing worries me a bit. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 if p_lnum != lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 return a:ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 " Set up more variables now that we know we aren't continuation bound. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 let msl_ind = indent(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 " If the previous line ended with [*+/.-=], start a continuation that |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 " indents an extra level. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 if s:Match(lnum, s:continuation_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 if lnum == p_lnum |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 return msl_ind + a:width |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 return msl_ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 return a:ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 function s:InOneLineScope(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 let msl = s:GetMSL(a:lnum, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 if msl > 0 && s:Match(msl, s:one_line_scope_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 return msl |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 function s:ExitingOneLineScope(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 let msl = s:GetMSL(a:lnum, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 if msl > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 " if the current line is in a one line scope .. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 if s:Match(msl, s:one_line_scope_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 let prev_msl = s:GetMSL(msl - 1, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 if s:Match(prev_msl, s:one_line_scope_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 return prev_msl |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 " 3. GetTypescriptIndent Function {{{1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 " ========================= |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 function GetTypescriptIndent() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 " 3.1. Setup {{{2 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 " ---------- |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 " Set up variables for restoring position in file. Could use v:lnum here. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 let vcol = col('.') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 " 3.2. Work on the current line {{{2 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 " ----------------------------- |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 let ind = -1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 " Get the current line. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 let line = getline(v:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 " previous nonblank line number |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 let prevline = prevnonblank(v:lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 " If we got a closing bracket on an empty line, find its match and indent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 " according to it. For parentheses we indent to its column - 1, for the |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 " others we indent to the containing line's MSL's level. Return -1 if fail. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 let col = matchend(line, '^\s*[],})]') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 if col > 0 && !s:IsInStringOrComment(v:lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 call cursor(v:lnum, col) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 let lvar = s:InMultiVarStatement(v:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 if lvar |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 let prevline_contents = s:RemoveTrailingComments(getline(prevline)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 " check for comma first |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 if (line[col - 1] =~ ',') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 " if the previous line ends in comma or semicolon don't indent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 if (prevline_contents =~ '[;,]\s*$') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 return indent(s:GetMSL(line('.'), 0)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 " get previous line indent, if it's comma first return prevline indent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 elseif (prevline_contents =~ s:comma_first) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 return indent(prevline) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 " otherwise we indent 1 level |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 return indent(lvar) + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 if line[col-1]==')' && col('.') != col('$') - 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 let ind = virtcol('.')-1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 let ind = indent(s:GetMSL(line('.'), 0)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 return ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 " If the line is comma first, dedent 1 level |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 if (getline(prevline) =~ s:comma_first) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 return indent(prevline) - shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 if (line =~ s:ternary) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 if (getline(prevline) =~ s:ternary_q) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 return indent(prevline) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 return indent(prevline) + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 " If we are in a multi-line comment, cindent does the right thing. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 return cindent(v:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 " Check for multiple var assignments |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 " let var_indent = s:GetVarIndent(v:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 " if var_indent >= 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 " return var_indent |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 " endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 " 3.3. Work on the previous line. {{{2 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 " ------------------------------- |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 " If the line is empty and the previous nonblank line was a multi-line |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 " comment, use that comment's indent. Deduct one char to account for the |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 " space in ' */'. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 return indent(prevline) - 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 " Find a non-blank, non-multi-line string line above the current line. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 let lnum = s:PrevNonBlankNonString(v:lnum - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 " If the line is empty and inside a string, use the previous line. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 if line =~ '^\s*$' && lnum != prevline |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 return indent(prevnonblank(v:lnum)) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 " At the start of the file use zero indent. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 if lnum == 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 " Set up variables for current line. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 let line = getline(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 let ind = indent(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 " If the previous line ended with a block opening, add a level of indent. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 if s:Match(lnum, s:block_regex) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 return indent(s:GetMSL(lnum, 0)) + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 " If the previous line contained an opening bracket, and we are still in it, |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 " add indent depending on the bracket type. |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 if line =~ '[[({]' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 let counts = s:LineHasOpeningBrackets(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 if col('.') + 1 == col('$') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 return ind + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 return virtcol('.') |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 elseif counts[1] == '1' || counts[2] == '1' |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 return ind + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 call cursor(v:lnum, vcol) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 end |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 " 3.4. Work on the MSL line. {{{2 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 " -------------------------- |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 let ind_con = ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 let ind = s:IndentWithContinuation(lnum, ind_con, shiftwidth()) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 " }}}2 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 " |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 " |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 let ols = s:InOneLineScope(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 if ols > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 let ind = ind + shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 let ols = s:ExitingOneLineScope(lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 while ols > 0 && ind > 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 let ind = ind - shiftwidth() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 let ols = s:InOneLineScope(ols - 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 return ind |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 endfunction |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 " }}}1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 let &cpo = s:cpo_save |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 unlet s:cpo_save |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 function! Fixedgq(lnum, count) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 let l:tw = &tw ? &tw : 80; |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 let l:count = a:count |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 let l:first_char = indent(a:lnum) + 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 if mode() == 'i' " gq was not pressed, but tw was set |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 return 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 " This gq is only meant to do code with strings, not comments |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 if s:IsLineComment(a:lnum, l:first_char) || s:IsInMultilineComment(a:lnum, l:first_char) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 return 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 return 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 " Put all the lines on one line and do normal spliting after that |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 if l:count > 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 while l:count > 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 let l:count -= 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 normal J |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 endwhile |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 let l:winview = winsaveview() |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 call cursor(a:lnum, l:tw + 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 call cursor(a:lnum, l:tw + 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 " No need for special treatment, normal gq handles edgecases better |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 if breakpoint[1] == orig_breakpoint[1] |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 call winrestview(l:winview) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 return 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 " Try breaking after string |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 if breakpoint[1] <= indent(a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 call cursor(a:lnum, l:tw + 1) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum) |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 if breakpoint[1] != 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 call feedkeys("r\<CR>") |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 else |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 let l:count = l:count - 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 " run gq on new lines |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 if l:count == 1 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 call feedkeys("gqq") |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 endif |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 return 0 |
e18b1c654d09
Update runtime files - Add typescript syntax and indent.
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 endfunction |