mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e94bbcc0b4 | ||
|
|
a0618db019 | ||
|
|
176999f347 | ||
|
|
5a6a9b3473 | ||
|
|
aa8817621c | ||
|
|
54187d0be1 | ||
|
|
3e2eaeee5c | ||
|
|
6dfc508af5 | ||
|
|
ed441f19a1 | ||
|
|
e4525c465a | ||
|
|
19bfa092a3 | ||
|
|
f91ec2458f |
@@ -1,4 +1,4 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 1.9.3
|
||||
script: rake ci
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
# Change Log
|
||||
## Version 3.2
|
||||
* Added tests to test various use cases using <a
|
||||
href='https://github.com/kana/vim-vspec'>Vspec</a>..
|
||||
* Added travis integration for automated tests.
|
||||
|
||||
## Version 3.1
|
||||
* Removed borders. You can now optionally create a table header by simply
|
||||
adding a header border immidiately after the header line by using the
|
||||
|
||||
14
README.md
14
README.md
@@ -1,4 +1,4 @@
|
||||
# VIM Table Mode
|
||||
# VIM Table Mode [](https://travis-ci.org/dhruvasagar/soulmate_rails)
|
||||
|
||||
An awesome automatic table creator & formatter allowing one to create neat
|
||||
tables as you type.
|
||||
@@ -11,17 +11,21 @@ CHANGELOG.md </a>
|
||||
## Getting Started
|
||||
### Installation
|
||||
|
||||
There are 2 ways to do this
|
||||
There are several ways to do this
|
||||
|
||||
1. I recommend installing <a
|
||||
href="https://github.com/tpope/vim-pathogen">pathogen.vim</a> and then
|
||||
adding a git submodule for your plugin:
|
||||
href="https://github.com/Shougo/neobundle.vim">NeoBundle</a> and then just
|
||||
add `NeoBundle 'dhruvasagar/vim-table-mode'` to your ~/.vimrc
|
||||
|
||||
2. If you are using <a
|
||||
href="https://github.com/tpope/vim-pathogen">pathogen.vim</a>, then
|
||||
add a git submodule for your plugin:
|
||||
|
||||
```sh
|
||||
$ cd ~/.vim
|
||||
$ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode
|
||||
```
|
||||
2. Copy autoload/todomode.vim, plugin/todo-mode.vim, doc/todo-mode.txt to
|
||||
3. Copy autoload/todomode.vim, plugin/todo-mode.vim, doc/todo-mode.txt to
|
||||
respective ~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
|
||||
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
||||
restart VIM
|
||||
|
||||
@@ -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.
|
||||
@@ -113,9 +113,6 @@ function! s:StartExpr() "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HeaderBorderExpr() "{{{2
|
||||
return '^\s*' . g:table_mode_corner . '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' . g:table_mode_corner . '$'
|
||||
endfunction
|
||||
|
||||
function! s:EndExpr() "{{{2
|
||||
let cend = s:GetCommentEnd()
|
||||
@@ -126,6 +123,14 @@ function! s:EndExpr() "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HeaderBorderExpr() "{{{2
|
||||
return s:StartExpr() .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ s:EndExpr()
|
||||
endfunction
|
||||
|
||||
function! s:StartCommentExpr() "{{{2
|
||||
let cstartexpr = s:GetCommentStart()
|
||||
if s:Strlen(cstartexpr) > 0
|
||||
@@ -164,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 "inoreabbrev <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 "iunabbrev <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -179,12 +179,28 @@ 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())
|
||||
let line_val = getline(line - s:RowGap())
|
||||
if tablemode#IsATableRow(line - s:RowGap()) || tablemode#IsATableRow(line + s:RowGap())
|
||||
let line_val = ''
|
||||
if tablemode#IsATableRow(line + s:RowGap())
|
||||
let line_val = getline(line + s:RowGap())
|
||||
endif
|
||||
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 , '')
|
||||
|
||||
let cstartexpr = s:StartCommentExpr()
|
||||
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||
@@ -197,6 +213,8 @@ function! s:GenerateHeaderBorder(line) "{{{2
|
||||
else
|
||||
return border
|
||||
endif
|
||||
else
|
||||
return s:DefaultHeaderBorder()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -643,31 +661,26 @@ function! tablemode#TableRealign(line) "{{{2
|
||||
let line = s:Line(a:line)
|
||||
|
||||
let [lnums, lines] = [[], []]
|
||||
let [bline, tline] = [0, line]
|
||||
while tablemode#IsATableRow(tline)
|
||||
let [tline, blines] = [line, []]
|
||||
while tablemode#IsATableRow(tline) || getline(tline) =~# s:HeaderBorderExpr()
|
||||
if getline(tline) =~# s:HeaderBorderExpr()
|
||||
call insert(blines, tline)
|
||||
let tline = tline - s:RowGap()
|
||||
continue
|
||||
endif
|
||||
call insert(lnums, tline)
|
||||
call insert(lines, getline(tline))
|
||||
let tline = tline - s:RowGap()
|
||||
endwhile
|
||||
|
||||
" If we reached header walking upwards
|
||||
if getline(tline) =~# s:HeaderBorderExpr() && tablemode#IsATableRow(tline - s:RowGap())
|
||||
let bline = tline
|
||||
let tline = tline - s:RowGap()
|
||||
" Insert the header line
|
||||
call insert(lnums, tline)
|
||||
call insert(lines, getline(tline))
|
||||
endif
|
||||
|
||||
let tline = line + s:RowGap()
|
||||
|
||||
" If we start at header
|
||||
if !bline && getline(tline) =~# s:HeaderBorderExpr()
|
||||
let bline = tline
|
||||
let tline = tline + s:RowGap()
|
||||
endif
|
||||
|
||||
while tablemode#IsATableRow(tline)
|
||||
while tablemode#IsATableRow(tline) || getline(tline) =~# s:HeaderBorderExpr()
|
||||
if getline(tline) =~# s:HeaderBorderExpr()
|
||||
call insert(blines, tline)
|
||||
let tline = tline + s:RowGap()
|
||||
continue
|
||||
endif
|
||||
call add(lnums, tline)
|
||||
call add(lines, getline(tline))
|
||||
let tline = tline + s:RowGap()
|
||||
@@ -680,15 +693,19 @@ function! tablemode#TableRealign(line) "{{{2
|
||||
call setline(lnum, lines[index])
|
||||
endfor
|
||||
|
||||
if bline
|
||||
for bline in blines
|
||||
call tablemode#AddHeaderBorder(bline)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableRow(line) "{{{2
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator)
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator . '[^' .
|
||||
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableHeader(line) "{{{2
|
||||
return getline(a:line) =~# s:HeaderBorderExpr()
|
||||
endfunction
|
||||
|
||||
function! tablemode#LineNr(row) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
@@ -754,7 +771,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
if a:direction ==# 'l'
|
||||
if s:IsLastCell()
|
||||
if !tablemode#IsATableRow(line('.') + s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') + s:RowGap()) && !tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('j')
|
||||
normal! 0
|
||||
endif
|
||||
@@ -767,7 +786,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
endif
|
||||
elseif a:direction ==# 'h'
|
||||
if s:IsFirstCell()
|
||||
if !tablemode#IsATableRow(line('.') - s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') - s:RowGap()) && !tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('k')
|
||||
normal! $
|
||||
endif
|
||||
@@ -779,9 +800,17 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
||||
endif
|
||||
elseif a:direction ==# 'j'
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap()) | execute 'normal ' . s:RowGap() . 'j' | endif
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'j'
|
||||
elseif tablemode#IsATableHeader(line('.') + s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'j'
|
||||
endif
|
||||
elseif a:direction ==# 'k'
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap()) | execute 'normal ' . s:RowGap() . 'k' | endif
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'k'
|
||||
elseif tablemode#IsATableHeader(line('.') - s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'k'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
@@ -802,7 +831,21 @@ endfunction
|
||||
function! tablemode#DeleteColumn() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
call s:MoveToFirstRow()
|
||||
call s:MoveToStartOfCell()
|
||||
|
||||
if tablemode#IsATableRow(line('.') + 1)
|
||||
call s:MoveToFirstRow()
|
||||
" If we have a header delete it first
|
||||
if tablemode#IsATableRow(line('.')-2)
|
||||
call cursor(line('.')-2, col('.'))
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
else " We're already on the header
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
|
||||
call s:MoveToStartOfCell()
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
call s:MoveToLastRow()
|
||||
@@ -816,15 +859,11 @@ endfunction
|
||||
function! tablemode#DeleteRow() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
if tablemode#RowCount('.') ==# 1
|
||||
normal! kVjjd
|
||||
else
|
||||
normal! kVjd
|
||||
if tablemode#IsATableRow('.')
|
||||
normal! dd
|
||||
endif
|
||||
|
||||
if tablemode#IsATableRow(line('.')+1)
|
||||
normal! j
|
||||
else
|
||||
if !tablemode#IsATableRow('.')
|
||||
normal! k
|
||||
endif
|
||||
endfor
|
||||
@@ -873,6 +912,7 @@ function! tablemode#AddFormula() "{{{2
|
||||
if fr !=# ''
|
||||
let fr = '$' . row . ',' . colm . '=' . fr
|
||||
let fline = tablemode#GetLastRow('.') + s:RowGap()
|
||||
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
||||
let cursor_pos = [line('.'), col('.')]
|
||||
if getline(fline) =~# 'tmf: '
|
||||
" Comment line correctly
|
||||
@@ -961,11 +1001,14 @@ function! tablemode#EvaluateFormulaLine() abort "{{{2
|
||||
endif
|
||||
if tablemode#IsATableRow('.') " We're inside the table
|
||||
let line = s:GetLastRow('.')
|
||||
if getline(line + s:RowGap()) =~# 'tmf: '
|
||||
let exprs = split(matchstr(getline(line + s:RowGap()), matchexpr), ';')
|
||||
let fline = line + s:RowGap()
|
||||
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
||||
if getline(fline) =~# 'tmf: '
|
||||
let exprs = split(matchstr(getline(fline), matchexpr), ';')
|
||||
endif
|
||||
elseif getline('.') =~# 'tmf: ' " We're on the formula line
|
||||
let line = line('.') - s:RowGap()
|
||||
if getline(line) =~# s:HeaderBorderExpr() | let line -= s:RowGap() | endif
|
||||
if tablemode#IsATableRow(line)
|
||||
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
||||
endif
|
||||
|
||||
@@ -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/>
|
||||
@@ -29,7 +29,7 @@ GETTING STARTED *table-mode-getting-started*
|
||||
|
||||
Create Table on the fly:
|
||||
Using Table Mode is dead simple. You simply start typing on a new line
|
||||
with the table separator - |g:table-mode-separator|, and you just type
|
||||
with the table separator - |table-mode-separator|, and you just type
|
||||
away! The plugin does the rest automatically for you as you type. With
|
||||
each additional separator you add, it aligns the table properly,
|
||||
without having to do anything else.
|
||||
@@ -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*
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user