mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
766066394c | ||
|
|
f2f62d78e5 | ||
|
|
7810ce0ca0 | ||
|
|
b22d793135 | ||
|
|
de2ad0b71d | ||
|
|
29c7ec1a23 | ||
|
|
9ce981cc77 |
@@ -1,4 +1,9 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
## Version 4.4.0
|
||||||
|
* Minor bug fixes
|
||||||
|
* Added feature to allow using negative indices within formulas to access rows,
|
||||||
|
columns relative to the last, -1 being the last.
|
||||||
|
|
||||||
## Version 4.3.0
|
## Version 4.3.0
|
||||||
* Refactored some more
|
* Refactored some more
|
||||||
* Fixed issue #19, hiphens in the table broke alignment
|
* Fixed issue #19, hiphens in the table broke alignment
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,4 +1,4 @@
|
|||||||
# VIM Table Mode v4.3.0 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
# VIM Table Mode v4.4.0 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
||||||
|
|
||||||
An awesome automatic table creator & formatter allowing one to create neat
|
An awesome automatic table creator & formatter allowing one to create neat
|
||||||
tables as you type.
|
tables as you type.
|
||||||
@@ -48,6 +48,10 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
|||||||
per buffer basis and so it does not cause any unusual behavior unless it is
|
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.
|
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 right or left by using a `:` character defined by
|
||||||
|
`g:table_mode_align_char` option.
|
||||||
|
|
||||||
- **Format existing content into a table** :
|
- **Format existing content into a table** :
|
||||||
|
|
||||||
Table Mode wouldn't justify it's name if it didn't allow formatting
|
Table Mode wouldn't justify it's name if it didn't allow formatting
|
||||||
@@ -133,11 +137,13 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
|||||||
|
|
||||||
- `$n`: This matches the table column number `n`. So the `formula` would
|
- `$n`: This matches the table column number `n`. So the `formula` would
|
||||||
be evaluated for each cell in that column and the result would be placed
|
be evaluated for each cell in that column and the result would be placed
|
||||||
in it.
|
in it. You can use negative indice to represent column relative to the
|
||||||
|
last, -1 being the last.
|
||||||
|
|
||||||
- `$n,m`: This matches the table cell n,m (row, column). So in this case
|
- `$n,m`: This matches the table cell n,m (row, column). So in this case
|
||||||
the formula would be evaluated and the result will be placed in this
|
the formula would be evaluated and the result will be placed in this
|
||||||
cell.
|
cell. You can also use negative values to refer to cells relative to
|
||||||
|
the size, -1 being the last (row or column).
|
||||||
|
|
||||||
- The `formula` can be a simple mathematical expression involving cells
|
- The `formula` can be a simple mathematical expression involving cells
|
||||||
which are also defined by the same format as that of the target cell. You
|
which are also defined by the same format as that of the target cell. You
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ function! s:SetActive(bool) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
||||||
let gflag = 'g'
|
let old_gdefault = &gdefault
|
||||||
if &gdefault | let gflag = 'gg' | endif
|
set nogdefault
|
||||||
|
|
||||||
let delim = g:table_mode_delimiter
|
let delim = g:table_mode_delimiter
|
||||||
if a:0 | let delim = a:1 | endif
|
if a:0 | let delim = a:1 | endif
|
||||||
if delim ==# ','
|
if delim ==# ','
|
||||||
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs,\\ze[^\'\"]*[\'\"]/__COMMA__/" . gflag
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs,\\ze[^\'\"]*[\'\"]/__COMMA__/g"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [cstart, cend] = [tablemode#table#GetCommentStart(), tablemode#table#GetCommentEnd()]
|
let [cstart, cend] = [tablemode#table#GetCommentStart(), tablemode#table#GetCommentEnd()]
|
||||||
@@ -67,11 +67,13 @@ function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
|||||||
|
|
||||||
silent! execute a:line . 's/' . tablemode#table#StartExpr() . '\zs\ze' . match_char_start .
|
silent! execute a:line . 's/' . tablemode#table#StartExpr() . '\zs\ze' . match_char_start .
|
||||||
\ '\|' . delim . '\|' . match_char_end . '\zs\ze' . tablemode#table#EndExpr() . '/' .
|
\ '\|' . delim . '\|' . match_char_end . '\zs\ze' . tablemode#table#EndExpr() . '/' .
|
||||||
\ g:table_mode_separator . '/' . gflag
|
\ g:table_mode_separator . '/g'
|
||||||
|
|
||||||
if delim ==# ','
|
if delim ==# ','
|
||||||
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs__COMMA__\\ze[^\'\"]*[\'\"]/,/" . gflag
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs__COMMA__\\ze[^\'\"]*[\'\"]/,/g"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let &gdefault=old_gdefault
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Tableizeline(line, ...) "{{{2
|
function! s:Tableizeline(line, ...) "{{{2
|
||||||
|
|||||||
@@ -118,12 +118,14 @@ function! tablemode#align#Split(string, delim)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#align#alignments(lnum, ncols) "{{{2
|
function! tablemode#align#alignments(lnum, ncols) "{{{2
|
||||||
let alignments = repeat(['l'], a:ncols) " For each column
|
let alignments = []
|
||||||
if tablemode#table#IsHeader(a:lnum+1)
|
if tablemode#table#IsHeader(a:lnum+1)
|
||||||
let hcols = tablemode#align#Split(getline(a:lnum+1), '[' . g:table_mode_corner . g:table_mode_corner_corner . ']')
|
let hcols = tablemode#align#Split(getline(a:lnum+1), '[' . g:table_mode_corner . g:table_mode_corner_corner . ']')
|
||||||
for idx in range(len(hcols))
|
for idx in range(len(hcols))
|
||||||
" Right align if header
|
" Right align if header
|
||||||
|
call add(alignments, 'l')
|
||||||
if hcols[idx] =~# g:table_mode_align_char . '$' | let alignments[idx] = 'r' | endif
|
if hcols[idx] =~# g:table_mode_align_char . '$' | let alignments[idx] = 'r' | endif
|
||||||
|
if hcols[idx] !~# '[^0-9\.]' | let alignments[idx] = 'r' | endif
|
||||||
endfor
|
endfor
|
||||||
end
|
end
|
||||||
return alignments
|
return alignments
|
||||||
@@ -166,9 +168,11 @@ function! tablemode#align#Align(lines) "{{{2
|
|||||||
let tline = lines[idx].text
|
let tline = lines[idx].text
|
||||||
|
|
||||||
if len(tline) <= 1 | continue | endif
|
if len(tline) <= 1 | continue | endif
|
||||||
for i in range(len(tline))
|
for jdx in range(len(tline))
|
||||||
let field = s:Padding(tline[i], maxes[i], alignments[i])
|
" Dealing with the header being the first line
|
||||||
let tline[i] = field . (i == 0 || i == len(tline) ? '' : ' ')
|
if jdx >= len(alignments) | call add(alignments, 'l') | endif
|
||||||
|
let field = s:Padding(tline[jdx], maxes[jdx], alignments[jdx])
|
||||||
|
let tline[jdx] = field . (jdx == 0 || jdx == len(tline) ? '' : ' ')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let lines[idx].text = s:StripTrailingSpaces(join(tline, ''))
|
let lines[idx].text = s:StripTrailingSpaces(join(tline, ''))
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let first_row = tablemode#spreadsheet#GetFirstRow(line)
|
let first_row = tablemode#spreadsheet#GetFirstRow(line)
|
||||||
|
let last_row = tablemode#spreadsheet#GetLastRow(line)
|
||||||
if row == 0
|
if row == 0
|
||||||
let values = []
|
let values = []
|
||||||
let line = first_row
|
let line = first_row
|
||||||
@@ -94,13 +95,14 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
|||||||
return values
|
return values
|
||||||
else
|
else
|
||||||
let row_nr = 0
|
let row_nr = 0
|
||||||
let line = first_row
|
let row_diff = row > 0 ? 1 : -1
|
||||||
|
let line = row > 0 ? first_row : last_row
|
||||||
while tablemode#table#IsRow(line) || tablemode#table#IsHeader(line)
|
while tablemode#table#IsRow(line) || tablemode#table#IsHeader(line)
|
||||||
if tablemode#table#IsRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let row_nr += 1
|
let row_nr += row_diff
|
||||||
if row ==# row_nr | break | endif
|
if row ==# row_nr | break | endif
|
||||||
endif
|
endif
|
||||||
let line += 1
|
let line += row_diff
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
||||||
@@ -193,6 +195,10 @@ function! tablemode#spreadsheet#cell#SetCell(val, ...) "{{{2
|
|||||||
let [line, row, colm] = a:000
|
let [line, row, colm] = a:000
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Account for negative values to reference from relatively from the last
|
||||||
|
if row < 0 | let row = tablemode#spreadsheet#RowCount(line) + row + 1 | endif
|
||||||
|
if colm < 0 | let colm = tablemode#spreadsheet#ColumnCount(line) + colm + 1 | endif
|
||||||
|
|
||||||
if tablemode#table#IsRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let line = tablemode#utils#line(line) + (row - tablemode#spreadsheet#RowNr(line)) * 1
|
let line = tablemode#utils#line(line) + (row - tablemode#spreadsheet#RowNr(line)) * 1
|
||||||
let line_val = getline(line)
|
let line_val = getline(line)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v4.3.0
|
*table-mode.txt* Table Mode for easy table formatting. v4.4.0
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 4.3.0
|
VERSION 4.4.0
|
||||||
|
|
||||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
License: MIT <http://opensource.org/licenses/MIT/>
|
License: MIT <http://opensource.org/licenses/MIT/>
|
||||||
@@ -104,11 +104,14 @@ Formula Expressions :
|
|||||||
|
|
||||||
'$n': This matches the table column number 'n'. So the formula
|
'$n': This matches the table column number 'n'. So the formula
|
||||||
would be evaluated for each cell in that column and the result
|
would be evaluated for each cell in that column and the result
|
||||||
would be placed in it.
|
would be placed in it. You can use negative indice to
|
||||||
|
represent column relative to the last, -1 being the last.
|
||||||
|
|
||||||
'$n,m': This matches the table cell n,m (row, column). So in
|
'$n,m': This matches the table cell n,m (row, column). So in
|
||||||
this case the formula would be evaluated and the result will
|
this case the formula would be evaluated and the result will
|
||||||
be placed in this cell.
|
be placed in this cell. You can also use negative values to
|
||||||
|
refer to cells relative to the size, -1 being the last (row or
|
||||||
|
column).
|
||||||
|
|
||||||
The formula can be a simple mathematical expression involving cells
|
The formula can be a simple mathematical expression involving cells
|
||||||
which are also defined by the same format as that of the target cell.
|
which are also defined by the same format as that of the target cell.
|
||||||
|
|||||||
Reference in New Issue
Block a user