mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef66b3ec2f | ||
|
|
6584cee4a4 | ||
|
|
1eef73fc5b | ||
|
|
d3b70df0a6 | ||
|
|
096165718e | ||
|
|
30a3eba816 | ||
|
|
cc0055f329 | ||
|
|
8d3affcf5f | ||
|
|
9edd6d7d20 | ||
|
|
441c30c35a | ||
|
|
ebd16eef19 | ||
|
|
141efc3edd | ||
|
|
c82bc292c5 | ||
|
|
8209b59215 | ||
|
|
5b3b2f7c05 | ||
|
|
47f60d2972 | ||
|
|
0f680bfd1b | ||
|
|
19f2f5c26f | ||
|
|
e07c240940 | ||
|
|
8bacd0ba66 | ||
|
|
8309a33aa7 | ||
|
|
293c847cdf | ||
|
|
96236638a8 | ||
|
|
1d14a027a8 | ||
|
|
e490373435 | ||
|
|
b420dedbf5 |
@@ -1,4 +1,4 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.2.0
|
||||
- 2.3.0
|
||||
script: rake ci
|
||||
|
||||
2
Gemfile
2
Gemfile
@@ -1,5 +1,5 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
ruby '2.2.0'
|
||||
ruby '2.3.0'
|
||||
gem 'rake'
|
||||
gem 'vim-flavor', '~> 1.1'
|
||||
|
||||
29
README.md
29
README.md
@@ -1,4 +1,4 @@
|
||||
# VIM Table Mode v4.6.4.1 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
||||
# VIM Table Mode v4.6.5 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
||||
|
||||
An awesome automatic table creator & formatter allowing one to create neat
|
||||
tables as you type.
|
||||
@@ -28,7 +28,26 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
|
||||
### Creating table on-the-fly
|
||||
|
||||
To start using the plugin in the on-the-fly mode use `:TableModeToggle` mapped to <kbd>\<Leader\>tm</kbd> by default (which means <kbd>\\</kbd> <kbd>t</kbd> <kbd>m</kbd> if you didn't override the <Leader> by `:let mapleader = ","` to have <kbd>,</kbd> <kbd>t</kbd> <kbd>m</kbd>).
|
||||
To start using the plugin in the on-the-fly mode use `:TableModeToggle` mapped to <kbd>\<Leader\>tm</kbd> by default (which means <kbd>\\</kbd> <kbd>t</kbd> <kbd>m</kbd> if you didn't override the <Leader> by `:let mapleader = ','` to have <kbd>,</kbd> <kbd>t</kbd> <kbd>m</kbd>).
|
||||
|
||||
> Tip :
|
||||
> You can use the following to quickly enable / disable table mode in insert
|
||||
> mode by using `||` or `__` :
|
||||
> ```vim
|
||||
> function! s:isAtStartOfLine(mapping)
|
||||
> let text_before_cursor = getline('.')[0 : col('.')-1]
|
||||
> let mapping_pattern = '\V' . escape(a:mapping, '\')
|
||||
> let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
|
||||
> return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
|
||||
> endfunction
|
||||
>
|
||||
> inoreabbrev <expr> <bar><bar>
|
||||
> \ <SID>isAtStartOfLine('\|\|') ?
|
||||
> \ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
|
||||
> inoreabbrev <expr> __
|
||||
> \ <SID>isAtStartOfLine('__') ?
|
||||
> \ '<c-o>:silent! TableModeDisable<cr>' : '__'
|
||||
> ```
|
||||
|
||||
Enter the first line, delimiting columns by the `|` symbol. The plugin reacts by inserting spaces between the text and the separator if you omit them:
|
||||
|
||||
@@ -68,7 +87,7 @@ Corner separators are adjustable:
|
||||
|
||||
For Markdown-compatible tables use
|
||||
|
||||
let g:table_mode_corner="|"
|
||||
let g:table_mode_corner='|'
|
||||
|
||||
|
||||
|-----------------|--------------------------|------------|
|
||||
@@ -81,8 +100,8 @@ For Markdown-compatible tables use
|
||||
|
||||
To get ReST-compatible tables use
|
||||
|
||||
let g:table_mode_corner_corner="+"
|
||||
let g:table_mode_header_fillchar="="
|
||||
let g:table_mode_corner_corner='+'
|
||||
let g:table_mode_header_fillchar='='
|
||||
|
||||
|
||||
+-----------------+--------------------------+------------+
|
||||
|
||||
@@ -65,22 +65,20 @@ function! s:ToggleMapping() "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#SyntaxEnable()
|
||||
exec 'syntax match Table'
|
||||
\ '/' . tablemode#table#StartExpr() . '\zs|.\+|\ze' . tablemode#table#EndExpr() . '/'
|
||||
\ 'contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL'
|
||||
syntax match TableSeparator /|/ contained
|
||||
syntax match TableColumnAlign /:/ contained
|
||||
syntax match TableBorder /[\-+]\+/ contained
|
||||
function! s:ToggleSyntax() "{{{2
|
||||
if !g:table_mode_syntax | return | endif
|
||||
|
||||
hi! link TableBorder Delimiter
|
||||
hi! link TableSeparator Delimiter
|
||||
hi! link TableColumnAlign Type
|
||||
endfunction
|
||||
|
||||
function! s:ToggleSyntax()
|
||||
if tablemode#IsActive()
|
||||
call tablemode#SyntaxEnable()
|
||||
exec 'syntax match Table'
|
||||
\ '/' . tablemode#table#StartExpr() . '\zs|.\+|\ze' . tablemode#table#EndExpr() . '/'
|
||||
\ 'contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL'
|
||||
syntax match TableSeparator /|/ contained
|
||||
syntax match TableColumnAlign /:/ contained
|
||||
syntax match TableBorder /[\-+]\+/ contained
|
||||
|
||||
hi! link TableBorder Delimiter
|
||||
hi! link TableSeparator Delimiter
|
||||
hi! link TableColumnAlign Type
|
||||
else
|
||||
syntax clear Table
|
||||
syntax clear TableBorder
|
||||
@@ -93,10 +91,25 @@ function! s:ToggleSyntax()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:ToggleAutoAlign() "{{{2
|
||||
if !g:table_mode_auto_align | return | endif
|
||||
|
||||
if tablemode#IsActive()
|
||||
augroup TableModeAutoAlign
|
||||
au!
|
||||
|
||||
autocmd CursorHold,CursorHoldI * nested silent! call tablemode#table#Realign('.')
|
||||
augroup END
|
||||
else
|
||||
silent! augroup! TableModeAutoAlign
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:SetActive(bool) "{{{2
|
||||
let b:table_mode_active = a:bool
|
||||
call s:ToggleSyntax()
|
||||
call s:ToggleMapping()
|
||||
call s:ToggleAutoAlign()
|
||||
if tablemode#IsActive()
|
||||
doautocmd User TableModeEnabled
|
||||
else
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function! tablemode#logger#log(message)
|
||||
if g:table_mode_verbose
|
||||
echom message
|
||||
echom a:message
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
" Private Functions {{{1
|
||||
function! s:IsFormulaLine(line) "{{{2
|
||||
return getline(a:line) =~# 'tmf: '
|
||||
endfunction
|
||||
|
||||
" Public Functions {{{1
|
||||
function! tablemode#spreadsheet#formula#Add(...) "{{{2
|
||||
@@ -105,14 +108,21 @@ function! tablemode#spreadsheet#formula#EvaluateFormulaLine() abort "{{{2
|
||||
let line = tablemode#spreadsheet#GetLastRow('.')
|
||||
let fline = line + 1
|
||||
if tablemode#table#IsBorder(fline) | let fline += 1 | endif
|
||||
if getline(fline) =~# 'tmf: '
|
||||
let exprs = split(matchstr(getline(fline), matchexpr), ';')
|
||||
endif
|
||||
elseif getline('.') =~# 'tmf: ' " We're on the formula line
|
||||
while s:IsFormulaLine(fline)
|
||||
let exprs += split(matchstr(getline(fline), matchexpr), ';')
|
||||
let fline += 1
|
||||
endwhile
|
||||
elseif s:IsFormulaLine('.')
|
||||
let fline = line('.')
|
||||
let line = line('.') - 1
|
||||
while s:IsFormulaLine(line) | let fline = line | let line -= 1 | endwhile
|
||||
if tablemode#table#IsBorder(line) | let line -= 1 | endif
|
||||
if tablemode#table#IsRow(line)
|
||||
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
||||
" let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
||||
while s:IsFormulaLine(fline)
|
||||
let exprs += split(matchstr(getline(fline), matchexpr), ';')
|
||||
let fline += 1
|
||||
endwhile
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
" Private Functions {{{1
|
||||
function! s:blank(string) "{{{2
|
||||
return a:string =~# '^\s*$'
|
||||
endfunction
|
||||
|
||||
function! s:BorderExpr() "{{{2
|
||||
return tablemode#table#StartExpr() .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_corner_corner . ']' .
|
||||
@@ -27,14 +31,11 @@ function! s:GenerateHeaderBorder(line) "{{{2
|
||||
endif
|
||||
if tablemode#utils#strlen(line_val) <= 1 | return s:DefaultBorder() | 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')
|
||||
" To accurately deal with unicode double width characters
|
||||
if tablemode#table#IsHeader(line - 1)
|
||||
let fill_columns = map(split(border, g:table_mode_corner), 'repeat(g:table_mode_header_fillchar, tablemode#utils#StrDisplayWidth(v:val))')
|
||||
else
|
||||
let fill_columns = map(split(border, g:table_mode_corner), 'repeat(g:table_mode_fillchar, tablemode#utils#StrDisplayWidth(v:val))')
|
||||
endif
|
||||
let border = g:table_mode_corner . join(fill_columns, g:table_mode_corner) . g:table_mode_corner
|
||||
let tline = line_val[stridx(line_val, g:table_mode_separator):strridx(line_val, g:table_mode_separator)]
|
||||
let fillchar = tablemode#table#IsHeader(line - 1) ? g:table_mode_header_fillchar : g:table_mode_fillchar
|
||||
let seperator_match_regex = g:table_mode_separator . '\zs\([^' . g:table_mode_separator . ']*\)\ze' . g:table_mode_separator
|
||||
let border = substitute(tline, seperator_match_regex, '\=repeat(fillchar, tablemode#utils#StrDisplayWidth(submatch(0)))', 'g')
|
||||
let border = substitute(border, g:table_mode_separator, g:table_mode_corner, 'g')
|
||||
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_corner_corner . '\1' . g:table_mode_corner_corner, '')
|
||||
|
||||
" Incorporate header alignment chars
|
||||
@@ -135,7 +136,7 @@ function! tablemode#table#EndExpr() "{{{2
|
||||
endfunction
|
||||
|
||||
function! tablemode#table#IsBorder(line) "{{{2
|
||||
return !empty(getline(a:line)) && getline(a:line) =~# s:BorderExpr()
|
||||
return !s:blank(getline(a:line)) && getline(a:line) =~# s:BorderExpr()
|
||||
endfunction
|
||||
|
||||
function! tablemode#table#IsHeader(line) "{{{2
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
*table-mode.txt* Table Mode for easy table formatting
|
||||
===============================================================================
|
||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||
VERSION 4.6.4.1
|
||||
VERSION 4.6.5
|
||||
|
||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||
License: MIT <http://opensource.org/licenses/MIT/>
|
||||
@@ -138,6 +138,7 @@ OPTIONS *table-mode-options*
|
||||
|
||||
Overview:
|
||||
|table-mode-loaded| ............. Disable the plugin.
|
||||
|table-mode-verbose| ............ Notify when Enabled/Disabled.
|
||||
|table-mode-corner| ............. Set corner character.
|
||||
|table-mode-separator| .......... Set separator character.
|
||||
|table-mode-fillchar| ........... Set table fillchar character.
|
||||
@@ -168,11 +169,18 @@ Overview:
|
||||
|table-mode-eval-formula-map| ... Set the eval formula mapping
|
||||
|table-mode-echo-cell-map| ...... Set the echo cell mapping
|
||||
|table-mode-sort-map| ........... Set the table sort mapping
|
||||
|table-mode-syntax| ............. Control table mode syntax
|
||||
|table-mode-auto-align| ......... Set if the table mode should auto
|
||||
align as you type
|
||||
|
||||
g:loaded_table_mode *table-mode-loaded*
|
||||
Use this option to disable the plugin: >
|
||||
let g:loaded_table_mode = 1
|
||||
<
|
||||
g:table_mode_verbose *table-mode-verbose*
|
||||
Use this option to disable notifications: >
|
||||
let g:table_mode_verbose = 0
|
||||
<
|
||||
g:table_mode_corner *table-mode-corner*
|
||||
Use this option to define the table corner character: >
|
||||
let g:table_mode_corner = '+'
|
||||
@@ -291,6 +299,16 @@ g:table_mode_sort_map *table-mode-sort-map*
|
||||
current column. >
|
||||
let g:table_mode_sort_map = '<Leader>ts'
|
||||
>
|
||||
g:table_mode_syntax *table-mode-syntax*
|
||||
Control whether table mode should define table syntax definitions or
|
||||
not. >
|
||||
let g:table_mode_syntax = 1
|
||||
<
|
||||
g:table_mode_auto_align *table-mode-auto-align*
|
||||
Set if the table mode should auto align as you type when table mode is
|
||||
active. >
|
||||
let g:table_mode_auto_align = 1
|
||||
<
|
||||
|
||||
===============================================================================
|
||||
MAPPINGS *table-mode-mappings*
|
||||
|
||||
@@ -16,7 +16,7 @@ endfunction
|
||||
|
||||
" Set Global Defaults {{{1
|
||||
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
||||
call s:SetGlobalOptDefault('table_mode_verbose', 0)
|
||||
call s:SetGlobalOptDefault('table_mode_verbose', 1)
|
||||
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
||||
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
||||
call s:SetGlobalOptDefault('table_mode_header_fillchar', '-')
|
||||
@@ -44,22 +44,18 @@ call s:SetGlobalOptDefault('table_mode_eval_formula_map', '<Leader>tfe')
|
||||
call s:SetGlobalOptDefault('table_mode_echo_cell_map', '<Leader>t?')
|
||||
call s:SetGlobalOptDefault('table_mode_sort_map', '<Leader>ts')
|
||||
|
||||
call s:SetGlobalOptDefault('table_mode_syntax', 1)
|
||||
call s:SetGlobalOptDefault('table_mode_auto_align', 1)
|
||||
|
||||
function! s:TableEchoCell() "{{{1
|
||||
if tablemode#table#IsRow('.')
|
||||
echomsg '$' . tablemode#spreadsheet#RowNr('.') . ',' . tablemode#spreadsheet#ColumnNr('.')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
augroup TableMode
|
||||
au!
|
||||
|
||||
autocmd Syntax * if tablemode#IsActive() | call tablemode#SyntaxEnable() | endif
|
||||
augroup END
|
||||
|
||||
" Define Commands & Mappings {{{1
|
||||
if !g:table_mode_always_active "{{{2
|
||||
exec "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_toggle_map .
|
||||
\ " <Esc>:call tablemode#Toggle()<CR>"
|
||||
exec "nnoremap <silent>" g:table_mode_map_prefix . g:table_mode_toggle_map ":<C-U>call tablemode#Toggle()<CR>"
|
||||
command! -nargs=0 TableModeToggle call tablemode#Toggle()
|
||||
command! -nargs=0 TableModeEnable call tablemode#Enable()
|
||||
command! -nargs=0 TableModeDisable call tablemode#Disable()
|
||||
@@ -111,8 +107,8 @@ nnoremap <silent> <Plug>(table-mode-echo-cell) :call <SID>TableEchoCell()<CR>
|
||||
nnoremap <silent> <Plug>(table-mode-sort) :call tablemode#spreadsheet#Sort('')<CR>
|
||||
|
||||
if !hasmapto('<Plug>(table-mode-tableize)')
|
||||
exec "nmap " . g:table_mode_map_prefix . "t <Plug>(table-mode-tableize)"
|
||||
exec "xmap " . g:table_mode_map_prefix . "t <Plug>(table-mode-tableize)"
|
||||
exec "nmap" g:table_mode_map_prefix . "t <Plug>(table-mode-tableize)"
|
||||
exec "xmap" g:table_mode_map_prefix . "t <Plug>(table-mode-tableize)"
|
||||
endif
|
||||
|
||||
if !hasmapto('<Plug>(table-mode-tableize-delimiter)')
|
||||
|
||||
@@ -25,3 +25,6 @@ let g:table_mode_add_formula_map = '<Leader>tfa'
|
||||
let g:table_mode_eval_formula_map = '<Leader>tfe'
|
||||
let g:table_mode_echo_cell_map = '<Leader>t?'
|
||||
let g:table_mode_sort_map = '<Leader>ts'
|
||||
|
||||
let g:table_mode_syntax = 1
|
||||
let g:table_mode_auto_align = 1
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
| This | is 測試 | table |
|
||||
| This | is also | a table |
|
||||
|This|is 測試|table|
|
||||
|This|is also|a table|
|
||||
|
||||
Reference in New Issue
Block a user