Skip to content

Commit

Permalink
Version 2.1
Browse files Browse the repository at this point in the history
    * Concealing of links can be turned off - set |g:vimwiki_url_maxsave| to 0.
      The option g:vimwiki_url_mingain was removed
    * |g:vimwiki_folding| also accepts value 'list'; with 'expr' both sections
      and code blocks folded, g:vimwiki_fold_lists option was removed
    * Issue 261: Syntax folding is back. |g:vimwiki_folding| values are
      changed to '', 'expr', 'syntax'.
    * Issue 372: Ignore case in g:vimwiki_valid_html_tags
    * Issue 374: Make autowriteall local to vimwiki. It is not 100% local
      though.
    * Issue 384: Custom_wiki2html script now receives templating arguments
    * Issue 393: Custom_wiki2html script path can contain tilde character
    * Issue 392: Custom_wiki2html arguments are quoted, e.g names with spaces
    * Various small bug fixes.
  • Loading branch information
habamax authored and vim-scripts committed Apr 26, 2013
1 parent d19cc85 commit cb5c38a
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 187 deletions.
6 changes: 3 additions & 3 deletions autoload/vimwiki/base.vim
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function! vimwiki#base#system_open_link(url) "{{{
execute '!open ' . shellescape(a:url, 1)
endfunction
function! s:linux_handler(url)
execute 'silent !xdg-open ' . shellescape(a:url, 1)
call system('xdg-open ' . shellescape(a:url, 1).' &')
endfunction
let success = 0
try
Expand Down Expand Up @@ -549,7 +549,7 @@ endfunction "}}}
function! vimwiki#base#backlinks() "{{{
execute 'lvimgrep "\%(^\|[[:blank:][:punct:]]\)'.
\ expand("%:t:r").
\ '\([[:blank:][:punct:]]\|$\)" '.
\ '\([[:blank:][:punct:]]\|$\)\C" '.
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ')
endfunction "}}}

Expand Down Expand Up @@ -639,7 +639,7 @@ function! vimwiki#base#edit_file(command, filename, ...) "{{{
" then
" [[test*file]]...
" you'll have E77: Too many file names
let fname = escape(a:filename, '% *|')
let fname = escape(a:filename, '% *|#')
let dir = fnamemodify(a:filename, ":p:h")
if vimwiki#base#mkdir(dir, 1)
execute a:command.' '.fname
Expand Down
45 changes: 23 additions & 22 deletions autoload/vimwiki/html.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
" Author: Maxim Kim <[email protected]>
" Home: http://code.google.com/p/vimwiki/

" XXX: This file should be refactored!
" TODO: We need vimwiki abstract syntax tree. If properly designed it wourld
" greatly symplify different syntax to HTML generation.
"
" vimwiki -- --> PDF
" \ /
" markdown -----> AST -----> HTML
" / \
" mediawiki -- --> Latex
"

" Load only once {{{
if exists("g:loaded_vimwiki_html_auto") || &cp
Expand Down Expand Up @@ -137,22 +145,12 @@ endfunction "}}}

function! s:safe_html(line) "{{{
" escape & < > when producing HTML text
" uses variables s:lt_pattern, s:gt_pattern that are
" set in vimwiki#html#Wiki2HTML() according to g:vimwiki_valid_html_tags
"" htmlize symbols: < > &

" s:lt_pattern, s:gt_pattern depend on g:vimwiki_valid_html_tags
" and are set in vimwiki#html#Wiki2HTML()
let line = substitute(a:line, '&', '\&amp;', 'g')
" the following depends on g:vimwiki_valid_html_tags
let line = substitute(line,s:lt_pattern,'\&lt;', 'g')
let line = substitute(line,s:gt_pattern,'\&gt;', 'g')

"let tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|')
"let line = substitute(line,'<\%(/\?\%('
" \.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!',
" \'\&lt;', 'g')
"let line = substitute(line,'\%(</\?\%('
" \.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?\)\@<!>',
" \'\&gt;', 'g')
return line
endfunction "}}}

Expand Down Expand Up @@ -456,11 +454,10 @@ function! s:tag_wikilink(value) "{{{
if g:vimwiki_debug > 1
echom '[[idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.']]'
endif
let url = escape(url, '#')
let line = vimwiki#html#linkify_link(url, descr)
return line
endfunction "}}}
"}}} v1.3 links
"}}}


function! s:tag_remove_internal_link(value) "{{{
Expand Down Expand Up @@ -1352,13 +1349,17 @@ endfunction " }}}

function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{
call vimwiki#base#mkdir(a:path)
execute '!'.VimwikiGet('custom_wiki2html'). ' '
echomsg system(VimwikiGet('custom_wiki2html'). ' '.
\ a:force. ' '.
\ VimwikiGet('syntax'). ' '.
\ strpart(VimwikiGet('ext'), 1). ' '.
\ a:path. ' '.
\ a:wikifile. ' '.
\ s:default_CSS_full_name(a:path)
\ shellescape(a:path, 1). ' '.
\ shellescape(a:wikifile, 1). ' '.
\ shellescape(s:default_CSS_full_name(a:path), 1). ' '.
\ (len(VimwikiGet('template_path')) > 1 ? shellescape(expand(VimwikiGet('template_path')), 1) : '-'). ' '.
\ (len(VimwikiGet('template_default')) > 0 ? VimwikiGet('template_default') : '-'). ' '.
\ (len(VimwikiGet('template_ext')) > 0 ? VimwikiGet('template_ext') : '-'). ' '.
\ (len(VimwikiGet('subdir')) > 0 ? shellescape(s:root_path(VimwikiGet('subdir')), 1) : '-'))
endfunction " }}}

function! vimwiki#html#Wiki2HTML(path_html, wikifile) "{{{
Expand Down Expand Up @@ -1415,8 +1416,8 @@ function! vimwiki#html#Wiki2HTML(path_html, wikifile) "{{{
let s:gt_pattern = '>'
if g:vimwiki_valid_html_tags != ''
let tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|')
let s:lt_pattern = '<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!'
let s:gt_pattern = '\%(</\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?\)\@<!>'
let s:lt_pattern = '\c<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!'
let s:gt_pattern = '\c\%(</\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?\)\@<!>'
endif

for line in lsource
Expand Down Expand Up @@ -1566,7 +1567,7 @@ function! vimwiki#html#WikiAll2HTML(path_html) "{{{
endfunction "}}}

function! s:file_exists(fname) "{{{
return !empty(getftype(a:fname))
return !empty(getftype(expand(a:fname)))
endfunction "}}}

" uses VimwikiGet('path')
Expand Down
69 changes: 39 additions & 30 deletions autoload/vimwiki/tbl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ let g:loaded_vimwiki_tbl_auto = 1
"}}}

let s:textwidth = &tw
let s:rxSep = g:vimwiki_rxTableSep


" Misc functions {{{
function! s:rxSep() "{{{
return g:vimwiki_rxTableSep
endfunction "}}}

function! s:wide_len(str) "{{{
" vim73 has new function that gives correct string width.
if exists("*strdisplaywidth")
Expand All @@ -43,36 +46,36 @@ function! s:wide_len(str) "{{{
endfunction "}}}

function! s:cell_splitter() "{{{
return '\s*'.s:rxSep.'\s*'
return '\s*'.s:rxSep().'\s*'
endfunction "}}}

function! s:sep_splitter() "{{{
return '-'.s:rxSep.'-'
return '-'.s:rxSep().'-'
endfunction "}}}

function! s:is_table(line) "{{{
return s:is_separator(a:line) || (a:line !~ s:rxSep.s:rxSep && a:line =~ '^\s*'.s:rxSep.'.\+'.s:rxSep.'\s*$')
return s:is_separator(a:line) || (a:line !~ s:rxSep().s:rxSep() && a:line =~ '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
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 "}}}

function! s:is_separator_tail(line) "{{{
return a:line =~ '^\{-1}\%(\s*\|-*\)\%('.s:rxSep.'-\+\)\+'.s:rxSep.'\s*$'
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)
"echomsg "DEBUG is_last_column> ".(line =~ s:rxSep.'\s*$' && line !~ s:rxSep.'.*'.s:rxSep.'\s*$')
return line =~ s:rxSep.'\s*$' && line !~ s:rxSep.'.*'.s:rxSep.'\s*$'
"echomsg "DEBUG is_last_column> ".(line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$')
return line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$'

endfunction "}}}

function! s:is_first_column(lnum, cnum) "{{{
let line = strpart(getline(a:lnum), 0, a:cnum - 1)
"echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep)
return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep)
"echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep())
return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep())
endfunction "}}}

function! s:count_separators_up(lnum) "{{{
Expand Down Expand Up @@ -100,8 +103,8 @@ function! s:count_separators_down(lnum) "{{{
endfunction "}}}

function! s:create_empty_row(cols) "{{{
let row = s:rxSep
let cell = " ".s:rxSep
let row = s:rxSep()
let cell = " ".s:rxSep()

for c in range(a:cols)
let row .= cell
Expand All @@ -111,8 +114,8 @@ function! s:create_empty_row(cols) "{{{
endfunction "}}}

function! s:create_row_sep(cols) "{{{
let row = s:rxSep
let cell = "---".s:rxSep
let row = s:rxSep()
let cell = "---".s:rxSep()

for c in range(a:cols)
let row .= cell
Expand Down Expand Up @@ -274,10 +277,10 @@ function! s:cur_column() "{{{
" TODO: do we need conditional: if s:is_separator(line)

let curs_pos = col('.')
let mpos = match(line, s:rxSep, 0)
let mpos = match(line, s:rxSep(), 0)
let col = -1
while mpos < curs_pos && mpos != -1
let mpos = match(line, s:rxSep, mpos+1)
let mpos = match(line, s:rxSep(), mpos+1)
if mpos != -1
let col += 1
endif
Expand All @@ -301,7 +304,7 @@ function! s:fmt_cell(cell, max_len) "{{{
endfunction "}}}

function! s:fmt_row(line, max_lens, col1, col2) "{{{
let new_line = s:rxSep
let new_line = s:rxSep()
let cells = vimwiki#tbl#get_cells(a:line)
for idx in range(len(cells))
if idx == a:col1
Expand All @@ -310,12 +313,12 @@ function! s:fmt_row(line, max_lens, col1, col2) "{{{
let idx = a:col1
endif
let value = 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]).s:rxSep()
endfor

let idx = len(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]).s:rxSep()
let idx += 1
endwhile
return new_line
Expand All @@ -330,14 +333,14 @@ function! s:fmt_cell_sep(max_len) "{{{
endfunction "}}}

function! s:fmt_sep(max_lens, col1, col2) "{{{
let new_line = s:rxSep
let new_line = s:rxSep()
for idx in range(len(a:max_lens))
if idx == a:col1
let idx = a: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]).s:rxSep()
endfor
return new_line
endfunction "}}}
Expand All @@ -349,10 +352,10 @@ function! s:kbd_create_new_row(cols, goto_first) "{{{
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>"
let cmd .= "\<ESC>0"
if a:goto_first
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'c', line('.'))\<CR>"
else
let cmd .= (col('.')-1)."l"
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
endif
let cmd .= "a"

Expand All @@ -361,16 +364,16 @@ endfunction "}}}

function! s:kbd_goto_next_row() "{{{
let cmd = "\<ESC>j"
let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= "a"
return cmd
endfunction "}}}

function! s:kbd_goto_prev_row() "{{{
let cmd = "\<ESC>k"
let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= "a"
return cmd
endfunction "}}}
Expand Down Expand Up @@ -432,7 +435,7 @@ function! s:kbd_goto_prev_col(jumpup) "{{{
let cmd .= "$"
endif
let cmd .= ":call vimwiki#tbl#goto_prev_col()\<CR>a"
" let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'b', line('.'))\<CR>"
" let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'b', line('.'))\<CR>"
" let cmd .= "a"
"echomsg "DEBUG kbd_goto_prev_col> ".cmd
return cmd
Expand Down Expand Up @@ -487,6 +490,9 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{
endfunction "}}}

function! vimwiki#tbl#format(lnum, ...) "{{{
if !(&filetype == 'vimwiki')
return
endif
let line = getline(a:lnum)
if !s:is_table(line)
return
Expand Down Expand Up @@ -554,6 +560,9 @@ function! vimwiki#tbl#align_or_cmd(cmd) "{{{
endfunction "}}}

function! vimwiki#tbl#reset_tw(lnum) "{{{
if !(&filetype == 'vimwiki')
return
endif
let line = getline(a:lnum)
if !s:is_table(line)
return
Expand Down Expand Up @@ -584,7 +593,7 @@ function! vimwiki#tbl#move_column_left() "{{{
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
call cursor(line('.'), 1)

let sep = '\('.s:rxSep.'\).\zs'
let sep = '\('.s:rxSep().'\).\zs'
let mpos = -1
let col = -1
while col < cur_col-1
Expand Down Expand Up @@ -617,7 +626,7 @@ function! vimwiki#tbl#move_column_right() "{{{
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
call cursor(line('.'), 1)

let sep = '\('.s:rxSep.'\).\zs'
let sep = '\('.s:rxSep().'\).\zs'
let mpos = -1
let col = -1
while col < cur_col+1
Expand Down
Loading

0 comments on commit cb5c38a

Please sign in to comment.