diff --git a/README.md b/README.md
index 7b58a10..408bcc5 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,10 @@ An awesome automatic table creator & formatter allowing one to create neat
tables as you type.
## 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 :
* 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
diff --git a/after/plugin/table-mode.vim b/after/plugin/table-mode.vim
index 94e5b18..e1c65cf 100644
--- a/after/plugin/table-mode.vim
+++ b/after/plugin/table-mode.vim
@@ -4,7 +4,7 @@
" Author: Dhruva Sagar
" License: MIT (http://www.opensource.org/licenses/MIT)
" 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'
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
" uses a small amount of code from it.
@@ -49,6 +49,7 @@ call s:SetGlobalOptDefault('table_mode_toggle_map', 'tm')
call s:SetGlobalOptDefault('table_mode_always_active', 0)
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
call s:SetGlobalOptDefault('table_mode_tableize_map', 'T')
+call s:SetGlobalOptDefault('table_mode_align', 'l1')
"}}}1
" Define Commands & Mappings {{{1
diff --git a/autoload/tablemode.vim b/autoload/tablemode.vim
index 976fdc3..3c84d5a 100644
--- a/autoload/tablemode.vim
+++ b/autoload/tablemode.vim
@@ -4,7 +4,7 @@
" Author: Dhruva Sagar
" License: MIT (http://www.opensource.org/licenses/MIT)
" 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'
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
" uses a small amount of code from it.
@@ -40,49 +40,9 @@ function! s:CountSeparator(line, separator) "{{{2
endfunction
" }}}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) . "\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) . "\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
- 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
" }}}2
@@ -94,35 +54,21 @@ function! s:IsTableModeActive() "{{{2
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
- 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
if g:table_mode_separator ==# '|'
- let table_mode_separator_map = ''
+ return ''
else
- let table_mode_separator_map = g:table_mode_separator
+ return g:table_mode_separator
endif
- return table_mode_separator_map
endfunction
" }}}2
function! s:ToggleMapping() "{{{2
if exists('b:table_mode_active') && b:table_mode_active
- exec "inoremap " . s:TableModeSeparatorMap() . ' ' .
+ execute "inoremap " . s:TableModeSeparatorMap() . ' ' .
\ s:TableModeSeparatorMap() . ":call Tableize()a"
else
- exec "iunmap " . s:TableModeSeparatorMap()
+ execute "iunmap " . s:TableModeSeparatorMap()
endif
endfunction
" }}}2
@@ -133,6 +79,63 @@ function! s:SetActive(bool) "{{{2
endfunction
" }}}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) . "\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) . "\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
" Public API {{{1
diff --git a/doc/table-mode.txt b/doc/table-mode.txt
index 40519a9..586537e 100644
--- a/doc/table-mode.txt
+++ b/doc/table-mode.txt
@@ -56,6 +56,7 @@ Overview:
|table-mode-options-toggle-map| ...... Set table mode toggle mapping
|table-mode-options-always-active| ... Set table mode to always enabled
|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*
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
|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*
diff --git a/doc/tags b/doc/tags
index c689202..40a2e58 100644
--- a/doc/tags
+++ b/doc/tags
@@ -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-trigger table-mode.txt /*table-mode-mappings-trigger*
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-border table-mode.txt /*table-mode-options-border*
table-mode-options-corner table-mode.txt /*table-mode-options-corner*