mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
45 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 | ||
|
|
1bf139b30d | ||
|
|
b613e39bd0 | ||
|
|
7c56d298bb | ||
|
|
4cf1f53430 | ||
|
|
01289c0752 | ||
|
|
2ab64777a5 | ||
|
|
26b21e3454 | ||
|
|
fdfa4b12c2 | ||
|
|
e7373c9083 | ||
|
|
6872024827 | ||
|
|
50b3b01a33 | ||
|
|
5395c9f52b | ||
|
|
13d836dbfe | ||
|
|
b1e4041e43 | ||
|
|
bba1bf8d6e | ||
|
|
4baf9cfd2e | ||
|
|
8d2e013756 | ||
|
|
cc723fe8cd | ||
|
|
2c06812c39 |
@@ -1,4 +1,4 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.2.0
|
||||
- 2.3.0
|
||||
script: rake ci
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
## Version 4.6.4.1
|
||||
* Added a fix for markdown commentstring
|
||||
|
||||
## Version 4.6.4
|
||||
* Added support for center aligning columns
|
||||
|
||||
|
||||
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'
|
||||
|
||||
128
README.md
128
README.md
@@ -1,14 +1,10 @@
|
||||
# VIM Table Mode v4.6.4 [](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.
|
||||
|
||||
## Change Log
|
||||
See <a
|
||||
href="https://github.com/dhruvasagar/vim-table-mode/blob/master/CHANGELOG.md">
|
||||
CHANGELOG.md </a>
|
||||
## Getting Started
|
||||
|
||||
## Getting Started
|
||||
### Installation
|
||||
|
||||
There are several ways to do this
|
||||
@@ -30,29 +26,98 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
||||
restart VIM
|
||||
|
||||
### Usage
|
||||
### Creating table on-the-fly
|
||||
|
||||
- **On the fly table creation** :
|
||||
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>).
|
||||
|
||||
By default the table column separator is <kbd>|</kbd> defined by the
|
||||
`g:table_mode_separator` option. As soon as you type it on a new line (ignores
|
||||
indentation) the script gets to work on creating a table around it. As you
|
||||
type and define more columns, the table is completed, formatted and aligned
|
||||
automatically on the fly.
|
||||
> 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:
|
||||
|
||||
| name | address | phone |
|
||||
|
||||
In the second line (without leaving Insert mode), enter `|` twice. The plugin will write a properly formatted horizontal line:
|
||||
|
||||
| name | address | phone |
|
||||
|------+---------+-------|
|
||||
|
||||
When you enter the subsequent lines, the plugin will automatically adjust the formatting to match the text you’re entering every time you press `|`:
|
||||
|
||||
| name | address | phone |
|
||||
|------------+---------+-------|
|
||||
| John Adams |
|
||||
|
||||
Go on until the table is ready:
|
||||
|
||||
| name | address | phone |
|
||||
|-----------------+--------------------------+------------|
|
||||
| John Adams | 1600 Pennsylvania Avenue | 0123456789 |
|
||||
|-----------------+--------------------------+------------|
|
||||
| Sherlock Holmes | 221B Baker Street | 0987654321 |
|
||||
|-----------------+--------------------------+------------|
|
||||
|
||||
Then you can return to the first line and above it enter `||`:
|
||||
|
||||
|-----------------+--------------------------+------------|
|
||||
| name | address | phone |
|
||||
|-----------------+--------------------------+------------|
|
||||
| John Adams | 1600 Pennsylvania Avenue | 0123456789 |
|
||||
|-----------------+--------------------------+------------|
|
||||
| Sherlock Holmes | 221B Baker Street | 0987654321 |
|
||||
|-----------------+--------------------------+------------|
|
||||
|
||||
Corner separators are adjustable:
|
||||
|
||||
For Markdown-compatible tables use
|
||||
|
||||
let g:table_mode_corner='|'
|
||||
|
||||
|
||||
|-----------------|--------------------------|------------|
|
||||
| name | address | phone |
|
||||
|-----------------|--------------------------|------------|
|
||||
| John Adams | 1600 Pennsylvania Avenue | 0123456789 |
|
||||
|-----------------|--------------------------|------------|
|
||||
| Sherlock Holmes | 221B Baker Street | 0987654321 |
|
||||
|-----------------|--------------------------|------------|
|
||||
|
||||
To get ReST-compatible tables use
|
||||
|
||||
let g:table_mode_corner_corner='+'
|
||||
let g:table_mode_header_fillchar='='
|
||||
|
||||
|
||||
+-----------------+--------------------------+------------+
|
||||
| name | address | phone |
|
||||
+=================+==========================+============+
|
||||
| John Adams | 1600 Pennsylvania Avenue | 0123456789 |
|
||||
+-----------------+--------------------------+------------+
|
||||
| Sherlock Holmes | 221B Baker Street | 0987654321 |
|
||||
+-----------------+--------------------------+------------+
|
||||
|
||||
Since this could lead to unwanted behavior I have disabled table mode by
|
||||
default. You have to use `:TableModeToggle` command or the table mode
|
||||
toggle mapping, which is <kbd>\<Leader\>tm</kbd> defined by `g:table_mode_toggle_map`
|
||||
option to toggle the table mode or you can directly use `:TableModeEnable`
|
||||
and `:TableModeDisable` to enable or disable the table mode. This is on a
|
||||
per buffer basis and so it does not cause any unusual behavior unless it is
|
||||
enabled explicitly. Please read `:h table-mode` for further information.
|
||||
|
||||
You can also define in a table header border how it's content should be
|
||||
aligned, whether center, right or left by using a `:` character defined by
|
||||
`g:table_mode_align_char` option.
|
||||
|
||||
- **Format existing content into a table** :
|
||||
### Formatting existing content into a table
|
||||
|
||||
Table Mode wouldn't justify it's name if it didn't allow formatting
|
||||
existing content into a table. And it does as promised. Like table creation
|
||||
@@ -74,7 +139,7 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
You can use the mapping <kbd>\<Leader\>T</kbd> with a `[count]` to apply it to the
|
||||
next `[count]` lines in standard vim style.
|
||||
|
||||
- **Move between cells** :
|
||||
### Moving around
|
||||
|
||||
Now you can move between cells using table mode motions <kbd>[|</kbd>,
|
||||
<kbd>]|</kbd>, <kbd>{|</kbd> & <kbd>}|</kbd> to move left | right | up |
|
||||
@@ -82,7 +147,7 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
and move to the next | previous row after the last | first cell in the
|
||||
current row if one exists.
|
||||
|
||||
- **Manipulating Table** :
|
||||
### Manipulating Table
|
||||
|
||||
- **Cell Text Object** :
|
||||
|
||||
@@ -105,7 +170,9 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
(provided you are within a table row), this can also be preceeded with a
|
||||
[count] to delete multiple columns.
|
||||
|
||||
- **Table Formulas** :
|
||||
## Advanced Usage: Spreadsheet Capabilities
|
||||
|
||||
### Table Formulas
|
||||
|
||||
Table Mode now has support for formulas like a spreadsheet. There are 2 ways
|
||||
of defining formulas :
|
||||
@@ -129,7 +196,7 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
|
||||
NOTE: You can now use the mapping <kbd>\<Leader\>t?</kbd>
|
||||
|
||||
- **Formula Expressions** :
|
||||
### Formula Expressions
|
||||
|
||||
Expressions are of the format `$target = formula`.
|
||||
|
||||
@@ -170,10 +237,15 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
||||
- `$5,3 = Sum(1,2:5,2)/$5,1`
|
||||
- `$5,3 = Average(1,2:5,2)/$5,1`
|
||||
|
||||
### Demo
|
||||
## Demo
|
||||
|
||||
<a href="http://www.youtube.com/watch?v=sK2IH1hiDkw"><img
|
||||
src="https://raw.github.com/dhruvasagar/vim-table-mode/master/youtube.png"/></a>
|
||||
<a href="http://www.youtube.com/watch?v=9lVQ0VJY3ps"><img
|
||||
src="https://raw.github.com/axil/vim-table-mode/master/youtube.png"/></a>
|
||||
|
||||
## Change Log
|
||||
See <a
|
||||
href="https://github.com/dhruvasagar/vim-table-mode/blob/master/CHANGELOG.md">
|
||||
CHANGELOG.md </a>
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -41,7 +41,7 @@ function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
||||
if tablemode#table#IsRow(a:line)
|
||||
let line = tablemode#utils#line(a:line)
|
||||
|
||||
while tablemode#table#IsRow(line + 1) || tablemode#table#IsBorder(line + 1)
|
||||
while tablemode#table#IsTable(line + 1)
|
||||
let line += 1
|
||||
endwhile
|
||||
if tablemode#table#IsBorder(line) | let line -= 1 | endif
|
||||
@@ -61,7 +61,7 @@ function! tablemode#spreadsheet#LineNr(line, row) "{{{2
|
||||
let line = tablemode#spreadsheet#GetFirstRow(a:line)
|
||||
let row_nr = 0
|
||||
|
||||
while tablemode#table#IsRow(line + 1) || tablemode#table#IsBorder(line + 1)
|
||||
while tablemode#table#IsTable(line + 1)
|
||||
if tablemode#table#IsRow(line)
|
||||
let row_nr += 1
|
||||
if a:row ==# row_nr | break | endif
|
||||
@@ -77,7 +77,7 @@ function! tablemode#spreadsheet#RowNr(line) "{{{2
|
||||
let line = tablemode#utils#line(a:line)
|
||||
|
||||
let rowNr = 0
|
||||
while !tablemode#table#IsHeader(line) && (tablemode#table#IsRow(line) || tablemode#table#IsBorder(line))
|
||||
while !tablemode#table#IsHeader(line) && tablemode#table#IsTable(line)
|
||||
if tablemode#table#IsRow(line) | let rowNr += 1 | endif
|
||||
let line -= 1
|
||||
endwhile
|
||||
@@ -89,13 +89,13 @@ function! tablemode#spreadsheet#RowCount(line) "{{{2
|
||||
let line = tablemode#utils#line(a:line)
|
||||
|
||||
let [tline, totalRowCount] = [line, 0]
|
||||
while !tablemode#table#IsHeader(tline) && (tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline))
|
||||
while !tablemode#table#IsHeader(tline) && tablemode#table#IsTable(tline)
|
||||
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
|
||||
let tline -= 1
|
||||
endwhile
|
||||
|
||||
let tline = line + 1
|
||||
while !tablemode#table#IsHeader(tline) && (tablemode#table#IsRow(tline) || tablemode#table#IsBorder(tline))
|
||||
while !tablemode#table#IsHeader(tline) && tablemode#table#IsTable(tline)
|
||||
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
|
||||
let tline += 1
|
||||
endwhile
|
||||
|
||||
@@ -58,7 +58,7 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
||||
if row == 0
|
||||
let values = []
|
||||
let line = first_row
|
||||
while tablemode#table#IsRow(line) || tablemode#table#IsBorder(line)
|
||||
while tablemode#table#IsTable(line)
|
||||
if tablemode#table#IsRow(line)
|
||||
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
||||
call add(values, tablemode#utils#strip(get(split(row_line, g:table_mode_separator), colm>0?colm-1:colm, '')))
|
||||
@@ -70,7 +70,7 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
||||
let row_nr = 0
|
||||
let row_diff = row > 0 ? 1 : -1
|
||||
let line = row > 0 ? first_row : last_row
|
||||
while tablemode#table#IsRow(line) || tablemode#table#IsBorder(line)
|
||||
while tablemode#table#IsTable(line)
|
||||
if tablemode#table#IsRow(line)
|
||||
let row_nr += row_diff
|
||||
if row ==# row_nr | break | endif
|
||||
|
||||
@@ -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
|
||||
@@ -16,7 +19,10 @@ function! tablemode#spreadsheet#formula#Add(...) "{{{2
|
||||
if getline(fline) =~# 'tmf: '
|
||||
" Comment line correctly
|
||||
let line_val = getline(fline)
|
||||
let line_expr = line_val[match(line_val, tablemode#table#StartCommentExpr()):match(line_val, tablemode#table#EndCommentExpr())]
|
||||
let start_pos = match(line_val, tablemode#table#StartCommentExpr())
|
||||
let end_pos = match(line_val, tablemode#table#EndCommentExpr())
|
||||
if empty(end_pos) | let end_pos = len(line_val) | endif
|
||||
let line_expr = strpart(line_val, start_pos, end_pos)
|
||||
let sce = matchstr(line_val, tablemode#table#StartCommentExpr() . '\zs')
|
||||
let ece = matchstr(line_val, tablemode#table#EndCommentExpr())
|
||||
call setline(fline, sce . line_expr . '; ' . fr . ece)
|
||||
@@ -102,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
|
||||
@@ -78,7 +79,7 @@ endfunction
|
||||
function! tablemode#table#GetCommentStart() "{{{2
|
||||
let cstring = &commentstring
|
||||
if tablemode#utils#strlen(cstring) > 0
|
||||
return substitute(split(cstring, '%s')[0], '.', '\\\0', 'g')
|
||||
return substitute(split(cstring, '%s')[0], '[^()]', '\\\0', 'g')
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
@@ -98,7 +99,7 @@ function! tablemode#table#GetCommentEnd() "{{{2
|
||||
if tablemode#utils#strlen(cstring) > 0
|
||||
let cst = split(cstring, '%s')
|
||||
if len(cst) == 2
|
||||
return substitute(cst[1], '.', '\\\0', 'g')
|
||||
return substitute(cst[1], '[^()]', '\\\0', 'g')
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
@@ -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
|
||||
@@ -149,7 +150,11 @@ function! tablemode#table#IsHeader(line) "{{{2
|
||||
endfunction
|
||||
|
||||
function! tablemode#table#IsRow(line) "{{{2
|
||||
return !tablemode#table#IsBorder(a:line) && getline(a:line) =~# (tablemode#table#StartExpr() . g:table_mode_separator)
|
||||
return !tablemode#table#IsBorder(a:line) && getline(a:line) =~# (tablemode#table#StartExpr() . g:table_mode_separator) . '[^' . g:table_mode_separator . ']\+'
|
||||
endfunction
|
||||
|
||||
function! tablemode#table#IsTable(line) "{{{2
|
||||
return tablemode#table#IsRow(a:line) || tablemode#table#IsBorder(a:line)
|
||||
endfunction
|
||||
|
||||
function! tablemode#table#AddBorder(line) "{{{2
|
||||
@@ -161,7 +166,7 @@ function! tablemode#table#Realign(line) "{{{2
|
||||
|
||||
let lines = []
|
||||
let [lnum, blines] = [line, []]
|
||||
while tablemode#table#IsRow(lnum) || tablemode#table#IsBorder(lnum)
|
||||
while tablemode#table#IsTable(lnum)
|
||||
if tablemode#table#IsBorder(lnum)
|
||||
call insert(blines, lnum)
|
||||
let lnum -= 1
|
||||
@@ -172,7 +177,7 @@ function! tablemode#table#Realign(line) "{{{2
|
||||
endwhile
|
||||
|
||||
let lnum = line + 1
|
||||
while tablemode#table#IsRow(lnum) || tablemode#table#IsBorder(lnum)
|
||||
while tablemode#table#IsTable(lnum)
|
||||
if tablemode#table#IsBorder(lnum)
|
||||
call add(blines, lnum)
|
||||
let lnum += 1
|
||||
|
||||
@@ -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
|
||||
VERSION 4.6.5
|
||||
|
||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||
License: MIT <http://opensource.org/licenses/MIT/>
|
||||
@@ -86,7 +86,7 @@ Table Formulas:
|
||||
input formula will be appended to the formula line if one
|
||||
exists or a new one will be created with the input formula
|
||||
taking the current cell as the target cell. The formula line
|
||||
is evaluated immidiately to reflect the results.
|
||||
is evaluated immediately to reflect the results.
|
||||
|
||||
You can directly also add / manipulate formula expressions in
|
||||
the formula line. The formula line is a commented line right
|
||||
@@ -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*
|
||||
@@ -349,6 +367,10 @@ MAPPINGS *table-mode-mappings*
|
||||
would evaluate the formula line and update the table
|
||||
accordingly. This invokes the |TableEvalFormulaLine| command.
|
||||
|
||||
|
||||
*table-mode-mappings-sort-column*
|
||||
<Leader>ts Sort a column under the cursor. This invokes |TableSort|
|
||||
|
||||
|| Expands to a header border. You can change this by changing
|
||||
|table-mode-separator| option. You can change the character to
|
||||
be used for te extreme corners of the border by changing
|
||||
@@ -416,6 +438,14 @@ COMMANDS *table-mode-commands*
|
||||
This command when invoked from anywhere within the table or directly
|
||||
on the formula line evaluates it and updates the table accordingly.
|
||||
|
||||
*:TableSort*
|
||||
*table-mode-:TableSort*
|
||||
:TableSort[!] [i][u][r][n][x][o]
|
||||
This command sorts column under the cursor and inherits the same flags
|
||||
as the |:sort| command.
|
||||
|
||||
With [!] the order is reversed.
|
||||
|
||||
===============================================================================
|
||||
CONTRIBUTING *table-mode-contributing*
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -108,11 +104,11 @@ nnoremap <silent> <Plug>(table-mode-eval-formula) :call tablemode#spreadsheet#fo
|
||||
|
||||
nnoremap <silent> <Plug>(table-mode-echo-cell) :call <SID>TableEchoCell()<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(table-mode-sort) :call tablemode#spreadsheet#Sort()<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|
|
||||
|
||||
@@ -19,7 +19,7 @@ describe 'Formulas'
|
||||
call tablemode#spreadsheet#formula#Add("Sum(1:-1)")
|
||||
Expect tablemode#spreadsheet#cell#GetCell() == '250.0'
|
||||
call cursor(8, 15)
|
||||
Expect getline('.') == '/* tmf: $4,2=Sum(1:3) ; $5,2=Sum(1:-1) */'
|
||||
Expect getline('.') == '/* tmf: $4,2=Sum(1:3); $5,2=Sum(1:-1) */'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
23
t/table.vim
23
t/table.vim
@@ -40,6 +40,29 @@ describe 'table'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'IsTable'
|
||||
before
|
||||
new normal! ggdG
|
||||
read t/fixtures/table/sample_with_header.txt
|
||||
end
|
||||
|
||||
it 'should be true on a table row'
|
||||
Expect tablemode#table#IsTable(2) to_be_true
|
||||
Expect tablemode#table#IsTable(4) to_be_true
|
||||
Expect tablemode#table#IsTable(5) to_be_true
|
||||
end
|
||||
|
||||
it 'should be true when on a table border'
|
||||
Expect tablemode#table#IsTable(1) to_be_true
|
||||
Expect tablemode#table#IsTable(3) to_be_true
|
||||
Expect tablemode#table#IsTable(6) to_be_true
|
||||
end
|
||||
|
||||
it 'should not be true when not on a table'
|
||||
Expect tablemode#table#IsTable(7) to_be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'IsHeader'
|
||||
before
|
||||
new
|
||||
|
||||
BIN
youtube.png
BIN
youtube.png
Binary file not shown.
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 43 KiB |
Reference in New Issue
Block a user