Compare commits

...

50 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
Dhruva Sagar
b420dedbf5 Fix #88
Added the iabbrevs to README
2016-07-11 13:22:12 +05:30
Dhruva Sagar
1bf139b30d Bumped version 2016-05-09 09:07:40 +05:30
Dhruva Sagar
b613e39bd0 Fix #89
Unescape special characters () within the commmentstring
2016-05-08 15:57:13 +05:30
Dhruva Sagar
7c56d298bb Updated test for formula validation 2016-05-08 15:56:48 +05:30
Dhruva Sagar
4cf1f53430 Fix #86
Fixed issue with table formula addition when there exists one already
and the comment string is singular, i.e. no end delimiter.
2016-04-09 12:55:29 +05:30
Dhruva Sagar
01289c0752 Merge branch 'master' of github.com:dhruvasagar/vim-table-mode 2015-12-03 22:53:41 +05:30
Dhruva Sagar
2ab64777a5 Merge pull request #75 from hein09/patch-1
Fixed sort in doc
2015-12-03 21:11:39 +05:30
hein09
26b21e3454 Fixed sort in doc
Fixed sort-parts in documentation breaking the help-tag-indexing of vim
2015-12-03 15:48:18 +01:00
Dhruva Sagar
fdfa4b12c2 Add tablemode#table#IsTable 2015-11-23 14:53:05 +05:30
Dhruva Sagar
e7373c9083 Merge pull request #71 from arecarn/fix-sort
Fix sort command, and add documentation for the command and mapping.
2015-11-17 06:43:19 +01:00
Ryan Carney
6872024827 add docs for table sorting command and mapping
----
Related Issues: #38
2015-11-15 14:46:47 -08:00
Ryan Carney
50b3b01a33 fix mapping to table sort
Symptom:
when trying to sort a column using <leader>ts the following error would
be displayed:

     E119: Not enough arguments for function: tablemode#spreadsheet#Sort

Problem:
Function call tablemode#spreadsheet#Sort() was missing a arguemnts for
it's named parameter bang.

Solution:
Add a blank value of '' as the argument for the bang parameter

----
Related Issues: #38
2015-11-15 14:45:05 -08:00
Dhruva Sagar
5395c9f52b Merge pull request #65 from axil/master
Updated readme
2015-06-05 06:22:58 -07:00
Lev Maximov
13d836dbfe included header_fillchar into the rst example 2015-06-05 11:28:55 +06:00
Lev Maximov
b1e4041e43 changed the video to a more recent one 2015-06-05 02:15:11 +06:00
Lev Maximov
bba1bf8d6e restructured the headers 2015-06-05 02:15:11 +06:00
Lev Maximov
4baf9cfd2e more detailed how-to-start instructions, with pictures 2015-06-05 02:14:50 +06:00
Dhruva Sagar
8d2e013756 Updated youtube video
* Updated the youtube video link to the more recent video.
2015-06-04 10:29:49 -07:00
Dhruva Sagar
cc723fe8cd Merge pull request #61 from rafaeln/patch-1
fix table in table-mode.txt
2015-04-21 13:48:06 -07:00
rafaeln
2c06812c39 fix table in table-mode.txt
immidiately --> immediately
2015-04-21 16:13:55 -03:00
Dhruva Sagar
2471a3b1da Updated docs 2015-04-14 15:57:49 -07:00
Dhruva Sagar
74d1492f2b Add support for center alignment. Fix #57
We now have support for center alignment, simply add a header border
with the `g:table_mode_align_char` as both the first and the last
character so it would look something like `+:.....:+` to center align
the column values.
2015-04-14 15:56:09 -07:00
Dhruva Sagar
c0a6d43f21 Updated ruby version in travis 2015-03-17 15:43:02 -07:00
Dhruva Sagar
af182b1387 Updated README
* Updated documentation with regards to manual installation
2015-03-17 13:53:24 -07:00
Dhruva Sagar
757d1f95eb Updated ruby version 2015-03-17 13:50:26 -07:00
22 changed files with 279 additions and 110 deletions

View File

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

View File

@@ -1,5 +1,11 @@
# Change Log
## Version 4.6.4.1
* Added a fix for markdown commentstring
## Version 4.6.4
* Added support for center aligning columns
## Version 4.6.3
* Fixed tablemode#spreadsheet#LineNr()
* Fixed tablemode#spreadsheet#cell#SetCell()

View File

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

134
README.md
View File

@@ -1,14 +1,10 @@
# VIM Table Mode v4.6.3 [![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.
## 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
@@ -25,34 +21,103 @@ There are several ways to do this
$ cd ~/.vim
$ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode
```
3. Copy autoload/tablemode.vim, plugin/table-mode.vim, doc/table-mode.txt to
respective ~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
3. Copy all files under autoload/, plugin/, doc/ to respective
~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
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 youre 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 right or left by using a `:` character defined by
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

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

@@ -13,7 +13,7 @@ function! s:Padding(string, length, where) "{{{3
elseif a:where =~# 'r'
return repeat(" ", gap_length) . a:string
elseif a:where =~# 'c'
let right = spaces / 2
let right = gap_length / 2
let left = right + (right * 2 != gap_length)
return repeat(" ", left) . a:string . repeat(" ", right)
endif
@@ -64,14 +64,19 @@ function! tablemode#align#Split(string, delim)
endfunction
function! tablemode#align#alignments(lnum, ncols) "{{{2
let achr = g:table_mode_align_char
let alignments = []
if tablemode#table#IsBorder(a:lnum+1)
let hcols = tablemode#align#Split(getline(a:lnum+1), '[' . g:table_mode_corner . g:table_mode_corner_corner . ']')
for idx in range(len(hcols))
" Right align if header
call add(alignments, 'l')
if hcols[idx] =~# g:table_mode_align_char . '$' | let alignments[idx] = 'r' | endif
if hcols[idx] !~# '[^0-9\.]' | let alignments[idx] = 'r' | endif
if hcols[idx] =~# achr . '[^'.achr.']\+' . achr
let alignments[idx] = 'c'
elseif hcols[idx] =~# achr . '$'
let alignments[idx] = 'r'
endif
" if hcols[idx] !~# '[^0-9\.]' | let alignments[idx] = 'r' | endif
endfor
end
return alignments

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

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

View File

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

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

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
@@ -45,7 +46,10 @@ function! s:GenerateHeaderBorder(line) "{{{2
for idx in range(len(hcols))
if hcols[idx] =~# g:table_mode_align_char
if hcols[idx] =~# g:table_mode_align_char . '$'
" center align
if hcols[idx] =~# g:table_mode_align_char . '[^'.g:table_mode_align_char.']\+' . g:table_mode_align_char
let gcols[idx] = g:table_mode_align_char . gcols[idx][1:-2] . g:table_mode_align_char
elseif hcols[idx] =~# g:table_mode_align_char . '$'
let gcols[idx] = gcols[idx][:-2] . g:table_mode_align_char
else
let gcols[idx] = g:table_mode_align_char . gcols[idx][1:]
@@ -75,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
@@ -95,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
@@ -132,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
@@ -146,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
@@ -158,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
@@ -169,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

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.3
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*

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

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|

View File

@@ -1,4 +1,4 @@
| Title | Message |
|------:+--------:|
| t1 | msg1 |
| t2 | msg2 |
| S. No | Title | Message |
|-------+:------+:-------:|
| 1 | t1 | msg1 |
| 2 | t2 | msg2 |

View File

@@ -1,4 +1,4 @@
| Title | Message |
|------:+--------:|
| t1 | msg1 |
| t2 | msg2 |
|S. No|Title|Message|
|-----+:----+:-----:|
|1|t1|msg1|
|2|t2|msg2|

View File

@@ -1,8 +1,8 @@
|--------------+------------------+------------|
| 测试测试 | 测试长度 | 长测试 |
|--------------+------------------+-----------:|
| abc | 测试长度 | 长测试 |
| 测试测试 | 测试长度 | 长测试 |
|--------------+:----------------:+-----------:|
| abc | 测试长度 | 长测试 |
| 长 | 测试测试测试测试 | 测试测试 |
| 测试测试 | 测试 | 测试测测试 |
| 测试测试测试 | 测试测试 | 测试 |
| 测试测试 | 测试 | 测试测测试 |
| 测试测试测试 | 测试测试 | 测试 |
|--------------+------------------+------------|

View File

@@ -1,6 +1,6 @@
|--------+--------+------|
|测试测试|测试长度|长测试|
|--------+--------+-----:|
|--------+:------:+-----:|
|abc|测试长度|长测试|
|长|测试测试测试测试|测试测试|
|测试测试|测试|测试测测试|

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 43 KiB