diff --git a/autoload/vimwiki.vim b/autoload/vimwiki.vim index 61c2972..c023ce2 100644 --- a/autoload/vimwiki.vim +++ b/autoload/vimwiki.vim @@ -65,7 +65,7 @@ function! vimwiki#current_subdir()"{{{ endfunction"}}} function! vimwiki#open_link(cmd, link, ...) "{{{ - if s:is_link_to_non_wiki_file(a:link) + if vimwiki#is_non_wiki_link(a:link) call s:edit_file(a:cmd, a:link) else if a:0 @@ -127,6 +127,13 @@ function! vimwiki#generate_links()"{{{ endfor endfunction " }}} +function! vimwiki#goto(key) "{{{ + call s:edit_file(':e', + \ VimwikiGet('path'). + \ a:key. + \ VimwikiGet('ext')) +endfunction "}}} + function! s:is_windows() "{{{ return has("win32") || has("win64") || has("win95") || has("win16") endfunction "}}} @@ -134,15 +141,21 @@ endfunction "}}} function! s:get_links(pat) "{{{ " search all wiki files in 'path' and its subdirs. let subdir = vimwiki#current_subdir() - let globlinks = glob(VimwikiGet('path').subdir.'**/'.a:pat) - " remove .wiki extensions - let globlinks = substitute(globlinks, '\'.VimwikiGet('ext'), "", "g") + " if current wiki is temporary -- was added by an arbitrary wiki file then do + " not search wiki files in subdirectories. Or it would hang the system if + " wiki file was created in $HOME or C:/ dirs. + if VimwikiGet('temp') + let search_dirs = '' + else + let search_dirs = '**/' + endif + let globlinks = glob(VimwikiGet('path').subdir.search_dirs.a:pat) + + " remove extensions (and backup extensions too: .wiki~) + let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\~\?', "", "g") let links = split(globlinks, '\n') - " remove backup files (.wiki~) - call filter(links, 'v:val !~ ''.*\~$''') - " remove paths let rem_path = escape(expand(VimwikiGet('path')).subdir, '\') call map(links, 'substitute(v:val, rem_path, "", "g")') @@ -235,15 +248,15 @@ function! s:strip_word(word) "{{{ endfunction " }}} -function! s:is_link_to_non_wiki_file(link) "{{{ - " Check if link is to a non-wiki file. - " The easiest way is to check if it has extension like .txt or .html - if a:link =~ '\.\w\{1,4}$' +function! vimwiki#is_non_wiki_link(lnk) "{{{ + let exts = '.\+\.\%('. + \ join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|'). + \ '\)$' + if a:lnk =~ exts return 1 endif return 0 -endfunction -" }}} +endfunction "}}} function! vimwiki#is_link_to_dir(link) "{{{ " Check if link is to a directory. @@ -252,8 +265,7 @@ function! vimwiki#is_link_to_dir(link) "{{{ return 1 endif return 0 -endfunction -" }}} +endfunction " }}} function! s:print_wiki_list() "{{{ let idx = 0 @@ -294,19 +306,23 @@ endfunction function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{ let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g') let new_fname = a:new_fname + let old_fname_r = old_fname + let new_fname_r = new_fname - if !s:is_wiki_word(new_fname) - let new_fname = '[['.new_fname.']]' + if !s:is_wiki_word(new_fname) && s:is_wiki_word(old_fname) + let new_fname_r = '[['.new_fname.']]' endif + if !s:is_wiki_word(old_fname) - let old_fname = '\[\['.vimwiki#unsafe_link(old_fname). - \ '\%(|.*\)\?\%(\]\[.*\)\?\]\]' + let old_fname_r = '\[\[\zs'.vimwiki#unsafe_link(old_fname). + \ '\ze\%(|.*\)\?\%(\]\[.*\)\?\]\]' else - let old_fname = '\<'.old_fname.'\>' + let old_fname_r = '\<'.old_fname.'\>' endif + let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n') for fname in files - call s:update_wiki_link(fname, old_fname, new_fname) + call s:update_wiki_link(fname, old_fname_r, new_fname_r) endfor endfunction " }}} @@ -348,8 +364,7 @@ function! s:update_wiki_links(old_fname, new_fname) " {{{ \ new_dir.old_fname, new_dir.new_fname) let idx = idx + 1 endwhile -endfunction -" }}} +endfunction " }}} function! s:get_wiki_buffers() "{{{ let blist = [] @@ -365,21 +380,58 @@ function! s:get_wiki_buffers() "{{{ let bcount = bcount + 1 endwhile return blist -endfunction -" }}} +endfunction " }}} function! s:open_wiki_buffer(item) "{{{ call s:edit_file('e', a:item[0]) if !empty(a:item[1]) call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1]) endif -endfunction -" }}} +endfunction " }}} " }}} " SYNTAX highlight {{{ -function! vimwiki#WikiHighlightLinks() "{{{ +function! vimwiki#highlight_links() "{{{ + try + syntax clear VimwikiNoExistsLink + syntax clear VimwikiNoExistsLinkT + syntax clear VimwikiLink + syntax clear VimwikiLinkT + catch + endtry + + "" use max highlighting - could be quite slow if there are too many wikifiles + if VimwikiGet('maxhi') + " Every WikiWord is nonexistent + if g:vimwiki_camel_case + execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiWord.'/ display' + execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiWord.'/ display contained' + endif + execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiLink1.'/ display contains=VimwikiNoLinkChar' + execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiLink2.'/ display contains=VimwikiNoLinkChar' + + execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiLink1.'/ display contained' + execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiLink2.'/ display contained' + + " till we find them in vimwiki's path + call s:highlight_existed_links() + else + " A WikiWord (unqualifiedWikiName) + execute 'syntax match VimwikiLink /\<'.g:vimwiki_rxWikiWord.'\>/' + " A [[bracketed wiki word]] + execute 'syntax match VimwikiLink /'.g:vimwiki_rxWikiLink1.'/ display contains=VimwikiLinkChar' + execute 'syntax match VimwikiLink /'.g:vimwiki_rxWikiLink2.'/ display contains=VimwikiLinkChar' + + execute 'syntax match VimwikiLinkT /\<'.g:vimwiki_rxWikiWord.'\>/ display contained' + execute 'syntax match VimwikiLinkT /'.g:vimwiki_rxWikiLink1.'/ display contained' + execute 'syntax match VimwikiLinkT /'.g:vimwiki_rxWikiLink2.'/ display contained' + endif + + execute 'syntax match VimwikiLink `'.g:vimwiki_rxWeblink.'` display contains=@NoSpell' +endfunction "}}} + +function! s:highlight_existed_links() "{{{ let links = s:get_links('*'.VimwikiGet('ext')) " Links with subdirs should be highlighted for linux and windows separators @@ -390,31 +442,116 @@ function! vimwiki#WikiHighlightLinks() "{{{ for link in links if g:vimwiki_camel_case && - \ link =~ g:vimwiki_rxWikiWord && !s:is_link_to_non_wiki_file(link) - execute 'syntax match VimwikiLink /!\@/' + \ link =~ g:vimwiki_rxWikiWord && !vimwiki#is_non_wiki_link(link) + execute 'syntax match VimwikiLink /!\@/ display' endif - execute 'syntax match VimwikiLink /\[\[\<'. - \ vimwiki#unsafe_link(link). - \ '\>\%(|\+.*\)*\]\]/' - execute 'syntax match VimwikiLink /\[\[\<'. - \ vimwiki#unsafe_link(link). - \ '\>\]\[.\+\]\]/' + execute 'syntax match VimwikiLink /\[\['. + \ escape(vimwiki#unsafe_link(link), '~&$.*'). + \ '\%(|\+.\{-}\)\{-}\]\]/ display contains=VimwikiLinkChar' + execute 'syntax match VimwikiLink /\[\['. + \ escape(vimwiki#unsafe_link(link), '~&$.*'). + \ '\]\[.\{-1,}\]\]/ display contains=VimwikiLinkChar' + + execute 'syntax match VimwikiLinkT /\[\['. + \ escape(vimwiki#unsafe_link(link), '~&$.*'). + \ '\%(|\+.\{-}\)\{-}\]\]/ display contained' + execute 'syntax match VimwikiLinkT /\[\['. + \ escape(vimwiki#unsafe_link(link), '~&$.*'). + \ '\]\[.\{-1,}\]\]/ display contained' endfor - execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/' - execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/' + execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar' + execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/ display contains=VimwikiLinkChar' + + execute 'syntax match VimwikiLinkT /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/ display contained' + execute 'syntax match VimwikiLinkT /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/ display contained' + + " Issue 103: Always highlight links to non-wiki files as existed. + execute 'syntax match VimwikiLink /\[\[.\+\.\%('. + \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|'). + \'\)\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar' + execute 'syntax match VimwikiLink /\[\[.\+\.\%('. + \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|'). + \'\)\]\[.\+\]\]/ display contains=VimwikiLinkChar' + + execute 'syntax match VimwikiLinkT /\[\[.\+\.\%('. + \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|'). + \'\)\%(|\+.*\)*\]\]/ display contained' + execute 'syntax match VimwikiLinkT /\[\[.\+\.\%('. + \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|'). + \'\)\]\[.\+\]\]/ display contained' " highlight dirs let dirs = s:get_links('*/') call map(dirs, 'substitute(v:val, os_p, os_p2, "g")') for dir in dirs - execute 'syntax match VimwikiLink /\[\[\<'. - \ vimwiki#unsafe_link(dir). - \ '\>[/\\]*\%(|\+.*\)*\]\]/' - endfor -endfunction -" }}} + execute 'syntax match VimwikiLink /\[\['. + \ escape(vimwiki#unsafe_link(dir), '~&$.*'). + \ '[/\\]*\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar' + execute 'syntax match VimwikiLink /\[\['. + \ escape(vimwiki#unsafe_link(dir), '~&$.*'). + \ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contains=VimwikiLinkChar' -function! vimwiki#hl_exists(hl)"{{{ + execute 'syntax match VimwikiLinkT /\[\['. + \ escape(vimwiki#unsafe_link(dir), '~&$.*'). + \ '[/\\]*\%(|\+.*\)*\]\]/ display contained' + execute 'syntax match VimwikiLinkT /\[\['. + \ escape(vimwiki#unsafe_link(dir), '~&$.*'). + \ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contained' + endfor +endfunction "}}} + +function! vimwiki#setup_colors() "{{{ + + function! s:set_visible_ignore_color() "{{{ + if !exists("g:colors_name") || g:colors_name == 'default' + if &background == 'light' + hi VimwikiIgnore guifg=#d0d0d0 + else + hi VimwikiIgnore guifg=#505050 + endif + else + hi link VimwikiIgnore Normal + endif + endfunction "}}} + + let hlfg_ignore = vimwiki#get_hl_param('Ignore', 'guifg') + let hlbg_normal = vimwiki#get_hl_param('Normal', 'guibg') + if hlfg_ignore == 'bg' || hlfg_ignore == hlbg_normal + call s:set_visible_ignore_color() + else + hi link VimwikiIgnore Ignore + endif + + if g:vimwiki_hl_headers == 0 + hi def link VimwikiHeader Title + return + endif + + if &background == 'light' + hi def VimwikiHeader1 guibg=bg guifg=#aa5858 gui=bold ctermfg=DarkRed + hi def VimwikiHeader2 guibg=bg guifg=#507030 gui=bold ctermfg=DarkGreen + hi def VimwikiHeader3 guibg=bg guifg=#1030a0 gui=bold ctermfg=DarkBlue + hi def VimwikiHeader4 guibg=bg guifg=#103040 gui=bold ctermfg=Black + hi def VimwikiHeader5 guibg=bg guifg=#505050 gui=bold ctermfg=Black + hi def VimwikiHeader6 guibg=bg guifg=#636363 gui=bold ctermfg=Black + else + hi def VimwikiHeader1 guibg=bg guifg=#e08090 gui=bold ctermfg=Red + hi def VimwikiHeader2 guibg=bg guifg=#80e090 gui=bold ctermfg=Green + hi def VimwikiHeader3 guibg=bg guifg=#6090e0 gui=bold ctermfg=Blue + hi def VimwikiHeader4 guibg=bg guifg=#c0c0f0 gui=bold ctermfg=White + hi def VimwikiHeader5 guibg=bg guifg=#e0e0f0 gui=bold ctermfg=White + hi def VimwikiHeader6 guibg=bg guifg=#f0f0f0 gui=bold ctermfg=White + endif +endfunction "}}} + +function vimwiki#get_hl_param(hgroup, hparam) "{{{ + redir => hlstatus + exe "silent hi ".a:hgroup + redir END + return matchstr(hlstatus, a:hparam.'\s*=\s*\zs\S\+') +endfunction "}}} + +function! vimwiki#hl_exists(hl) "{{{ if !hlexists(a:hl) return 0 endif @@ -454,26 +591,38 @@ function! vimwiki#nested_syntax(filetype, start, end, textSnipHl) abort "{{{ else unlet b:current_syntax endif - execute 'syntax region textSnip'.ft.' - \ matchgroup='.a:textSnipHl.' - \ start="'.a:start.'" end="'.a:end.'" - \ contains=@'.group + execute 'syntax region textSnip'.ft. + \ ' matchgroup='.a:textSnipHl. + \ ' start="'.a:start.'" end="'.a:end.'"'. + \ ' contains=@'.group.' keepend' + + " A workaround to Issue 115: Nested Perl syntax highlighting differs from + " regular one. + " Perl syntax file has perlFunctionName which is usually has no effect due to + " 'contained' flag. Now we have 'syntax include' that makes all the groups + " included as 'contained' into specific group. + " Here perlFunctionName (with quite an angry regexp "\h\w*[^:]") clashes with + " the rest syntax rules as now it has effect being really 'contained'. + " Clear it! + if ft =~ 'perl' + syntax clear perlFunctionName + endif endfunction "}}} "}}} " WIKI functions {{{ -function! vimwiki#WikiNextWord() "{{{ +function! vimwiki#find_next_link() "{{{ call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, '') endfunction " }}} -function! vimwiki#WikiPrevWord() "{{{ +function! vimwiki#find_prev_link() "{{{ call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, 'b') endfunction " }}} -function! vimwiki#WikiFollowWord(split) "{{{ +function! vimwiki#follow_link(split) "{{{ if a:split == "split" let cmd = ":split " elseif a:split == "vsplit" @@ -486,7 +635,7 @@ function! vimwiki#WikiFollowWord(split) "{{{ if link == "" let weblink = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWeblink)) if weblink != "" - call VimwikiWeblinkHandler(weblink) + call VimwikiWeblinkHandler(escape(weblink, '#')) else execute "normal! \n" endif @@ -496,20 +645,18 @@ function! vimwiki#WikiFollowWord(split) "{{{ let subdir = vimwiki#current_subdir() call vimwiki#open_link(cmd, subdir.link) -endfunction -" }}} +endfunction " }}} -function! vimwiki#WikiGoBackWord() "{{{ +function! vimwiki#go_back_link() "{{{ if exists("b:vimwiki_prev_link") " go back to saved WikiWord let prev_word = b:vimwiki_prev_link execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g') call setpos('.', prev_word[1]) endif -endfunction -" }}} +endfunction " }}} -function! vimwiki#WikiGoHome(index) "{{{ +function! vimwiki#goto_index(index) "{{{ call vimwiki#select(a:index) call vimwiki#mkdir(VimwikiGet('path')) @@ -517,17 +664,15 @@ function! vimwiki#WikiGoHome(index) "{{{ execute ':e '.fnameescape( \ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext')) catch /E37/ " catch 'No write since last change' error - " this is really unsecure!!! - execute ':'.VimwikiGet('gohome').' '. + execute ':split '. \ VimwikiGet('path'). \ VimwikiGet('index'). \ VimwikiGet('ext') catch /E325/ " catch 'ATTENTION' error (:h E325) endtry -endfunction -"}}} +endfunction "}}} -function! vimwiki#WikiDeleteWord() "{{{ +function! vimwiki#delete_link() "{{{ "" file system funcs "" Delete WikiWord you are in from filesystem let val = input('Delete ['.expand('%').'] (y/n)? ', "") @@ -547,10 +692,9 @@ function! vimwiki#WikiDeleteWord() "{{{ if expand('%:p') != "" execute "e" endif -endfunction -"}}} +endfunction "}}} -function! vimwiki#WikiRenameWord() "{{{ +function! vimwiki#rename_link() "{{{ "" Rename WikiWord, update all links to renamed WikiWord let subdir = vimwiki#current_subdir() let old_fname = subdir.expand('%:t') @@ -575,18 +719,17 @@ function! vimwiki#WikiRenameWord() "{{{ return endif - let new_link = subdir.new_link - " check new_fname - it should be 'good', not empty if substitute(new_link, '\s', '', 'g') == '' echomsg 'vimwiki: Cannot rename to an empty filename!' return endif - if s:is_link_to_non_wiki_file(new_link) + if vimwiki#is_non_wiki_link(new_link) echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!' return endif + let new_link = subdir.new_link let new_link = s:strip_word(new_link) let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext') @@ -649,16 +792,15 @@ function! vimwiki#WikiRenameWord() "{{{ echomsg old_fname." is renamed to ".new_fname let &more = setting_more -endfunction -" }}} +endfunction " }}} -function! vimwiki#WikiUISelect()"{{{ +function! vimwiki#ui_select()"{{{ call s:print_wiki_list() let idx = input("Select Wiki (specify number): ") if idx == "" return endif - call vimwiki#WikiGoHome(idx) + call vimwiki#goto_index(idx) endfunction "}}} diff --git a/autoload/vimwiki_diary.vim b/autoload/vimwiki_diary.vim index 37b7eed..9803cc1 100644 --- a/autoload/vimwiki_diary.vim +++ b/autoload/vimwiki_diary.vim @@ -62,7 +62,7 @@ function! s:get_diary_range(lines, header) "{{{ let idx += 1 endfor - let ln_end = idx - 1 + let ln_end = idx return [ln_start, ln_end] endfunction "}}} @@ -99,10 +99,24 @@ function! s:get_links() "{{{ call map(links, 'fnamemodify(v:val, ":t")') call filter(links, 'v:val =~ "'.escape(rx, '\').'"') - call map(links, '"[[".v:val."]]"') return links endfunction "}}} +function! s:get_position_links(link) "{{{ + let idx = -1 + let links = [] + if a:link =~ '\d\{4}-\d\d-\d\d' + let links = s:get_links() + " include 'today' into links + if index(links, s:diary_date_link()) == -1 + call add(links, s:diary_date_link()) + endif + call sort(links) + let idx = index(links, a:link) + endif + return [idx, links] +endfunction "}}} + function! s:format_links(links) "{{{ let lines = [] let line = '| ' @@ -137,6 +151,7 @@ function! s:add_link(page, header, link) "{{{ if ln_start == -1 call insert(lines, '= '.a:header.' =') let ln_start = 1 + let ln_end = 1 endif " removing 'old' links @@ -148,6 +163,7 @@ function! s:add_link(page, header, link) "{{{ " get all diary links from filesystem let links = s:get_links() + call map(links, '"[[".v:val."]]"') " add current link if index(links, link) == -1 @@ -192,7 +208,7 @@ function! vimwiki_diary#make_note(index, ...) "{{{ call vimwiki#open_link(':e ', link, s:diary_index()) endfunction "}}} -" Calendar.vim callback and sign functions. +" Calendar.vim callback function. function! vimwiki_diary#calendar_action(day, month, year, week, dir) "{{{ let day = s:prefix_zero(a:day) let month = s:prefix_zero(a:month) @@ -213,8 +229,9 @@ function! vimwiki_diary#calendar_action(day, month, year, week, dir) "{{{ " Create diary note for a selected date in default wiki. call vimwiki_diary#make_note(1, link) -endfunction +endfunction "}}} +" Calendar.vim sign function. function vimwiki_diary#calendar_sign(day, month, year) "{{{ let day = s:prefix_zero(a:day) let month = s:prefix_zero(a:month) @@ -222,3 +239,43 @@ function vimwiki_diary#calendar_sign(day, month, year) "{{{ \ a:year.'-'.month.'-'.day.VimwikiGet('ext') return filereadable(expand(sfile)) endfunction "}}} + +function! vimwiki_diary#goto_next_day() "{{{ + let link = '' + let [idx, links] = s:get_position_links(expand('%:t:r')) + + if idx == (len(links) - 1) + return + endif + + if idx != -1 && idx < len(links) - 1 + let link = VimwikiGet('diary_rel_path').links[idx+1] + else + " goto today + let link = VimwikiGet('diary_rel_path').s:diary_date_link() + endif + + if len(link) + call vimwiki#open_link(':e ', link) + endif +endfunction "}}} + +function! vimwiki_diary#goto_prev_day() "{{{ + let link = '' + let [idx, links] = s:get_position_links(expand('%:t:r')) + + if idx == 0 + return + endif + + if idx > 0 + let link = VimwikiGet('diary_rel_path').links[idx-1] + else + " goto today + let link = VimwikiGet('diary_rel_path').s:diary_date_link() + endif + + if len(link) + call vimwiki#open_link(':e ', link) + endif +endfunction "}}} diff --git a/autoload/vimwiki_html.vim b/autoload/vimwiki_html.vim index 3c88ecc..1efa539 100644 --- a/autoload/vimwiki_html.vim +++ b/autoload/vimwiki_html.vim @@ -48,14 +48,6 @@ function! s:is_img_link(lnk) "{{{ return 0 endfunction "}}} -function! s:is_non_wiki_link(lnk) "{{{ - " TODO: Add more file extensions here - if a:lnk =~ '.\+\.\%(pdf\|txt\|doc\|rtf\|xls\)$' - return 1 - endif - return 0 -endfunction "}}} - function! s:has_abs_path(fname) "{{{ if a:fname =~ '\(^.:\)\|\(^/\)' return 1 @@ -102,15 +94,13 @@ function! s:create_default_CSS(path) " {{{ endif endfunction "}}} -function! s:get_html_header(wikifile, subdir, charset) "{{{ +function! s:get_html_header(title, subdir, charset) "{{{ let lines=[] - let title = fnamemodify(a:wikifile, ":t:r") - if VimwikiGet('html_header') != "" && !s:warn_html_header try let lines = readfile(expand(VimwikiGet('html_header'))) - call map(lines, 'substitute(v:val, "%title%", "'. title .'", "g")') + call map(lines, 'substitute(v:val, "%title%", "'. a:title .'", "g")') call map(lines, 'substitute(v:val, "%root_path%", "'. \ s:root_path(a:subdir) .'", "g")') return lines @@ -134,7 +124,7 @@ function! s:get_html_header(wikifile, subdir, charset) "{{{ call add(lines, '
') call add(lines, '') - call add(lines, '") endif - let pre = 1 + let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))] let processed = 1 - elseif pre && a:line =~ '^}}}\s*$' - let pre = 0 + elseif pre[0] && a:line =~ '^\s*}}}\s*$' + let pre = [0, 0] call add(lines, "") let processed = 1 - elseif pre + elseif pre[0] let processed = 1 - call add(lines, a:line) + call add(lines, substitute(a:line, '^\s\{'.pre[1].'}', '', '')) endif return [processed, lines, pre] endfunction "}}} @@ -713,7 +719,6 @@ function! s:process_tag_quote(line, quote) "{{{ let lines = [] let quote = a:quote let processed = 0 - " if a:line =~ '^\s\{4,}[^[:blank:]*#]' if a:line =~ '^\s\{4,}\S' if !quote call add(lines, "
") @@ -721,9 +726,6 @@ function! s:process_tag_quote(line, quote) "{{{ endif let processed = 1 call add(lines, substitute(a:line, '^\s*', '', '')) - elseif quote && a:line =~ '^\s*$' - let processed = 1 - call add(lines, a:line) elseif quote call add(lines, "") let quote = 0 @@ -987,12 +989,14 @@ endfunction "}}} "}}} +" }}} + " WIKI2HTML "{{{ function! s:parse_line(line, state) " {{{ let state = {} let state.para = a:state.para let state.quote = a:state.quote - let state.pre = a:state.pre + let state.pre = a:state.pre[:] let state.table = a:state.table[:] let state.lists = a:state.lists[:] let state.deflist = a:state.deflist @@ -1014,6 +1018,15 @@ function! s:parse_line(line, state) " {{{ endif endif + " title -- placeholder + if !processed + if line =~ '^\s*%title' + let processed = 1 + let param = matchstr(line, '^\s*%title\s\zs.*') + let state.placeholder = ['title', param] + endif + endif + " toc -- placeholder "{{{ if !processed if line =~ '^\s*%toc' @@ -1027,9 +1040,10 @@ function! s:parse_line(line, state) " {{{ " pres "{{{ if !processed let [processed, lines, state.pre] = s:process_tag_pre(line, state.pre) - if processed && len(state.lists) - call s:close_tag_list(state.lists, lines) - endif + " pre is just fine to be in the list -- do not close list item here. + " if processed && len(state.lists) + " call s:close_tag_list(state.lists, lines) + " endif if processed && len(state.table) let state.table = s:close_tag_table(state.table, lines) endif @@ -1052,7 +1066,7 @@ function! s:parse_line(line, state) " {{{ if processed && state.quote let state.quote = s:close_tag_quote(state.quote, lines) endif - if processed && state.pre + if processed && state.pre[0] let state.pre = s:close_tag_pre(state.pre, lines) endif if processed && len(state.table) @@ -1109,7 +1123,7 @@ function! s:parse_line(line, state) " {{{ if processed && len(state.table) let state.table = s:close_tag_table(state.table, lines) endif - if processed && state.pre + if processed && state.pre[0] let state.pre = s:close_tag_pre(state.pre, lines) endif if processed && state.para @@ -1153,7 +1167,7 @@ function! s:parse_line(line, state) " {{{ if processed && state.quote let state.quote = s:close_tag_quote(state.quote, res_lines) endif - if processed && state.pre + if processed && state.pre[0] let state.pre = s:close_tag_pre(state.pre, res_lines) endif if processed && len(state.table) @@ -1186,7 +1200,7 @@ function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{ let subdir = vimwiki#subdir(VimwikiGet('path'), wikifile) let lsource = s:remove_comments(readfile(wikifile)) - let ldest = s:get_html_header(wikifile, subdir, &fileencoding) + let ldest = [] let path = expand(a:path).subdir call vimwiki#mkdir(path) @@ -1201,7 +1215,7 @@ function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{ let state = {} let state.para = 0 let state.quote = 0 - let state.pre = 0 + let state.pre = [0, 0] " [in_pre, indent_pre] let state.table = [] let state.deflist = 0 let state.lists = [] @@ -1236,8 +1250,7 @@ function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{ if !nohtml let toc = s:get_html_toc(state.toc) - call s:process_placeholders(ldest, placeholders, 'toc', toc) - + call s:process_toc(ldest, placeholders, toc) call s:remove_blank_lines(ldest) "" process end of file @@ -1251,6 +1264,8 @@ function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{ call s:close_tag_table(state.table, lines) call extend(ldest, lines) + let title = s:process_title(placeholders, fnamemodify(a:wikifile, ":t:r")) + call extend(ldest, s:get_html_header(title, subdir, &fileencoding), 0) call extend(ldest, s:get_html_footer()) "" make html file. @@ -1266,9 +1281,12 @@ function! vimwiki_html#WikiAll2HTML(path) "{{{ endif echomsg 'Saving vimwiki files...' + let save_eventignore = &eventignore + let &eventignore = "all" let cur_buf = bufname('%') bufdo call s:save_vimwiki_buffer() exe 'buffer '.cur_buf + let &eventignore = save_eventignore let path = expand(a:path) call vimwiki#mkdir(path) diff --git a/autoload/vimwiki_lst.vim b/autoload/vimwiki_lst.vim index 497bff3..fcdfe36 100644 --- a/autoload/vimwiki_lst.vim +++ b/autoload/vimwiki_lst.vim @@ -40,7 +40,6 @@ endfunction "}}} " Get regexp of the list item with checkbox. function! s:rx_cb_list_item() "{{{ - " return s:rx_list_item().'\s*\zs\[.\?\]' return s:rx_list_item().'\s*\zs\[.\?\]' endfunction "}}} @@ -182,9 +181,7 @@ function! s:get_sibling_items(lnum) "{{{ let lnum = a:lnum let ind = s:get_level(lnum) - while s:get_level(lnum) >= ind && - \ lnum != 0 - + while lnum != 0 && s:get_level(lnum) >= ind if s:get_level(lnum) == ind && s:is_cb_list_item(lnum) call add(result, lnum) endif @@ -192,9 +189,7 @@ function! s:get_sibling_items(lnum) "{{{ endwhile let lnum = s:prev_list_item(a:lnum) - while s:get_level(lnum) >= ind && - \ lnum != 0 - + while lnum != 0 && s:get_level(lnum) >= ind if s:get_level(lnum) == ind && s:is_cb_list_item(lnum) call add(result, lnum) endif @@ -227,7 +222,7 @@ function! s:create_cb_list_item(lnum) "{{{ let m = matchstr(line, s:rx_list_item()) if m != '' let li_content = substitute(strpart(line, len(m)), '^\s*', '', '') - let line = m.'[ ] '.li_content + let line = substitute(m, '\s*$', ' ', '').'[ ] '.li_content call setline(a:lnum, line) endif endfunction "}}} @@ -321,7 +316,7 @@ function! vimwiki_lst#ToggleListItem(line1, line2) "{{{ endfunction "}}} -function! vimwiki_lst#insertCR() "{{{ +function! vimwiki_lst#kbd_cr() "{{{ " This function is heavily relies on proper 'set comments' option. let cr = "\