Compare commits

...

25 Commits

Author SHA1 Message Date
Dhruva Sagar
ef66b3ec2f Revert "Also auto realign on InsertLeave #73"
This reverts commit 6584cee4a4.
2017-03-09 15:02:42 +05:30
Dhruva Sagar
6584cee4a4 Also auto realign on InsertLeave #73 2017-03-09 14:24:15 +05:30
Dhruva Sagar
1eef73fc5b Add option to auto align table while editing #73 2017-03-09 11:00:19 +05:30
Dhruva Sagar
d3b70df0a6 Merge pull request #112 from polyzen/patch-1
readme: Fix minor Vint (Vim linter) warnings
2017-03-08 16:25:11 +05:30
Daniel M. Capella
096165718e readme: Fix minor Vint (Vim linter) warnings 2017-03-08 06:59:39 +00:00
Dhruva Sagar
30a3eba816 Fix #103 : Refactored border creation
Border creation should not conflict with the contents of the row
2017-01-05 11:42:10 +05:30
Dhruva Sagar
cc0055f329 Fixed align unicode fixture
The before fixture should not have any unnecessary spaces
2017-01-04 16:15:46 +05:30
Dhruva Sagar
8d3affcf5f Minor refactor for table syntax 2017-01-04 16:03:24 +05:30
Dhruva Sagar
9edd6d7d20 Add config to disable table mode syntax
Since table mode syntax can hamper performance, it is now possible to
disable it with a global config
2017-01-04 15:49:35 +05:30
Dhruva Sagar
441c30c35a Merge pull request #98 from harriott/master
enabling toggle notification by default
2016-09-28 19:27:31 +05:30
Joseph Harriott
ebd16eef19 Merge remote-tracking branch 'gh/master' 2016-09-28 15:39:23 +02:00
Joseph Harriott
141efc3edd corrected spurious loaded_table_verbose 2016-09-28 15:29:07 +02:00
Joseph Harriott
c82bc292c5 deleted tags, as requested 2016-09-27 23:30:29 +02:00
Dhruva Sagar
8209b59215 Bumped the version 2016-09-21 14:07:59 +05:30
Dhruva Sagar
5b3b2f7c05 Updated the README
Fixed the tip
2016-09-21 14:05:56 +05:30
harriott
47f60d2972 doc adjusted for default verbose 2016-09-09 11:03:00 +02:00
harriott
0f680bfd1b 'table_mode_verbose', 1 2016-09-09 10:53:18 +02:00
harriott
19f2f5c26f reset gitignore tags 2016-09-09 10:50:30 +02:00
harriott
e07c240940 fixed logger.vim and announce g:table_mode_verbose 2016-09-09 10:39:01 +02:00
Dhruva Sagar
8bacd0ba66 Bumped ruby version for travis 2016-08-23 09:29:00 +05:30
Dhruva Sagar
8309a33aa7 Fix #90
Allow for multiple formula lines
2016-08-23 09:26:24 +05:30
Dhruva Sagar
293c847cdf Bumped ruby version for tests 2016-08-23 09:25:56 +05:30
Dhruva Sagar
96236638a8 Fix #92
Improved mappings for table mode
2016-07-11 13:39:28 +05:30
Dhruva Sagar
1d14a027a8 Merge branch 'master' of github.com:dhruvasagar/vim-table-mode 2016-07-11 13:24:27 +05:30
Dhruva Sagar
e490373435 Fix #88
Added the iabbrevs to README
2016-07-11 13:23:37 +05:30
11 changed files with 98 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
language: ruby
rvm:
- 2.2.0
- 2.3.0
script: rake ci

View File

@@ -1,5 +1,5 @@
source 'https://rubygems.org'
ruby '2.2.0'
ruby '2.3.0'
gem 'rake'
gem 'vim-flavor', '~> 1.1'

View File

@@ -1,4 +1,4 @@
# VIM Table Mode v4.6.4.1 [![Build Status](https://travis-ci.org/dhruvasagar/vim-table-mode.png?branch=master)](https://travis-ci.org/dhruvasagar/vim-table-mode)
# VIM Table Mode v4.6.5 [![Build Status](https://travis-ci.org/dhruvasagar/vim-table-mode.png?branch=master)](https://travis-ci.org/dhruvasagar/vim-table-mode)
An awesome automatic table creator & formatter allowing one to create neat
tables as you type.
@@ -28,25 +28,25 @@ $ 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>' : '__'
>
> fun! <SID>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$')
> endf
> ```
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:
@@ -87,7 +87,7 @@ Corner separators are adjustable:
For Markdown-compatible tables use
let g:table_mode_corner="|"
let g:table_mode_corner='|'
|-----------------|--------------------------|------------|
@@ -100,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='='
+-----------------+--------------------------+------------+

View File

@@ -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

View File

@@ -1,5 +1,5 @@
function! tablemode#logger#log(message)
if g:table_mode_verbose
echom message
echom a:message
endif
endfunction

View File

@@ -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

View File

@@ -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

View File

@@ -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*

View File

@@ -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)')

View File

@@ -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

View File

@@ -1,2 +1,2 @@
| This | is 測試 | table |
| This | is also | a table |
|This|is 測試|table|
|This|is also|a table|