Skip to content

Commit 1833982

Browse files
committed
Merge pull request #361 from pangloss/develop
Update Master
2 parents 1d8c267 + 2d11ec0 commit 1833982

File tree

3 files changed

+85
-54
lines changed

3 files changed

+85
-54
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ Default Value: 0
6666
You can customize concealing characters by defining one or more of the following
6767
variables:
6868

69-
let g:javascript_conceal_function = "ƒ"
70-
let g:javascript_conceal_null = "ø"
71-
let g:javascript_conceal_this = "@"
72-
let g:javascript_conceal_return = "⇚"
73-
let g:javascript_conceal_undefined = "¿"
74-
let g:javascript_conceal_NaN = "ℕ"
75-
let g:javascript_conceal_prototype = "¶"
76-
let g:javascript_conceal_static = "•"
77-
let g:javascript_conceal_super = "Ω"
69+
let g:javascript_conceal_function = "ƒ"
70+
let g:javascript_conceal_null = "ø"
71+
let g:javascript_conceal_this = "@"
72+
let g:javascript_conceal_return = "⇚"
73+
let g:javascript_conceal_undefined = "¿"
74+
let g:javascript_conceal_NaN = "ℕ"
75+
let g:javascript_conceal_prototype = "¶"
76+
let g:javascript_conceal_static = "•"
77+
let g:javascript_conceal_super = "Ω"
78+
let g:javascript_conceal_arrow_function = "⇒"
7879

7980
## Contributing
8081

indent/javascript.vim

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ endif
2626
let s:cpo_save = &cpo
2727
set cpo&vim
2828

29+
" Get shiftwidth value
30+
if exists('*shiftwidth')
31+
func s:sw()
32+
return shiftwidth()
33+
endfunc
34+
else
35+
func s:sw()
36+
return &sw
37+
endfunc
38+
endif
39+
2940
" 1. Variables {{{1
3041
" ============
3142

@@ -55,7 +66,7 @@ let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]
5566
" TODO: this needs to deal with if ...: and so on
5667
let s:msl_regex = s:continuation_regex.'|'.s:expr_case
5768

58-
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
69+
let s:one_line_scope_regex = '\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(.*)\)' . s:line_term
5970

6071
" Regex that defines blocks.
6172
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
@@ -68,15 +79,15 @@ let s:comma_last = ',\s*$'
6879
let s:ternary = '^\s\+[?|:]'
6980
let s:ternary_q = '^\s\+?'
7081

71-
let s:case_indent = &sw
72-
let s:case_indent_after = &sw
73-
let m = matchlist(&cinoptions, ':\(.\)')
74-
if (len(m) > 2)
75-
let s:case_indent = m[1]
82+
let s:case_indent = s:sw()
83+
let s:case_indent_after = s:sw()
84+
let s:m = matchlist(&cinoptions, ':\(.\)')
85+
if (len(s:m) > 2)
86+
let s:case_indent = s:m[1]
7687
endif
77-
let m = matchlist(&cinoptions, '=\(.\)')
78-
if (len(m) > 2)
79-
let s:case_indent_after = m[1]
88+
let s:m = matchlist(&cinoptions, '=\(.\)')
89+
if (len(s:m) > 2)
90+
let s:case_indent_after = s:m[1]
8091
endif
8192
" 2. Auxiliary Functions {{{1
8293
" ======================
@@ -201,9 +212,9 @@ function s:GetVarIndent(lnum)
201212

202213
" if the previous line doesn't end in a comma, return to regular indent
203214
if (line !~ s:comma_last)
204-
return indent(prev_lnum) - &sw
215+
return indent(prev_lnum) - s:sw()
205216
else
206-
return indent(lvar) + &sw
217+
return indent(lvar) + s:sw()
207218
endif
208219
endif
209220

@@ -342,7 +353,7 @@ function GetJavascriptIndent()
342353
return indent(prevline)
343354
" otherwise we indent 1 level
344355
else
345-
return indent(lvar) + &sw
356+
return indent(lvar) + s:sw()
346357
endif
347358
endif
348359
endif
@@ -361,7 +372,7 @@ function GetJavascriptIndent()
361372

362373
" If the line is comma first, dedent 1 level
363374
if (getline(prevline) =~ s:comma_first)
364-
return indent(prevline) - &sw
375+
return indent(prevline) - s:sw()
365376
endif
366377
if (getline(prevline) =~ s:expr_case)
367378
return indent(prevline) + s:case_indent_after
@@ -371,7 +382,7 @@ function GetJavascriptIndent()
371382
if (getline(prevline) =~ s:ternary_q)
372383
return indent(prevline)
373384
else
374-
return indent(prevline) + &sw
385+
return indent(prevline) + s:sw()
375386
endif
376387
endif
377388

@@ -413,9 +424,9 @@ function GetJavascriptIndent()
413424
" If the previous line ended with a block opening, add a level of indent.
414425
if s:Match(lnum, s:block_regex)
415426
if (line =~ s:expr_case)
416-
return indent(s:GetMSL(lnum, 0)) + &sw/2
427+
return indent(s:GetMSL(lnum, 0)) + s:sw()/2
417428
else
418-
return indent(s:GetMSL(lnum, 0)) + &sw
429+
return indent(s:GetMSL(lnum, 0)) + s:sw()
419430
endif
420431
endif
421432

@@ -428,12 +439,12 @@ function GetJavascriptIndent()
428439
let counts = s:LineHasOpeningBrackets(lnum)
429440
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
430441
if col('.') + 1 == col('$')
431-
return ind + &sw
442+
return ind + s:sw()
432443
else
433444
return virtcol('.')
434445
endif
435446
elseif counts[1] == '1' || counts[2] == '1'
436-
return ind + &sw
447+
return ind + s:sw()
437448
else
438449
call cursor(v:lnum, vcol)
439450
end
@@ -443,18 +454,18 @@ function GetJavascriptIndent()
443454
" --------------------------
444455

445456
let ind_con = ind
446-
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
457+
let ind = s:IndentWithContinuation(lnum, ind_con, s:sw())
447458

448459
" }}}2
449460
"
450461
"
451462
let ols = s:InOneLineScope(lnum)
452463
if ols > 0
453-
let ind = ind + &sw
464+
let ind = ind + s:sw()
454465
else
455466
let ols = s:ExitingOneLineScope(lnum)
456467
while ols > 0 && ind > 0
457-
let ind = ind - &sw
468+
let ind = ind - s:sw()
458469
let ols = s:InOneLineScope(ols - 1)
459470
endwhile
460471
endif

0 commit comments

Comments
 (0)