Releasing v2.1.1

- Moved some code around for better readability.
- Added new option g:table_mode_align for allowing the user to set the
  format option for aligning the text, this is passed directly to
  Tabular.
- Updated vim doc.
- Updated README.md
This commit is contained in:
Dhruva Sagar
2013-03-21 08:44:26 +05:30
parent f23737d5fa
commit f8610cebdb
5 changed files with 77 additions and 62 deletions

View File

@@ -4,6 +4,10 @@ An awesome automatic table creator & formatter allowing one to create neat
tables as you type. tables as you type.
## Change Log ## Change Log
### Version 2.1.1 :
* Added option g:table_mode_align to allow setting Tabular format option for
more control on how Tabular aligns text.
### Version 2.1 : ### Version 2.1 :
* VIM loads plugins in alphabetical order and so table-mode would be loaded * VIM loads plugins in alphabetical order and so table-mode would be loaded
before Tabularize which it depends on. Hence Moved plugin into an after before Tabularize which it depends on. Hence Moved plugin into an after

View File

@@ -4,7 +4,7 @@
" Author: Dhruva Sagar <http://dhruvasagar.com/> " Author: Dhruva Sagar <http://dhruvasagar.com/>
" License: MIT (http://www.opensource.org/licenses/MIT) " License: MIT (http://www.opensource.org/licenses/MIT)
" Website: http://github.com/dhruvasagar/vim-table-mode " Website: http://github.com/dhruvasagar/vim-table-mode
" Version: 2.1 " Version: 2.1.1
" Note: This plugin was heavily inspired by the 'CucumberTables.vim' " Note: This plugin was heavily inspired by the 'CucumberTables.vim'
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and " (https://gist.github.com/tpope/287147) plugin by Tim Pope and
" uses a small amount of code from it. " uses a small amount of code from it.
@@ -49,6 +49,7 @@ call s:SetGlobalOptDefault('table_mode_toggle_map', '<Leader>tm')
call s:SetGlobalOptDefault('table_mode_always_active', 0) call s:SetGlobalOptDefault('table_mode_always_active', 0)
call s:SetGlobalOptDefault('table_mode_delimiter', ',') call s:SetGlobalOptDefault('table_mode_delimiter', ',')
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>T') call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>T')
call s:SetGlobalOptDefault('table_mode_align', 'l1')
"}}}1 "}}}1
" Define Commands & Mappings {{{1 " Define Commands & Mappings {{{1

View File

@@ -4,7 +4,7 @@
" Author: Dhruva Sagar <http://dhruvasagar.com/> " Author: Dhruva Sagar <http://dhruvasagar.com/>
" License: MIT (http://www.opensource.org/licenses/MIT) " License: MIT (http://www.opensource.org/licenses/MIT)
" Website: http://github.com/dhruvasagar/vim-table-mode " Website: http://github.com/dhruvasagar/vim-table-mode
" Version: 2.1 " Version: 2.1.1
" Note: This plugin was heavily inspired by the 'CucumberTables.vim' " Note: This plugin was heavily inspired by the 'CucumberTables.vim'
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and " (https://gist.github.com/tpope/287147) plugin by Tim Pope and
" uses a small amount of code from it. " uses a small amount of code from it.
@@ -40,49 +40,9 @@ function! s:CountSeparator(line, separator) "{{{2
endfunction endfunction
" }}}2 " }}}2
function! s:UpdateLineBorder(line) "{{{2
let cline = a:line
let hf = '^\s*' . g:table_mode_corner . '[' . g:table_mode_corner . ' ' . g:table_mode_fillchar . ']*' . g:table_mode_corner . '\?\s*$'
let curr_line_count = s:CountSeparator(cline, g:table_mode_separator)
if getline(cline-1) =~# hf
let prev_line_count = s:CountSeparator(cline-1, g:table_mode_corner)
if curr_line_count > prev_line_count
exec 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
endif
else
call append(cline-1, repeat(g:table_mode_corner, curr_line_count))
let cline = a:line + 1
endif
if getline(cline+1) =~# hf
let next_line_count = s:CountSeparator(cline+1, g:table_mode_corner)
if curr_line_count > next_line_count
exec 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
end
else
call append(cline, repeat(g:table_mode_corner, curr_line_count))
endif
endfunction
" }}}2
function! s:FillTableBorder() "{{{2
let current_col = col('.')
let current_line = line('.')
execute 'silent! %s/' . g:table_mode_corner . ' \zs\([' . g:table_mode_fillchar . ' ]*\)\ze ' . g:table_mode_corner . '/\=repeat("' . g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
call cursor(current_line, current_col)
endfunction
" }}}2
function! s:Tableizeline(line) "{{{2
call s:ConvertDelimiterToSeparator(a:line)
call s:UpdateLineBorder(a:line)
exec 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/l1'
endfunction
" }}}2
function! s:ConvertDelimiterToSeparator(line) "{{{2 function! s:ConvertDelimiterToSeparator(line) "{{{2
execute 'silent! ' . a:line . 's/^\s*\zs\ze.\|' . g:table_mode_delimiter . '\|$/' . g:table_mode_separator . '/g' execute 'silent! ' . a:line . 's/^\s*\zs\ze.\|' . g:table_mode_delimiter .
\ '\|$/' . g:table_mode_separator . '/g'
endfunction endfunction
" }}}2 " }}}2
@@ -94,35 +54,21 @@ function! s:IsTableModeActive() "{{{2
endfunction endfunction
" }}}2 " }}}2
function! s:Tableize() "{{{2
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
exec 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/l1'
if g:table_mode_border | call s:FillTableBorder() | endif
normal! 0
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
endif
endfunction
" }}}2
function! s:TableModeSeparatorMap() "{{{2 function! s:TableModeSeparatorMap() "{{{2
if g:table_mode_separator ==# '|' if g:table_mode_separator ==# '|'
let table_mode_separator_map = '<Bar>' return '<Bar>'
else else
let table_mode_separator_map = g:table_mode_separator return g:table_mode_separator
endif endif
return table_mode_separator_map
endfunction endfunction
" }}}2 " }}}2
function! s:ToggleMapping() "{{{2 function! s:ToggleMapping() "{{{2
if exists('b:table_mode_active') && b:table_mode_active if exists('b:table_mode_active') && b:table_mode_active
exec "inoremap <silent> " . s:TableModeSeparatorMap() . ' ' . execute "inoremap <silent> " . s:TableModeSeparatorMap() . ' ' .
\ s:TableModeSeparatorMap() . "<Esc>:call <SID>Tableize()<CR>a" \ s:TableModeSeparatorMap() . "<Esc>:call <SID>Tableize()<CR>a"
else else
exec "iunmap <silent> " . s:TableModeSeparatorMap() execute "iunmap <silent> " . s:TableModeSeparatorMap()
endif endif
endfunction endfunction
" }}}2 " }}}2
@@ -133,6 +79,63 @@ function! s:SetActive(bool) "{{{2
endfunction endfunction
" }}}2 " }}}2
function! s:UpdateLineBorder(line) "{{{2
let cline = a:line
let hf = '^\s*' . g:table_mode_corner . '[' . g:table_mode_corner . ' ' .
\ g:table_mode_fillchar . ']*' . g:table_mode_corner . '\?\s*$'
let curr_line_count = s:CountSeparator(cline, g:table_mode_separator)
if getline(cline-1) =~# hf
let prev_line_count = s:CountSeparator(cline-1, g:table_mode_corner)
if curr_line_count > prev_line_count
execute 'normal! kA' . repeat(g:table_mode_corner, curr_line_count - prev_line_count) . "\<Esc>j"
endif
else
call append(cline-1, repeat(g:table_mode_corner, curr_line_count))
let cline = a:line + 1
endif
if getline(cline+1) =~# hf
let next_line_count = s:CountSeparator(cline+1, g:table_mode_corner)
if curr_line_count > next_line_count
execute 'normal! jA' . repeat(g:table_mode_corner, curr_line_count - next_line_count) . "\<Esc>k"
end
else
call append(cline, repeat(g:table_mode_corner, curr_line_count))
endif
endfunction
" }}}2
function! s:FillTableBorder() "{{{2
let current_col = col('.')
let current_line = line('.')
execute 'silent! %s/' . g:table_mode_corner . ' \zs\([' .
\ g:table_mode_fillchar . ' ]*\)\ze ' . g:table_mode_corner . '/\=repeat("' .
\ g:table_mode_fillchar . '", s:Strlen(submatch(0)))/g'
call cursor(current_line, current_col)
endfunction
" }}}2
function! s:Tableize() "{{{2
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
if g:table_mode_border | call s:FillTableBorder() | endif
normal! 0
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
endif
endfunction
" }}}2
function! s:Tableizeline(line) "{{{2
call s:ConvertDelimiterToSeparator(a:line)
call s:UpdateLineBorder(a:line)
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
endfunction
" }}}2
" }}}1 " }}}1
" Public API {{{1 " Public API {{{1

View File

@@ -56,6 +56,7 @@ Overview:
|table-mode-options-toggle-map| ...... Set table mode toggle mapping |table-mode-options-toggle-map| ...... Set table mode toggle mapping
|table-mode-options-always-active| ... Set table mode to always enabled |table-mode-options-always-active| ... Set table mode to always enabled
|table-mode-options-delimiter| ....... Set the delimiter for Tableize |table-mode-options-delimiter| ....... Set the delimiter for Tableize
|table-mode-options-align| ........... Set the text alignment for Tableize
g:table_mode_loaded *table-mode-options-loaded* g:table_mode_loaded *table-mode-options-loaded*
Use this option to disable the plugin: > Use this option to disable the plugin: >
@@ -104,6 +105,11 @@ g:table_mode_delimiter *table-mode-options-delimiter*
Use this option to define the delimiter which used by Use this option to define the delimiter which used by
|table-mode-commands-tableize| |table-mode-commands-tableize|
g:table_mode_align *table-mode-options-align*
Use this option to define the format for text alignment to be used for
the tables. Go through |tabular-walkthrough| for details on how to set
the format options for alignment. >
let g:table_mode_align = 'l1'
=============================================================================== ===============================================================================
MAPPINGS *table-mode-mappings* MAPPINGS *table-mode-mappings*

View File

@@ -15,6 +15,7 @@ table-mode-mappings table-mode.txt /*table-mode-mappings*
table-mode-mappings-toggle table-mode.txt /*table-mode-mappings-toggle* table-mode-mappings-toggle table-mode.txt /*table-mode-mappings-toggle*
table-mode-mappings-trigger table-mode.txt /*table-mode-mappings-trigger* table-mode-mappings-trigger table-mode.txt /*table-mode-mappings-trigger*
table-mode-options table-mode.txt /*table-mode-options* table-mode-options table-mode.txt /*table-mode-options*
table-mode-options-align table-mode.txt /*table-mode-options-align*
table-mode-options-always-active table-mode.txt /*table-mode-options-always-active* table-mode-options-always-active table-mode.txt /*table-mode-options-always-active*
table-mode-options-border table-mode.txt /*table-mode-options-border* table-mode-options-border table-mode.txt /*table-mode-options-border*
table-mode-options-corner table-mode.txt /*table-mode-options-corner* table-mode-options-corner table-mode.txt /*table-mode-options-corner*