Skip to content

Commit 924a645

Browse files
authored
misc fixes (#578)
make sure to calculate switch_offset even when using 'c-style' and fix block comments at the very top of a file
1 parent 6d70fab commit 924a645

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

indent/javascript.vim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ let g:javascript_continuation .= s:line_term
7171

7272
function s:Onescope(lnum,text,add)
7373
return a:text =~ '\%(\<else\|\<do\|=>' . (a:add ? '\|\<try\|\<finally' : '' ) . '\)\C' . s:line_term ||
74-
\ (a:add && a:text =~ s:line_pre . s:line_term && getline(s:PrevCodeLine(a:lnum - 1)) =~ ')' . s:line_term) ||
75-
\ (cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1 &&
74+
\ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) ||
75+
\ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) &&
7676
\ s:lookForParens('(', ')', 'cbW', 100) > 0 &&
7777
\ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' :
78-
\ '\<\%(for\%(\s+each\)\=\|if\|let\|switch\|while\|with\)\C') . '\_s*\%#','bW')) &&
78+
\ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)\C') . '\_s*\%#','bW') &&
7979
\ (a:add || (expand("<cword>") == 'while' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1))
8080
endfunction
8181

@@ -132,10 +132,6 @@ function GetJavascriptIndent()
132132
" previous nonblank line number
133133
let prevline = prevnonblank(v:lnum - 1)
134134
" previous line of code
135-
let lnum = s:PrevCodeLine(v:lnum - 1)
136-
if lnum == 0
137-
return 0
138-
endif
139135

140136
" start with strings,comments,etc.{{{2
141137
if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) ||
@@ -145,6 +141,10 @@ function GetJavascriptIndent()
145141
if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment)
146142
return cindent(v:lnum)
147143
endif
144+
let lnum = s:PrevCodeLine(v:lnum - 1)
145+
if lnum == 0
146+
return 0
147+
endif
148148

149149
if (line =~ s:expr_case)
150150
let cpo_switch = &cpo

0 commit comments

Comments
 (0)