Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,42 @@ There are also two shorthands for adding the attributes `options=""` and `cols="
With the cursor inside the table, kbd:[+,cols+] adds the latter and kbd:[+,opts+] the former.


==== Aligning

When the https://github.com/godlygeek/tabular[Tabular Plugin] is
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One sentence per line. ,spl pls

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And lvl2 is to communicate "one idea per sentence".
If Tabular is highly recommended, it deserves it's own sentence.
Don't squeeze it into a parenthesis in the middle of a sentence.
Doing so interferes with the thought communicated in the surrounding sentence.

Suggest something like:

... is a popular plugin for aligning text.
The plugin is very useful for working with Asciidoc tables.
When the Tabular plugin is installed, tables can be aligned using `kbd:[+,|+]`.
This feature is limited to tables that ...

installed (which is highly recommended when working with tables),
alignment of tables is possible via kbd:[+,|+]. This applies only to tables
that use the Bar kbd:[+|+] as separator between cells.

Be aware that this only works for basic tables and certain features like
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want the user to be aware, use an admonition.
In this case I think it is enough to say, simply:

The align feature does not work well for tables with cell spanning.

I am not sure what "the cell spanning will not be visualized in the asciidoc sourcecode" means.

cell spanning do not work well with it together. It won't break the table,
but the cell spanning will not be visualized in the asciidoc sourcecode.

.Before
....
[%header]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % stuff is a nice feature but it's only noise in this context. I don't see how this adds any value for the reader. If it does it should be added in one fell swoop everywhere.

|===
|Animal|Color|Food
|Chicken|white|mostlycrop
|Pig|rose|everything
|===
....

.After
....
[%header]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

|===
| Animal | Color | Food
| Chicken | white | mostly crop
| Pig | rose | everything
|===
....

If the option `g:asciidoc_table_autoalign` is set to 1 (which is set to 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One sentence per line.

by default) a function will be enabled that autoaligns a table each time
the Bar kbd:[+|+] is entered inside the table.


[[editing-motions]]
=== Motions

Expand Down
3 changes: 3 additions & 0 deletions doc/asciidoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ Move forward to end of section with |][| and backward with |[]|.
" Table attributes
nnoremap <buffer> <LocalLeader>cols :call asciidoc#table#insert_attributes('cols')<CR>
nnoremap <buffer> <LocalLeader>opts :call asciidoc#table#insert_attributes('options')<CR>
" Table alignment (requires Tabular vim plugin)
nnoremap <buffer> <LocalLeader><Bar> :Tabularize /<Bar>\(===\)\@!<CR>
vnoremap <buffer> <LocalLeader><Bar> :Tabularize /<Bar>\(===\)\@!<CR>
" End.Table }}}


Expand Down
27 changes: 27 additions & 0 deletions ftplugin/asciidoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ if -1 < match(g:asciidoc_use_defaults, 'options')
let g:asciidoc_debug_level = 0
endif

if !exists('g:asciidoc_table_autoalign')
" do not autoalign table cells by default
let g:asciidoc_table_autoalign = 0
endif

setlocal commentstring=//\ %s
setlocal comments=fl:////,://,fn:*,fn:.
setlocal formatoptions=tcqjnro
Expand Down Expand Up @@ -375,4 +380,26 @@ nnoremap <buffer> <silent> <LocalLeader>dsb :call asciidoc#experimental#delete_s

" }}}

" Tabular ================================================== {{{
if exists(':Tabularize')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about the options here?
This might be the right choice.
First thought would be exists('g:tabular_loaded').
But if I have the plugin on path and don't want to load it for whatever reason, I would set that to prevent the plugin from loading.
Have you given thought to doing this particular check, or is it an "it's good enough" kind of thing?

" Use <Leader>| to realign tables with the Tabuliarize plugin
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Use <Leader>| to realign tables with the Tabuliarize plugin
" Use <LocalLeader>| to realign tables with the Tabuliarize plugin

nnoremap <buffer> <LocalLeader><Bar> :Tabularize /<Bar>\(===\)\@!<CR> " we need a negative lookahead to avoid breaking the block delimiters
vnoremap <buffer> <LocalLeader><Bar> :Tabularize /<Bar>\(===\)\@!<CR> " we need a negative lookahead to avoid breaking the block delimiters

" Realign table when entering a |
if g:asciidoc_table_autoalign == 1
inoremap <buffer> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# '^\s*|' || getline(line('.')+1) =~# '^\s*|')
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize /|\(=\)\@!
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
endif
endif
" }}}

" vim: set fdm=marker: