Switched to using || mapping for table border generation, more intuitive & create a minimal border on a new line without a table

This commit is contained in:
Dhruva Sagar
2013-11-13 08:45:15 +05:30
parent a0618db019
commit e94bbcc0b4
3 changed files with 18 additions and 14 deletions

View File

@@ -4,7 +4,7 @@
" Author: Dhruva Sagar <http://dhruvasagar.com/>
" License: MIT (http://www.opensource.org/licenses/MIT)
" Website: http://github.com/dhruvasagar/vim-table-mode
" Version: 3.2
" Version: 3.3
" 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.
@@ -169,13 +169,8 @@ function! s:ToggleMapping() "{{{2
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
execute "inoremap <silent> <buffer> " . g:table_mode_corner .
\ g:table_mode_fillchar . " <Esc>:call tablemode#AddHeaderBorder('.')<CR>A"
else
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
execute "iunmap <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
endif
endfunction
@@ -184,6 +179,14 @@ function! s:SetActive(bool) "{{{2
call s:ToggleMapping()
endfunction
function! s:DefaultHeaderBorder() "{{{2
if s:IsTableModeActive()
return g:table_mode_separator . g:table_mode_fillchar . g:table_mode_corner . g:table_mode_fillchar . g:table_mode_separator
else
return ''
endif
endfunction
function! s:GenerateHeaderBorder(line) "{{{2
let line = s:Line(a:line)
if tablemode#IsATableRow(line - s:RowGap()) || tablemode#IsATableRow(line + s:RowGap())
@@ -194,6 +197,7 @@ function! s:GenerateHeaderBorder(line) "{{{2
if tablemode#IsATableRow(line - s:RowGap()) && s:Strlen(line_val) < s:Strlen(getline(line - s:RowGap()))
let line_val = getline(line - s:RowGap())
endif
if s:Strlen(line_val) <= 1 | return s:DefaultHeaderBorder() | endif
let border = substitute(line_val[stridx(line_val, g:table_mode_separator):strridx(line_val, g:table_mode_separator)], g:table_mode_separator, g:table_mode_corner, 'g')
let border = substitute(border, '[^' . g:table_mode_corner . ']', g:table_mode_fillchar, 'g')
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
@@ -209,6 +213,8 @@ function! s:GenerateHeaderBorder(line) "{{{2
else
return border
endif
else
return s:DefaultHeaderBorder()
endif
endfunction

View File

@@ -1,7 +1,7 @@
*table-mode.txt* Table Mode for easy table formatting. v3.2
*table-mode.txt* Table Mode for easy table formatting. v3.3
===============================================================================
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
VERSION 3.2
VERSION 3.3
Author: Dhruva Sagar <http://dhruvasagar.com/>
License: MIT <http://opensource.org/licenses/MIT/>
@@ -323,11 +323,9 @@ MAPPINGS *table-mode-mappings*
would evaluate the formula line and update the table
accordingly. This invokes the |TableEvalFormulaLine| command.
+- Expands to a header border, the line immidiately above this
will be considered as the table header. You can change this by
changing |table-mode-corner| and |table-mode-fillchar|
options. This is an iabbrev so is triggered when you press
space or <CR> after typing the mapping.
|| Expands to a header border, the line immidiately above or
below this will be considered as the table header. You can
change this by changing |table-mode-separator| options.
===============================================================================
COMMANDS *table-mode-commands*

View File

@@ -4,7 +4,7 @@
" Author: Dhruva Sagar <http://dhruvasagar.com/>
" License: MIT (http://www.opensource.org/licenses/MIT)
" Website: http://github.com/dhruvasagar/vim-table-mode
" Version: 3.2
" Version: 3.3
" 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.