Skip to content

Commit c8730a1

Browse files
committed
Merge pull request #68 from hickop/fixes
Fixes comment indentation
2 parents 4dee33f + c6cf517 commit c8730a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

indent/javascript.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ let s:syng_string = 'regex\c'
3737
" Regex of syntax group names that are strings or documentation.
3838
let s:syng_multiline = 'comment\c'
3939

40+
" Regex of syntax group names that are line comment.
41+
let s:syng_linecom = 'linecomment\c'
42+
4043
" Expression used to check whether we should skip a match with searchpair().
4144
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
4245

@@ -77,6 +80,11 @@ function s:IsInMultilineComment(lnum, col)
7780
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
7881
endfunction
7982

83+
" Check if the character at lnum:col is a line comment.
84+
function s:IsLineComment(lnum, col)
85+
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom
86+
endfunction
87+
8088
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
8189
function s:PrevNonBlankNonString(lnum)
8290
let in_block = 0
@@ -323,7 +331,7 @@ function GetJavascriptIndent()
323331
endif
324332

325333
" If we are in a multi-line comment, cindent does the right thing.
326-
if s:IsInMultilineComment(v:lnum, 1)
334+
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
327335
return cindent(v:lnum)
328336
endif
329337

0 commit comments

Comments
 (0)