vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit fa6342c454a1b25602922d27ca8157e77584bb69
parent 5e4a89c89889c2e630cc97c620bc138c7efa5adf
Author: Alexey Radkov <alexey.radkov@gmail.com>
Date:   Fri, 15 Mar 2019 15:38:22 +0300

Merge branch 'dev' into dev
Diffstat:
Mautoload/vimwiki/tbl.vim | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mdoc/vimwiki.txt | 15+++++++++++++++
Msyntax/vimwiki.vim | 2+-
Msyntax/vimwiki_markdown.vim | 38++++++++++++++++++--------------------
4 files changed, 96 insertions(+), 35 deletions(-)

diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim @@ -63,7 +63,7 @@ endfunction function! s:is_separator(line) - return a:line =~# '^\s*'.s:rxSep().'\(--\+'.s:rxSep().'\)\+\s*$' + return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$' endfunction @@ -73,6 +73,11 @@ endfunction function! s:is_last_column(lnum, cnum) + return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$' +endfunction + + +function! s:is_last_column(lnum, cnum) let line = strpart(getline(a:lnum), a:cnum - 1) return line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$' endfunction @@ -264,6 +269,35 @@ function! s:get_rows(lnum, ...) endfunction +function! s:get_cell_aligns(lnum) + let aligns = {} + for [lnum, row] in s:get_rows(a:lnum) + let found_separator = s:is_separator(row) + if found_separator + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let cell = cells[idx] + if cell =~# '^--\+:' + let aligns[idx] = 'right' + elseif cell =~# '^:--\+:' + let aligns[idx] = 'center' + else + let aligns[idx] = 'left' + endif + endfor + return aligns + endif + endfor + if !found_separator + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let aligns[idx] = 'left' + endfor + endif + return aligns +endfunction + + function! s:get_cell_max_lens(lnum, ...) let max_lens = {} let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum) @@ -316,12 +350,13 @@ function! s:get_aligned_rows(lnum, col1, col2, depth) endfor let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows) endif + let aligns = s:get_cell_aligns(a:lnum) let result = [] for [lnum, row] in rows if s:is_separator(row) - let new_row = s:fmt_sep(max_lens, a:col1, a:col2) + let new_row = s:fmt_sep(max_lens, aligns, a:col1, a:col2) else - let new_row = s:fmt_row(cells[lnum - startlnum], max_lens, a:col1, a:col2) + let new_row = s:fmt_row(cells[lnum - startlnum], max_lens, aligns, a:col1, a:col2) endif call add(result, [lnum, new_row]) endfor @@ -350,20 +385,25 @@ function! s:cur_column() endfunction -function! s:fmt_cell(cell, max_len) +function! s:fmt_cell(cell, max_len, align) let cell = ' '.a:cell.' ' let diff = a:max_len - s:wide_len(a:cell) if diff == 0 && empty(a:cell) let diff = 1 endif - - let cell .= repeat(' ', diff) + if a:align == 'left' + let cell .= repeat(' ', diff) + elseif a:align == 'right' + let cell = repeat(' ',diff).cell + else + let cell = repeat(' ',diff/2).cell.repeat(' ',diff-diff/2) + endif return cell endfunction -function! s:fmt_row(cells, max_lens, col1, col2) +function! s:fmt_row(cells, max_lens, aligns, col1, col2) let new_line = s:rxSep() for idx in range(len(a:cells)) if idx == a:col1 @@ -372,28 +412,36 @@ function! s:fmt_row(cells, max_lens, col1, col2) let idx = a:col1 endif let value = a:cells[idx] - let new_line .= s:fmt_cell(value, a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell(value, a:max_lens[idx], a:aligns[idx]).s:rxSep() endfor let idx = len(a:cells) while idx < len(a:max_lens) - let new_line .= s:fmt_cell('', a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell('', a:max_lens[idx], a:aligns[idx]).s:rxSep() let idx += 1 endwhile return new_line endfunction -function! s:fmt_cell_sep(max_len) +function! s:fmt_cell_sep(max_len, align) + let cell = '' if a:max_len == 0 - return repeat('-', 3) + let cell .= '-' + else + let cell .= repeat('-', a:max_len) + endif + if a:align == 'right' + return cell.'-:' + elseif a:align == 'left' + return cell.'--' else - return repeat('-', a:max_len+2) + return ':'.cell.':' endif endfunction -function! s:fmt_sep(max_lens, col1, col2) +function! s:fmt_sep(max_lens, aligns, col1, col2) let new_line = s:rxSep() for idx in range(len(a:max_lens)) if idx == a:col1 @@ -401,7 +449,7 @@ function! s:fmt_sep(max_lens, col1, col2) elseif idx == a:col2 let idx = a:col1 endif - let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep() + let new_line .= s:fmt_cell_sep(a:max_lens[idx], a:aligns[idx]).s:rxSep() endfor return new_line endfunction diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -883,6 +883,12 @@ is decorated: > super^script^ sub,,script,, +For Markdown syntax these variations are used: > + + **bold text** or __bold text__ + *italic text* or _italic text_ + ***bold_italic text*** or ___italic_bold text___ + Furthermore, there are a number of words which are highlighted extra flashy: TODO, DONE, STARTED, FIXME, FIXED, XXX. @@ -1721,6 +1727,15 @@ values: > To indent table indent the first row. Then format it with 'gqq'. +You can specify the type of horizontal alignment for columns in the separator +using the ':' character. The default is left-align. > + + | Date | Item | Price | + |------------|:------:|--------:| + | yest | Coffee | $15.00 | + | 2017-02-13 | Tea | $2.10 | + | 2017-03-14 | Cake | $143.12 | +< ============================================================================== 10. Diary *vimwiki-diary* diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim @@ -383,7 +383,7 @@ hi def link VimwikiBoldT VimwikiBold hi def VimwikiItalic term=italic cterm=italic gui=italic hi def link VimwikiItalicT VimwikiItalic -hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic +hi def VimwikiBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic hi def link VimwikiItalicBold VimwikiBoldItalic hi def link VimwikiBoldItalicT VimwikiBoldItalic hi def link VimwikiItalicBoldT VimwikiBoldItalic diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim @@ -13,38 +13,36 @@ let s:markdown_syntax = g:vimwiki_syntax_variables['markdown'] let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$' let s:markdown_syntax.char_eqin = '\$' -" text: *strong* -" let s:markdown_syntax.rxBold = '\*[^*]\+\*' +" text: **strong** or __strong__ let s:markdown_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'\*'. - \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. - \'\*'. + \'\(\*\|_\)\{2\}'. + \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. + \'\1\{2\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_bold = '*' +let s:markdown_syntax.char_bold = '\*\*\|__' -" text: _emphasis_ -" let s:markdown_syntax.rxItalic = '_[^_]\+_' +" text: _emphasis_ or *emphasis* let s:markdown_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'_'. - \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. - \'_'. + \'\(\*\|_\)'. + \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. + \'\1'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_italic = '_' +let s:markdown_syntax.char_italic = '\*\|_' " text: *_bold italic_* or _*italic bold*_ let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'\*_'. - \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. - \'_\*'. + \'\(\*\)\{3\}'. + \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. + \'\1\{3\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_bolditalic = '\*_' +let s:markdown_syntax.char_bolditalic = '\*\*\*' let s:markdown_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. - \'_\*'. - \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. - \'\*_'. + \'\(_\)\{3\}'. + \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. + \'\1\{3\}'. \'\%([[:punct:]]\|\s\|$\)\@=' -let s:markdown_syntax.char_italicbold = '_\*' +let s:markdown_syntax.char_italicbold = '___' " text: `code` let s:markdown_syntax.rxCode = '`[^`]\+`'