mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-09 11:33:47 -05:00
Fixed bugs
- Covered case when commentstring is not set (default). - Escaping commentstring symbols.
This commit is contained in:
@@ -41,17 +41,32 @@ endfunction
|
|||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:GetCommentStart() "{{{2
|
function! s:GetCommentStart() "{{{2
|
||||||
return split(substitute(&commentstring, '%s', ' ', 'g'))[0]
|
let cstring = &commentstring
|
||||||
|
if s:Strlen(cstring) > 0
|
||||||
|
return substitute(split(substitute(cstring, '%s', ' ', 'g'))[0], '.', '\\\0', 'g')
|
||||||
|
else
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:StartExpr() "{{{2
|
function! s:StartExpr() "{{{2
|
||||||
return '^\s*\(' . s:GetCommentStart() . '\)\?\s*'
|
let cstart = s:GetCommentStart()
|
||||||
|
if s:Strlen(cstart) > 0
|
||||||
|
return '^\s*\(' . cstart . '\)\?\s*'
|
||||||
|
else
|
||||||
|
return '^\s*'
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:StartCommentExpr() "{{{2
|
function! s:StartCommentExpr() "{{{2
|
||||||
return '^\s*' . s:GetCommentStart() . '\s*'
|
let cstartexpr = s:GetCommentStart()
|
||||||
|
if s:Strlen(cstartexpr) > 0
|
||||||
|
return '^\s*' . cstartexpr . '\s*'
|
||||||
|
else
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -95,7 +110,8 @@ function! s:UpdateLineBorder(line) "{{{2
|
|||||||
silent! execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
|
silent! execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if getline(cline) =~# s:StartCommentExpr()
|
let cstartexpr = s:StartCommentExpr()
|
||||||
|
if s:Strlen(cstartexpr) > 0 && getline(cline) =~# cstartexpr
|
||||||
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
||||||
call append(cline-1, indent . repeat(g:table_mode_corner, curr_line_count))
|
call append(cline-1, indent . repeat(g:table_mode_corner, curr_line_count))
|
||||||
else
|
else
|
||||||
@@ -110,7 +126,8 @@ function! s:UpdateLineBorder(line) "{{{2
|
|||||||
silent! execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
|
silent! execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if getline(cline) =~# s:StartCommentExpr()
|
let cstartexpr = s:StartCommentExpr()
|
||||||
|
if s:Strlen(cstartexpr) > 0 && getline(cline) =~# cstartexpr
|
||||||
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
let indent = matchstr(getline(cline), s:StartCommentExpr())
|
||||||
call append(cline, indent . repeat(g:table_mode_corner, curr_line_count))
|
call append(cline, indent . repeat(g:table_mode_corner, curr_line_count))
|
||||||
else
|
else
|
||||||
@@ -138,8 +155,14 @@ endfunction
|
|||||||
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
||||||
let delim = g:table_mode_delimiter
|
let delim = g:table_mode_delimiter
|
||||||
if a:0 | let delim = a:1 | endif
|
if a:0 | let delim = a:1 | endif
|
||||||
|
if delim ==# ','
|
||||||
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs,\\ze[^\'\"]*[\'\"]/__COMMA__/g"
|
||||||
|
endif
|
||||||
silent! execute a:line . 's/' . s:StartExpr() . '\zs\ze.\|' . delim . '\|$/' .
|
silent! execute a:line . 's/' . s:StartExpr() . '\zs\ze.\|' . delim . '\|$/' .
|
||||||
\ g:table_mode_separator . '/g'
|
\ g:table_mode_separator . '/g'
|
||||||
|
if delim ==# ','
|
||||||
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs__COMMA__\\ze[^\'\"]*[\'\"]/,/g"
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user