Skip to content

Commit 05f9953

Browse files
authored
Fix 'commentstring' detection (#127)
* fix auto-detection of commentstring Skip indent if col('.') is indent. * buffer-variable should be prefixed by plugin name
1 parent 838cfce commit 05f9953

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

after/ftplugin/javascript.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ if exists("loaded_matchup")
2121
let b:match_skip = 's:comment\|string'
2222
endif
2323

24-
let b:original_commentstring = &l:commentstring
24+
let b:jsx_pretty_old_cms = &l:commentstring
2525

2626
augroup jsx_comment
2727
autocmd! CursorMoved <buffer>
28-
autocmd CursorMoved <buffer> call jsx_pretty#comment#update_commentstring(b:original_commentstring)
28+
autocmd CursorMoved <buffer> call jsx_pretty#comment#update_commentstring(b:jsx_pretty_old_cms)
2929
augroup end
3030

3131
setlocal suffixesadd+=.jsx

after/ftplugin/tsx.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ if exists("loaded_matchup")
1818
let b:match_skip = 's:comment\|string'
1919
endif
2020

21-
let b:original_commentstring = &l:commentstring
21+
let b:jsx_pretty_old_cms = &l:commentstring
2222

2323
augroup jsx_comment
2424
autocmd! CursorMoved <buffer>
25-
autocmd CursorMoved <buffer> call jsx_pretty#comment#update_commentstring(b:original_commentstring)
25+
autocmd CursorMoved <buffer> call jsx_pretty#comment#update_commentstring(b:jsx_pretty_old_cms)
2626
augroup end
2727

2828
setlocal suffixesadd+=.tsx

autoload/jsx_pretty/comment.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function! jsx_pretty#comment#update_commentstring(original)
2-
let syn_current = s:syn_name(line('.'), col('.'))
3-
let syn_start = s:syn_name(line('.'), 1)
2+
let line = getline(".")
3+
let col = col('.')
4+
if line !~# '^\s*$' && line[: col - 1] =~# '^\s*$' " skip indent
5+
let col = indent('.') + 1
6+
endif
7+
let syn_start = s:syn_name(line('.'), col)
48
let save_cursor = getcurpos()
59

610
if syn_start =~? '^jsx'
7-
let line = getline(".")
8-
let start = len(matchstr(line, '^\s*'))
9-
let syn_name = s:syn_name(line('.'), start + 1)
10-
1111
if line =~ '^\s*//'
1212
let &l:commentstring = '// %s'
13-
elseif s:syn_contains(line('.'), col('.'), 'jsxTaggedRegion')
13+
elseif s:syn_contains(line('.'), col, 'jsxTaggedRegion')
1414
let &l:commentstring = '<!-- %s -->'
15-
elseif syn_name =~? '^jsxAttrib'
15+
elseif syn_start =~? '^jsxAttrib'
1616
let &l:commentstring = '// %s'
1717
else
1818
let &l:commentstring = '{/* %s */}'

0 commit comments

Comments
 (0)