Skip to content

Develop -> Master #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
faf8bda
containing braces which aren't blocks
bounceme Aug 21, 2016
cd0fc28
comment fix
bounceme Aug 22, 2016
2e3ab0a
improve regex
bounceme Aug 22, 2016
fd6c2b7
Fix export default style indents
amadeus Aug 24, 2016
27ec99a
Merge pull request #614 from pangloss/fix-export-default-indent
bounceme Aug 25, 2016
af43741
regex update
bounceme Aug 25, 2016
f1bd983
allow nl in export default
bounceme Aug 25, 2016
aa5586c
small bugfixes
bounceme Aug 27, 2016
51035b5
react property expressions
bounceme Sep 1, 2016
941b389
Merge pull request #619 from pangloss/jsx
bounceme Sep 2, 2016
6aba384
adjustable indent (experimental)
bounceme Sep 2, 2016
d6616d5
Update javascript.vim
bounceme Sep 2, 2016
0bba857
bugfixes
bounceme Sep 3, 2016
f8a4a45
fixes for the bugfixes
bounceme Sep 3, 2016
174d94e
produce cindent-like
bounceme Sep 3, 2016
c9f6fad
performance refactor
bounceme Sep 3, 2016
0a3bb52
Update javascript.vim
bounceme Sep 3, 2016
cc9bd56
Update javascript.vim
bounceme Sep 3, 2016
2f5937e
deprecate options
bounceme Sep 3, 2016
8711b66
remove variables from readme
bounceme Sep 4, 2016
7e6d963
Merge pull request #621 from pangloss/adj
bounceme Sep 4, 2016
bf74844
fix cached blank line problem
bounceme Sep 4, 2016
0586678
far better version of last commit
bounceme Sep 4, 2016
22d0e64
more performance and bugfixes
bounceme Sep 4, 2016
023e1d8
other fixes with cache
bounceme Sep 4, 2016
5f7e36a
formatting,date
bounceme Sep 4, 2016
224fcee
small changes
bounceme Sep 4, 2016
c36a91b
fix
bounceme Sep 4, 2016
172aae6
cleaning
bounceme Sep 4, 2016
2dd5dff
cleaning
bounceme Sep 4, 2016
d51ef6a
small change
bounceme Sep 4, 2016
46b6dd5
allow blank line in adjustment calc
bounceme Sep 4, 2016
4d7a422
superfluous condition
bounceme Sep 4, 2016
39f09ee
simplify assignment
bounceme Sep 5, 2016
0134b36
little optimizations (#627)
bounceme Sep 8, 2016
e69cc16
no adjustment in block statements
bounceme Sep 8, 2016
a7e64a9
don't let variable in block
bounceme Sep 8, 2016
89b5505
Allow any comment or empty in adjustment
bounceme Sep 8, 2016
0ab4b1d
small fix
bounceme Sep 8, 2016
81d8502
refactor adjustment and simplify
bounceme Sep 8, 2016
b53274d
more small improvements
bounceme Sep 8, 2016
91314f3
fix objects after ternary ':'
bounceme Sep 9, 2016
fce8e77
fix blocks after case statement
bounceme Sep 9, 2016
5a5cdf0
remove 1 char
bounceme Sep 9, 2016
c15142c
allow bind op as line end continuation
bounceme Sep 9, 2016
81e4e6f
small script function changes (#628)
bounceme Sep 10, 2016
0b6aad4
speed increase attempt (#629)
bounceme Sep 11, 2016
14198ab
copy indent if in same scope only
bounceme Sep 13, 2016
faf6f67
remove indent copy
bounceme Sep 13, 2016
4e2e377
Add highlight group specifically for object colons
jfelchner Sep 12, 2016
355d665
Add individual syntax groups for various parenthesis
jfelchner Sep 13, 2016
615f837
Add more specialized groups for the various braces
jfelchner Sep 13, 2016
430b528
Removed 'contained' constraint from 'this' keyword highlight
jfelchner Sep 13, 2016
aa2fb90
Add section comments
jfelchner Sep 13, 2016
20bb09a
Fix decorator syntax highlighting
jfelchner Sep 13, 2016
801aad4
Change highlight link for decorators to 'Tag'
jfelchner Sep 13, 2016
6c78b77
Whitespace
jfelchner Sep 13, 2016
0cb2e11
Change ClassKeywords to Keywords instead of Define
jfelchner Sep 13, 2016
5c4de0c
slight changes to the skip_func (#632)
bounceme Sep 13, 2016
2bc4663
Merge pull request #631 from jfelchner/fix/syntax-highlighting-issues
amadeus Sep 14, 2016
d5dbecb
Group link fixes
amadeus Sep 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ variables:
## Indentation Specific

* `:h cino-:`
* End-of-line continuations : `g:javascript_continuation` ( slightly complicated, look at the source code )
* Start-of-line continuations : `g:javascript_opfirst` ( same as above )

## Contributing

Expand Down
70 changes: 40 additions & 30 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
" Language: Javascript
" Maintainer: vim-javascript community
" URL: https://github.com/pangloss/vim-javascript
" Last Change: August 20, 2016
" Last Change: September 4, 2016

" Only load this indent file when no other was loaded.
if exists('b:did_indent')
Expand Down Expand Up @@ -38,7 +38,7 @@ else
endif

let s:line_pre = '^\s*\%(\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=\)\@>'
let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:'
let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:\C'
" Regex of syntax group names that are or delimit string or are comments.
let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)'

Expand All @@ -47,13 +47,20 @@ let s:syng_comment = '\%(comment\|doc\)'

" Expression used to check whether we should skip a match with searchpair().
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
function s:skip_func(lnum)
if !s:free || getline(line('.')) =~ '[''/"\\]' || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum)
let s:free = !eval(s:skip_expr)
endif
let s:looksyn = s:free ? line('.') : s:looksyn
return !s:free
endfunction

if has('reltime')
function s:GetPair(start,end,flags,time)
return searchpair(a:start,'',a:end,a:flags,s:skip_expr,max([prevnonblank(v:lnum) - 2000,0]),a:time)
function s:GetPair(start,end,flags,skip,time)
return searchpair(a:start,'',a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0]),a:time)
endfunction
else
function s:GetPair(start,end,flags,n)
function s:GetPair(start,end,flags,...)
return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0]))
endfunction
endif
Expand All @@ -62,29 +69,28 @@ let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$'

" configurable regexes that define continuation lines, not including (, {, or [.
if !exists('g:javascript_opfirst')
let g:javascript_opfirst = '\%([<>,:?^%|*&]\|\([-/.+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)'
let g:javascript_opfirst = '\%([<>,?^%|*&]\|\/[^/*]\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)'
endif
if !exists('g:javascript_continuation')
let g:javascript_continuation = '\%([<=,.?/*:^%|&]\|+\@<!+\|-\@<!-\|=\@<!>\|\<in\%(stanceof\)\=\)'
let g:javascript_continuation = '\%([<=,.?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<in\%(stanceof\)\=\)'
endif

let g:javascript_opfirst = s:line_pre . g:javascript_opfirst
let g:javascript_continuation .= s:line_term

function s:OneScope(lnum,text,add)
function s:OneScope(lnum,text)
return a:text =~# '\%(\<else\|\<do\|=>\)' . s:line_term ? 'no b' :
\ ((a:add && a:text =~ s:line_pre . '$' && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) ||
\ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) &&
\ s:GetPair('(', ')', 'cbW', 100) > 0 && search('\C\l\+\_s*\%#','bW') &&
\ (a:add || ((expand('<cword>') !=# 'while' || !s:GetPair('\C\<do\>', '\C\<while\>','nbW',100)) &&
\ expand('cword') !=# 'each' || search('\C\<for\_s\+\%#','nbW'))) ? expand('<cword>') : ''
\ cursor(a:lnum, match(' ' . a:text, ')' . s:line_term)) > -1 &&
\ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && search('\C\l\+\_s*\%#','bW') &&
\ (expand('<cword>') !=# 'while' || s:GetPair('\C\<do\>', '\C\<while\>','nbW',s:skip_expr,100) <= 0) &&
\ (expand('<cword>') !=# 'each' || search('\C\<for\_s\+\%#','nbW')) ? expand('<cword>') : ''
endfunction

" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
function s:IsBlock()
return getline(line('.'))[col('.')-1] == '{' && !search(
\ '\C\%(\<return\s*\|\%([-=~!<*+,.?^%|&\[(]\|=\@<!>\|\*\@<!\/\|\<\%(var\|const\|let\|yield\|delete\|void\|t\%(ypeof\|hrow\)\|new\|\<in\%(stanceof\)\=\)\)\_s*\)\%#','bnW') &&
\ (!search(':\_s*\%#','bW') || (!s:GetPair('[({[]','[])}]','bW',200) || s:IsBlock()))
\ '\C\%(\<return\s*\|\%([-=~!<*+,.?^%|&\[(]\|=\@<!>\|\*\@<!\/\|\<\%(var\|const\|let\|import\|export\%(\_s\+default\)\=\|yield\|delete\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\)\_s*\)\%#','bnW') &&
\ (search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock())
endfunction

" Auxiliary Functions {{{2
Expand All @@ -109,9 +115,12 @@ function s:Balanced(lnum)
if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom
let idx = stridx('(){}[]', l:line[pos])
if idx % 2 == 0
let open_{idx} = open_{idx} + 1
let open_{idx} += 1
else
let open_{idx - 1} = open_{idx - 1} - 1
let open_{idx - 1} -= 1
if open_{idx - 1} < 0
return 0
endif
endif
endif
let pos = match(l:line, '[][(){}]', pos + 1)
Expand All @@ -129,7 +138,7 @@ function GetJavascriptIndent()
let syns = synIDattr(synID(v:lnum, 1, 0), 'name')

" start with strings,comments,etc.{{{2
if (l:line !~ '^[''"`]' && syns =~? '\%(string\|template\)') ||
if (l:line !~ '^[''"]' && syns =~? '\%(string\|template\)') ||
\ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment)
return -1
endif
Expand All @@ -152,36 +161,37 @@ function GetJavascriptIndent()

" the containing paren, bracket, curly. Memoize, last lineNr either has the
" same scope or starts a new one, unless if it closed a scope.
let [s:looksyn,s:free] = [v:lnum - 1,1]
call cursor(v:lnum,1)
if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && b:js_cache[0] &&
if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum &&
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0)
let num = b:js_cache[1]
elseif syns != '' && l:line[0] =~ '\s'
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
let num = s:GetPair(pattern[0],pattern[1],'bW',2000)
let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000)
else
let num = s:GetPair('[({[]','[])}]','bW',2000)
let num = s:GetPair('[({[]','[])}]','bW','s:skip_func(s:looksyn)',2000)
endif

let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]

if l:line =~ s:line_pre . '[])}]'
return indent(num)
endif

let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), '\%(:\@<!\/\/.*\)$', '','')
call cursor(b:js_cache[1],b:js_cache[2])

let swcase = getline(l:lnum) =~# s:expr_case
let pline = swcase ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@<!\/\/.*\)$', '','')
let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:IsBlock())
let switch_offset = num == 0 || s:OneScope(num, strpart(getline(num),0,b:js_cache[2] - 1),1) !=# 'switch' ? 0 :
\ &cino !~ ':' || !has('float') ? s:sw() :
let switch_offset = num <= 0 || !(search(')\_s*\%#','bW') &&
\ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && search('\C\<switch\_s*\%#','bW')) ? 0 :
\ &cino !~ ':' || !has('float') ? s:sw() :
\ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1))

" most significant, find the indent amount
if inb && !swcase && ((l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation) ||
\ num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' &&
\ l:line !~ s:line_pre . '{')
let isOp = l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation
if isOp && (num <= 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) ||
\ s:OneScope(l:lnum,pline) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' &&
\ l:line !~ s:line_pre . '{'
return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset
elseif num > 0
return indent(num) + s:sw() + switch_offset
Expand Down
Loading