diff --git a/vimwiki_0_9_4.vba b/vimwiki_0_9_5.vba similarity index 92% rename from vimwiki_0_9_4.vba rename to vimwiki_0_9_5.vba index 6404a11..3000c33 100644 --- a/vimwiki_0_9_4.vba +++ b/vimwiki_0_9_5.vba @@ -1,3580 +1,3743 @@ " Vimball Archiver by Charles E. Campbell, Jr., Ph.D. UseVimball finish -autoload\vimwiki.vim [[[1 -554 -" Vimwiki autoload plugin file +syntax\vimwiki.vim [[[1 +139 +" Vimwiki syntax file " Author: Maxim Kim " Home: http://code.google.com/p/vimwiki/ +" vim:tw=79: -if exists("g:loaded_vimwiki_auto") || &cp +" Quit if syntax file is already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") finish endif -let g:loaded_vimwiki_auto = 1 -if has("win32") - let s:os_sep = '\' +"" 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 wikiNoExistsWord /\%(^\|[^!]\)\zs'.g:vimwiki_word1.'/' + endif + execute 'syntax match wikiNoExistsWord /'.g:vimwiki_word2.'/' + execute 'syntax match wikiNoExistsWord /'.g:vimwiki_word3.'/' + " till we find them in vimwiki's path + call vimwiki#WikiHighlightWords() else - let s:os_sep = '/' + " A WikiWord (unqualifiedWikiName) + execute 'syntax match wikiWord /\%(^\|[^!]\)\zs\<'.g:vimwiki_word1.'\>/' + " A [[bracketed wiki word]] + execute 'syntax match wikiWord /'.g:vimwiki_word2.'/' endif -let s:wiki_badsymbols = '[<>|?*:"]' -" MISC helper functions {{{ +execute 'syntax match wikiLink `'.g:vimwiki_rxWeblink.'`' -" This function is double defined. -" TODO: refactor common functions into new module. -function! s:chomp_slash(str)"{{{ - return substitute(a:str, '[/\\]\+$', '', '') -endfunction"}}} +" Emoticons: must come after the Textilisms, as later rules take precedence +" over earlier ones. This match is an approximation for the ~70 distinct +syntax match wikiEmoticons /\%((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/ -function! vimwiki#mkdir(path) "{{{ - let path = expand(a:path) - if !isdirectory(path) && exists("*mkdir") - let path = s:chomp_slash(path) - call mkdir(path, "p") - endif -endfunction -" }}} -function! vimwiki#safe_link(string) "{{{ - return substitute(a:string, s:wiki_badsymbols, g:vimwiki_stripsym, 'g') -endfunction -"}}} -function! vimwiki#unsafe_link(string) "{{{ - return substitute(a:string, g:vimwiki_stripsym, s:wiki_badsymbols, 'g') -endfunction -"}}} -function! vimwiki#subdir(path, filename)"{{{ - let path = expand(a:path) - let filename = expand(a:filename) - let idx = 0 - while path[idx] == filename[idx] - let idx = idx + 1 - endwhile +let g:vimwiki_rxTodo = '\C\%(TODO:\|DONE:\|FIXME:\|FIXED:\|XXX:\)' +execute 'syntax match wikiTodo /'. g:vimwiki_rxTodo .'/' - let p = split(strpart(filename, idx), '[/\\]') - let res = join(p[:-2], s:os_sep) - if len(res) > 0 - let res = res.s:os_sep - endif - return res -endfunction"}}} -function! vimwiki#current_subdir()"{{{ - return vimwiki#subdir(VimwikiGet('path'), expand('%:p')) -endfunction"}}} -function! s:msg(message) "{{{ - echohl WarningMsg - echomsg 'vimwiki: '.a:message - echohl None -endfunction -" }}} -function! s:filename(link) "{{{ - return split(a:link, '|')[0] -endfunction -" }}} -function! s:is_wiki_word(str) "{{{ - if a:str =~ g:vimwiki_word1 && a:str !~ '[[:space:]\\/]' - return 1 - endif - return 0 -endfunction -" }}} -function! s:edit_file(command, filename) "{{{ - let fname = escape(a:filename, '% ') - call vimwiki#mkdir(fnamemodify(a:filename, ":p:h")) - execute a:command.' '.fname -endfunction -" }}} -function! s:search_word(wikiRx, cmd) "{{{ - let match_line = search(a:wikiRx, 's'.a:cmd) - if match_line == 0 - call s:msg('WikiWord not found') - endif -endfunction -" }}} -function! s:get_word_at_cursor(wikiRX) "{{{ - let col = col('.') - 1 - let line = getline('.') - let ebeg = -1 - let cont = match(line, a:wikiRX, 0) - while (ebeg >= 0 || (0 <= cont) && (cont <= col)) - let contn = matchend(line, a:wikiRX, cont) - if (cont <= col) && (col < contn) - let ebeg = match(line, a:wikiRX, cont) - let elen = contn - ebeg - break - else - let cont = match(line, a:wikiRX, contn) - endif - endwh - if ebeg >= 0 - return strpart(line, ebeg, elen) - else - return "" - endif -endf "}}} -function! s:strip_word(word) "{{{ - let result = a:word - if strpart(a:word, 0, 2) == "[[" - " get rid of [[ and ]] - let w = strpart(a:word, 2, strlen(a:word)-4) - " we want "link" from [[link|link desc]] - let w = split(w, "|")[0] - let result = vimwiki#safe_link(w) - endif - return result -endfunction -" }}} -function! s:is_link_to_non_wiki_file(word) "{{{ - " Check if word is link to a non-wiki file. - " The easiest way is to check if it has extension like .txt or .html - if a:word =~ '\.\w\{1,4}$' - return 1 - endif - return 0 -endfunction -" }}} -function! s:print_wiki_list() "{{{ - let idx = 0 - while idx < len(g:vimwiki_list) - if idx == g:vimwiki_current_idx - let sep = ' * ' - echohl TablineSel - else - let sep = ' ' - echohl None - endif - echo (idx + 1).sep.VimwikiGet('path', idx) - let idx += 1 - endwhile - echohl None -endfunction -" }}} -function! s:wiki_select(wnum)"{{{ - if a:wnum < 1 || a:wnum > len(g:vimwiki_list) - return - endif - let b:vimwiki_idx = g:vimwiki_current_idx - let g:vimwiki_current_idx = a:wnum - 1 -endfunction -" }}} -function! s:update_wiki_link(fname, old, new) " {{{ - echo "Updating links in ".a:fname - let has_updates = 0 - let dest = [] - for line in readfile(a:fname) - if !has_updates && match(line, a:old) != -1 - let has_updates = 1 - endif - call add(dest, substitute(line, a:old, escape(a:new, "&"), "g")) - endfor - " add exception handling... - if has_updates - call rename(a:fname, a:fname.'#vimwiki_upd#') - call writefile(dest, a:fname) - call delete(a:fname.'#vimwiki_upd#') - endif -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 +" Load concrete Wiki syntax +execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'.vim' - if !s:is_wiki_word(new_fname) - let new_fname = '[['.new_fname.']]' - endif - if !s:is_wiki_word(old_fname) - let old_fname = '\[\['.vimwiki#unsafe_link(old_fname).'\%(|.*\)\?\]\]' - else - let old_fname = '\<'.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) - endfor -endfunction -" }}} -function! s:update_wiki_links(old_fname, new_fname) " {{{ - let old_fname = fnamemodify(a:old_fname, ":t:r") - let new_fname = fnamemodify(a:new_fname, ":t:r") +" Tables +execute 'syntax match wikiTable /'.g:vimwiki_rxTable.'/' - let subdirs = split(a:old_fname, '[/\\]')[: -2] +execute 'syntax match wikiBold /'.g:vimwiki_rxBold.'/' - " TODO: Use Dictionary here... - let dirs_keys = [''] - let dirs_vals = [''] - if len(subdirs) > 0 - let dirs_keys = [''] - let dirs_vals = [join(subdirs, '/').'/'] - let idx = 0 - while idx < len(subdirs) - 1 - call add(dirs_keys, join(subdirs[: idx], '/').'/') - call add(dirs_vals, join(subdirs[idx+1 :], '/').'/') - let idx = idx + 1 - endwhile - call add(dirs_keys,join(subdirs, '/').'/') - call add(dirs_vals, '') - endif +execute 'syntax match wikiItalic /'.g:vimwiki_rxItalic.'/' - let idx = 0 - while idx < len(dirs_keys) - let dir = dirs_keys[idx] - let new_dir = dirs_vals[idx] - call s:update_wiki_links_dir(dir, - \ new_dir.old_fname, new_dir.new_fname) - let idx = idx + 1 - endwhile -endfunction -" }}} -function! s:get_wiki_buffers() "{{{ - let blist = [] - let bcount = 1 - while bcount<=bufnr("$") - if bufexists(bcount) - let bname = fnamemodify(bufname(bcount), ":p") - if bname =~ VimwikiGet('ext')."$" - let bitem = [bname, getbufvar(bname, "vimwiki_prev_word")] - call add(blist, bitem) - endif - endif - let bcount = bcount + 1 - endwhile - return blist -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_word", a:item[1]) - endif -endfunction -" }}} -" }}} -" SYNTAX highlight {{{ -function! vimwiki#WikiHighlightWords() "{{{ - " search all wiki files in 'path' and its subdirs. - let subdir = vimwiki#current_subdir() - let wikies = glob(VimwikiGet('path').subdir.'**/*'.VimwikiGet('ext')) +execute 'syntax match wikiBoldItalic /'.g:vimwiki_rxBoldItalic.'/' - " remove .wiki extensions - let wikies = substitute(wikies, '\'.VimwikiGet('ext'), "", "g") - let g:vimwiki_wikiwords = split(wikies, '\n') +execute 'syntax match wikiItalicBold /'.g:vimwiki_rxItalicBold.'/' - " remove backup files (.wiki~) - call filter(g:vimwiki_wikiwords, 'v:val !~ ''.*\~$''') +execute 'syntax match wikiDelText /'.g:vimwiki_rxDelText.'/' - " remove paths - let rem_path = escape(expand(VimwikiGet('path')).subdir, '\') - call map(g:vimwiki_wikiwords, 'substitute(v:val, rem_path, "", "g")') +execute 'syntax match wikiSuperScript /'.g:vimwiki_rxSuperScript.'/' - " Links with subdirs should be highlighted for linux and windows separators - " Change \ or / to [/\\] - let os_p = '[/\\]' - let os_p2 = escape(os_p, '\') - call map(g:vimwiki_wikiwords, 'substitute(v:val, os_p, os_p2, "g")') +execute 'syntax match wikiSubScript /'.g:vimwiki_rxSubScript.'/' - for word in g:vimwiki_wikiwords - if word =~ g:vimwiki_word1 && !s:is_link_to_non_wiki_file(word) - execute 'syntax match wikiWord /\%(^\|[^!]\)\zs\<'.word.'\>/' - endif - execute 'syntax match wikiWord /\[\[\<'. - \ vimwiki#unsafe_link(word). - \ '\>\%(|\+.*\)*\]\]/' - endfor - execute 'syntax match wikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/' -endfunction -" }}} -function! vimwiki#hl_exists(hl)"{{{ - if !hlexists(a:hl) - return 0 - endif - redir => hlstatus - exe "silent hi" a:hl - redir END - return (hlstatus !~ "cleared") -endfunction -"}}} +execute 'syntax match wikiCode /'.g:vimwiki_rxCode.'/' -"}}} -" WIKI functions {{{ -function! vimwiki#WikiNextWord() "{{{ - call s:search_word(g:vimwiki_rxWikiWord, '') -endfunction -" }}} -function! vimwiki#WikiPrevWord() "{{{ - call s:search_word(g:vimwiki_rxWikiWord, 'b') -endfunction -" }}} -function! vimwiki#WikiFollowWord(split) "{{{ - if a:split == "split" - let cmd = ":split " - elseif a:split == "vsplit" - let cmd = ":vsplit " - else - let cmd = ":e " - endif - let word = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWikiWord)) - " insert doesn't work properly inside :if. Check :help :if. - if word == "" - execute "normal! \n" - return - endif - if s:is_link_to_non_wiki_file(word) - call s:edit_file(cmd, word) - else - let vimwiki_prev_word = [expand('%:p'), getpos('.')] - let subdir = vimwiki#current_subdir() - call s:edit_file(cmd, VimwikiGet('path').subdir.word.VimwikiGet('ext')) - let b:vimwiki_prev_word = vimwiki_prev_word - endif -endfunction -" }}} -function! vimwiki#WikiGoBackWord() "{{{ - if exists("b:vimwiki_prev_word") - " go back to saved WikiWord - let prev_word = b:vimwiki_prev_word - execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g') - call setpos('.', prev_word[1]) - endif -endfunction -" }}} -function! vimwiki#WikiGoHome(index) "{{{ - call s:wiki_select(a:index) - call vimwiki#mkdir(VimwikiGet('path')) +"
horizontal rule +execute 'syntax match wikiHR /'.g:vimwiki_rxHR.'/' - try - execute ':e '.VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext') - catch /E37/ " catch 'No write since last change' error - " this is really unsecure!!! - execute ':'.VimwikiGet('gohome').' '. - \ VimwikiGet('path'). - \ VimwikiGet('index'). - \ VimwikiGet('ext') - catch /E325/ " catch 'ATTENTION' error - " TODO: Hmmm, if open already opened index.wiki there is an error... - " Find out what is the reason and how to avoid it. Is it dangerous? - echomsg "Unknown error!" - endtry -endfunction -"}}} -function! vimwiki#WikiDeleteWord() "{{{ - "" file system funcs - "" Delete WikiWord you are in from filesystem - let val = input('Delete ['.expand('%').'] (y/n)? ', "") - if val != 'y' - return - endif - let fname = expand('%:p') - try - call delete(fname) - catch /.*/ - call s:msg('Cannot delete "'.expand('%:t:r').'"!') - return - endtry - execute "bdelete! ".escape(fname, " ") +" List items +execute 'syntax match wikiList /'.g:vimwiki_rxListBullet.'/' +execute 'syntax match wikiList /'.g:vimwiki_rxListNumber.'/' +execute 'syntax match wikiList /'.g:vimwiki_rxListDefine.'/' - " reread buffer => deleted WikiWord should appear as non-existent - if expand('%:p') != "" - execute "e" - endif -endfunction -"}}} -function! vimwiki#WikiRenameWord() "{{{ - "" Rename WikiWord, update all links to renamed WikiWord - let subdir = vimwiki#current_subdir() - let old_fname = subdir.expand('%:t') +" XXX: Think of removing this highlighting. +"============================================================================== +" +" Treat all other lines that start with spaces as PRE-formatted text. +execute 'syntax match wikiPre /'.g:vimwiki_rxPre1.'/ contains=wikiComment' +" syntax region wikiPre start=/\%(^\s\+[*#].*$\)\@' - let new_link = subdir.new_link +if !vimwiki#hl_exists("wikiHeader1") + execute 'syntax match wikiHeader /'.g:vimwiki_rxHeader.'/' +else + " Header levels, 1-6 + execute 'syntax match wikiHeader1 /'.g:vimwiki_rxH1.'/' + execute 'syntax match wikiHeader2 /'.g:vimwiki_rxH2.'/' + execute 'syntax match wikiHeader3 /'.g:vimwiki_rxH3.'/' + execute 'syntax match wikiHeader4 /'.g:vimwiki_rxH4.'/' + execute 'syntax match wikiHeader5 /'.g:vimwiki_rxH5.'/' + execute 'syntax match wikiHeader6 /'.g:vimwiki_rxH6.'/' +endif - " check new_fname - it should be 'good', not empty - if substitute(new_link, '\s', '', 'g') == '' - call s:msg('Cannot rename to an empty filename!') - return - endif - if s:is_link_to_non_wiki_file(new_link) - call s:msg('Cannot rename to a filename with extension (ie .txt .html)!') - return - endif +if !vimwiki#hl_exists("wikiHeader1") + hi def link wikiHeader Title +else + hi def link wikiHeader1 Title + hi def link wikiHeader2 Title + hi def link wikiHeader3 Title + hi def link wikiHeader4 Title + hi def link wikiHeader5 Title + hi def link wikiHeader6 Title +endif - let new_link = s:strip_word(new_link) - let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext') +hi def wikiBold term=bold cterm=bold gui=bold +hi def wikiItalic term=italic cterm=italic gui=italic +hi def wikiBoldItalic term=bold cterm=bold gui=bold,italic +hi def link wikiItalicBold wikiBoldItalic - " do not rename if word with such name exists - let fname = glob(new_fname) - if fname != '' - call s:msg('Cannot rename to "'.new_fname. - \ '". File with that name exist!') - return - endif - " rename WikiWord file - try - echomsg "Renaming ".VimwikiGet('path').old_fname." to ".new_fname - let res = rename(expand('%:p'), expand(new_fname)) - if res != 0 - throw "Cannot rename!" - end - catch /.*/ - call s:msg('Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"') - return - endtry +hi def link wikiCode PreProc +hi def link wikiWord Underlined +hi def link wikiNoExistsWord Error - let &buftype="nofile" +hi def link wikiPre PreProc +hi def link wikiLink Underlined +hi def link wikiList Statement +" hi def link wikiList Identifier +hi def link wikiCheckBox wikiList +hi def link wikiCheckBoxDone Comment +hi def link wikiTable PreProc +hi def link wikiEmoticons Character +hi def link wikiDelText Constant +hi def link wikiSuperScript Number +hi def link wikiSubScript Number +hi def link wikiTodo Todo +hi def link wikiComment Comment - let cur_buffer = [expand('%:p'), - \getbufvar(expand('%:p'), "vimwiki_prev_word")] +let b:current_syntax="vimwiki" +syntax\vimwiki_default.vim [[[1 +79 +" Vimwiki syntax file +" Default syntax +" Author: Maxim Kim +" Home: http://code.google.com/p/vimwiki/ +" vim:tw=78: - let blist = s:get_wiki_buffers() +" text: *strong* +" let g:vimwiki_rxBold = '\*[^*]\+\*' +let g:vimwiki_rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. + \'\*'. + \'\([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`]\)'. + \'\*'. + \'\%([[:punct:]]\|\s\|$\)\@=' - " save wiki buffers - for bitem in blist - execute ':b '.escape(bitem[0], ' ') - execute ':update' - endfor +" text: _emphasis_ +" let g:vimwiki_rxItalic = '_[^_]\+_' +let g:vimwiki_rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. + \'_'. + \'\([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`]\)'. + \'_'. + \'\%([[:punct:]]\|\s\|$\)\@=' - execute ':b '.escape(cur_buffer[0], ' ') - - " remove wiki buffers - for bitem in blist - execute 'bwipeout '.escape(bitem[0], ' ') - endfor - - let setting_more = &more - setlocal nomore +" text: *_bold italic_* or _*italic bold*_ +let g:vimwiki_rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. + \'\*_'. + \'\([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`]\)'. + \'_\*'. + \'\%([[:punct:]]\|\s\|$\)\@=' - " update links - " XXX: doesn't work for [[link|desc link]] - call s:update_wiki_links(old_fname, new_link) +let g:vimwiki_rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. + \'_\*'. + \'\([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`]\)'. + \'\*_'. + \'\%([[:punct:]]\|\s\|$\)\@=' - " restore wiki buffers - for bitem in blist - if bitem[0] != cur_buffer[0] - call s:open_wiki_buffer(bitem) - endif - endfor +" text: `code` +let g:vimwiki_rxCode = '`[^`]\+`' - call s:open_wiki_buffer([new_fname, - \ cur_buffer[1]]) - " execute 'bwipeout '.escape(cur_buffer[0], ' ') +" text: ~~deleted text~~ +let g:vimwiki_rxDelText = '\~\~[^~`]\+\~\~' - echomsg old_fname." is renamed to ".new_fname +" text: ^superscript^ +let g:vimwiki_rxSuperScript = '\^[^^`]\+\^' - let &more = setting_more -endfunction -" }}} -function! vimwiki#WikiUISelect()"{{{ - call s:print_wiki_list() - let idx = input("Select Wiki (specify number): ") - if idx == "" - return - endif - call vimwiki#WikiGoHome(idx) -endfunction -"}}} -" }}} -" TEXT OBJECTS functions {{{ +" text: ,,subscript,, +let g:vimwiki_rxSubScript = ',,[^,`]\+,,' -function! vimwiki#TO_header(inner) "{{{ - if !search('^\(=\+\)[^=]\+\1\s*$', 'bcW') - return - endif - let level = vimwiki#count_first_sym(getline(line('.'))) - normal V - if search('^\(=\{1,'.level.'}\)[^=]\+\1\s*$', 'W') - call cursor(line('.') - 1, 0) - else - call cursor(line('$'), 0) - endif - if a:inner && getline(line('.')) =~ '^\s*$' - let lnum = prevnonblank(line('.') - 1) - call cursor(lnum, 0) - endif -endfunction -"}}} -function! vimwiki#count_first_sym(line) "{{{ - let idx = 0 - while a:line[idx] == a:line[0] && idx < len(a:line) - let idx += 1 - endwhile - return idx -endfunction "}}} +" Header levels, 1-6 +let g:vimwiki_rxH1 = '^\s*=\{1}[^=]\+.*[^=]\+=\{1}\s*$' +let g:vimwiki_rxH2 = '^\s*=\{2}[^=]\+.*[^=]\+=\{2}\s*$' +let g:vimwiki_rxH3 = '^\s*=\{3}[^=]\+.*[^=]\+=\{3}\s*$' +let g:vimwiki_rxH4 = '^\s*=\{4}[^=]\+.*[^=]\+=\{4}\s*$' +let g:vimwiki_rxH5 = '^\s*=\{5}[^=]\+.*[^=]\+=\{5}\s*$' +let g:vimwiki_rxH6 = '^\s*=\{6}[^=]\+.*[^=]\+=\{6}\s*$' +let g:vimwiki_rxHeader = '\%('.g:vimwiki_rxH1.'\)\|'. + \ '\%('.g:vimwiki_rxH2.'\)\|'. + \ '\%('.g:vimwiki_rxH3.'\)\|'. + \ '\%('.g:vimwiki_rxH4.'\)\|'. + \ '\%('.g:vimwiki_rxH5.'\)\|'. + \ '\%('.g:vimwiki_rxH6.'\)' -function! vimwiki#AddHeaderLevel() "{{{ - let lnum = line('.') - let line = getline(lnum) +"
, horizontal rule +let g:vimwiki_rxHR = '^----.*$' - if line =~ '^\s*$' - return - endif +" Tables. Each line starts and ends with '||'; each cell is separated by '||' +let g:vimwiki_rxTable = '||' - if line !~ '^\(=\+\).\+\1\s*$' - let line = substitute(line, '^\s*', ' ', '') - let line = substitute(line, '\s*$', ' ', '') - endif - let level = vimwiki#count_first_sym(line) - if level < 6 - call setline(lnum, '='.line.'=') - endif -endfunction -"}}} -function! vimwiki#RemoveHeaderLevel() "{{{ - let lnum = line('.') - let line = getline(lnum) +" List items start with whitespace(s) then '*' or '#' +let g:vimwiki_rxListBullet = '^\s\+\*' +let g:vimwiki_rxListNumber = '^\s\+#' - if line =~ '^\s*$' - return - endif +let g:vimwiki_rxListDefine = '::\(\s\|$\)' - if line =~ '^\(=\+\).\+\1\s*$' - let line = strpart(line, 1, len(line) - 2) - if line =~ '^\s' - let line = strpart(line, 1, len(line)) - endif - if line =~ '\s$' - let line = strpart(line, 0, len(line) - 1) - endif - call setline(lnum, line) - endif -endfunction -" }}} +" Treat all other lines that start with spaces as PRE-formatted text. +let g:vimwiki_rxPre1 = '^\s\+[^[:blank:]*#].*$' -" }}} -autoload\vimwiki_lst.vim [[[1 -187 -" Vimwiki autoload plugin file -" Todo lists related stuff here. +" Preformatted text +let g:vimwiki_rxPreStart = '{{{' +let g:vimwiki_rxPreEnd = '}}}' +syntax\vimwiki_media.vim [[[1 +61 +" Vimwiki syntax file +" MediaWiki syntax " Author: Maxim Kim " Home: http://code.google.com/p/vimwiki/ +" vim:tw=78: -if exists("g:loaded_vimwiki_list_auto") || &cp - finish -endif -let g:loaded_vimwiki_lst_auto = 1 - -" Script variables {{{ -" used in various checks -let s:rx_list_item = '\('. - \ g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber. - \ '\)' -let s:rx_cb_list_item = s:rx_list_item.'\s*\zs\[.\?\]' -let s:rx_li_box = '\[.\?\]' -let s:rx_li_unchecked = '\[\s\?\]' -" used in substitutions -let s:rx_li_check = '\[x\]' -let s:rx_li_uncheck = '\[ \]' -" }}} +" text: '''strong''' +let g:vimwiki_rxBold = "'''[^']\\+'''" -" Script functions {{{ -" Set state of the list item on line number "lnum" to [ ] or [x] -function! s:set_state(lnum, on_off)"{{{ - let line = getline(a:lnum) - if a:on_off - let state = s:rx_li_check - else - let state = s:rx_li_uncheck - endif - let line = substitute(line, s:rx_li_box, state, '') - call setline(a:lnum, line) -endfunction"}}} +" text: ''emphasis'' +let g:vimwiki_rxItalic = "''[^']\\+''" -" Get state of the list item on line number "lnum" -function! s:get_state(lnum)"{{{ - let state = 1 - let line = getline(a:lnum) - let opt = matchstr(line, s:rx_cb_list_item) - if opt =~ s:rx_li_unchecked - let state = 0 - endif - return state -endfunction"}}} +" text: '''''strong italic''''' +let g:vimwiki_rxBoldItalic = "'''''[^']\\+'''''" +let g:vimwiki_rxItalicBold = g:vimwiki_rxBoldItalic -" Returns 1 if line is list item, 0 otherwise -function! s:is_cb_list_item(lnum)"{{{ - return getline(a:lnum) =~ s:rx_cb_list_item -endfunction"}}} +" text: `code` +let g:vimwiki_rxCode = '`[^`]\+`' -" Returns 1 if line is list item, 0 otherwise -function! s:is_list_item(lnum)"{{{ - return getline(a:lnum) =~ s:rx_list_item -endfunction"}}} +" text: ~~deleted text~~ +let g:vimwiki_rxDelText = '\~\~[^~]\+\~\~' -" Returns char column of checkbox. Used in parent/child checks. -function! s:get_li_pos(lnum) "{{{ - return stridx(getline(a:lnum), '[') -endfunction "}}} +" text: ^superscript^ +let g:vimwiki_rxSuperScript = '\^[^^]\+\^' -" Returns list of line numbers of parent and all its child items. -function! s:get_child_items(lnum)"{{{ - let result = [] - let lnum = a:lnum - let parent_pos = s:get_li_pos(lnum) +" text: ,,subscript,, +let g:vimwiki_rxSubScript = ',,[^,]\+,,' - " add parent - call add(result, lnum) - let lnum += 1 +" Header levels, 1-6 +let g:vimwiki_rxH1 = '^\s*=\{1}[^=]\+.*[^=]\+=\{1}\s*$' +let g:vimwiki_rxH2 = '^\s*=\{2}[^=]\+.*[^=]\+=\{2}\s*$' +let g:vimwiki_rxH3 = '^\s*=\{3}[^=]\+.*[^=]\+=\{3}\s*$' +let g:vimwiki_rxH4 = '^\s*=\{4}[^=]\+.*[^=]\+=\{4}\s*$' +let g:vimwiki_rxH5 = '^\s*=\{5}[^=]\+.*[^=]\+=\{5}\s*$' +let g:vimwiki_rxH6 = '^\s*=\{6}[^=]\+.*[^=]\+=\{6}\s*$' +let g:vimwiki_rxHeader = '\%('.g:vimwiki_rxH1.'\)\|'. + \ '\%('.g:vimwiki_rxH2.'\)\|'. + \ '\%('.g:vimwiki_rxH3.'\)\|'. + \ '\%('.g:vimwiki_rxH4.'\)\|'. + \ '\%('.g:vimwiki_rxH5.'\)\|'. + \ '\%('.g:vimwiki_rxH6.'\)' - while s:is_cb_list_item(lnum) && - \ s:get_li_pos(lnum) > parent_pos && - \ lnum <= line('$') +"
, horizontal rule +let g:vimwiki_rxHR = '^----.*$' - call add(result, lnum) - let lnum += 1 - endwhile +" Tables. Each line starts and ends with '||'; each cell is separated by '||' +let g:vimwiki_rxTable = '||' - return result -endfunction"}}} +" Bulleted list items start with whitespace(s), then '*' +" highlight only bullets and digits. +let g:vimwiki_rxListBullet = '^\s*\*\+\([^*]*$\)\@=' +let g:vimwiki_rxListNumber = '^\s*#\+' -" Returns list of line numbers of all items of the same level. -function! s:get_sibling_items(lnum)"{{{ - let result = [] - let lnum = a:lnum - let ind = s:get_li_pos(lnum) +let g:vimwiki_rxListDefine = '^\%(;\|:\)\s' - while s:is_cb_list_item(lnum) && - \ s:get_li_pos(lnum) >= ind && - \ lnum <= line('$') +" Treat all other lines that start with spaces as PRE-formatted text. +let g:vimwiki_rxPre1 = '^\s\+[^[:blank:]*#].*$' - if s:get_li_pos(lnum) == ind - call add(result, lnum) - endif - let lnum += 1 - endwhile +" Preformatted text +let g:vimwiki_rxPreStart = '
'
+let g:vimwiki_rxPreEnd = '<\/pre>'
+ftplugin\vimwiki.vim	[[[1
+222
+" Vimwiki filetype plugin file
+" Author: Maxim Kim 
+" Home: http://code.google.com/p/vimwiki/
 
-  let lnum = a:lnum - 1
-  while s:is_cb_list_item(lnum) &&
-        \ s:get_li_pos(lnum) >= ind &&
-        \ lnum >= 0
+if exists("b:did_ftplugin")
+  finish
+endif
+let b:did_ftplugin = 1  " Don't load another plugin for this buffer
 
-    if s:get_li_pos(lnum) == ind
-      call add(result, lnum)
-    endif
-    let lnum -= 1
-  endwhile
+" UNDO list {{{
+" Reset the following options to undo this plugin.
+let b:undo_ftplugin = "setlocal wrap< linebreak< ".
+      \ "suffixesadd< isfname< comments< ".
+      \ "autowriteall< ".
+      \ "formatoptions< foldtext< ".
+      \ "foldmethod< foldexpr< commentstring< "
+" UNDO }}}
 
-  return result
-endfunction"}}}
+" MISC STUFF {{{
 
-" Returns line number of the parent of lnum item
-function! s:get_parent_item(lnum)"{{{
-  let lnum = a:lnum
-  let ind = s:get_li_pos(lnum)
+setlocal wrap
+setlocal linebreak
+setlocal autowriteall
+setlocal commentstring=
+" MISC }}}
 
-  while s:is_cb_list_item(lnum) &&
-        \ s:get_li_pos(lnum) >= ind &&
-        \ lnum >= 0
-    let lnum -= 1
-  endwhile
+" GOTO FILE: gf {{{
+execute 'setlocal suffixesadd='.VimwikiGet('ext')
+setlocal isfname-=[,]
+" gf}}}
 
-  if s:is_cb_list_item(lnum)
-    return lnum
-  else
-    return a:lnum
-  endif
-endfunction"}}}
+" COMMENTS: autocreate list items {{{
+" for list items, and list items with checkboxes
+if VimwikiGet('syntax') == 'default'
+  setl comments=b:\ *\ [\ ],b:\ *[\ ],b:\ *\ [],b:\ *[],b:\ *\ [x],b:\ *[x]
+  setl comments+=b:\ #\ [\ ],b:\ #[\ ],b:\ #\ [],b:\ #[],b:\ #\ [x],b:\ #[x]
+  setl comments+=b:\ *,b:\ #
+else
+  setl comments=n:*\ [\ ],n:*[\ ],n:*\ [],n:*[],n:*\ [x],n:*[x]
+  setl comments+=n:#\ [\ ],n:#[\ ],n:#\ [],n:#[],n:#\ [x],n:#[x]
+  setl comments+=n:*,n:#
+endif
+setlocal formatoptions=ctnqro
+" COMMENTS }}}
 
-" Creates checkbox in a list item.
-function s:create_cb_list_item(lnum) "{{{
+" FOLDING for headers and list items using expr fold method. {{{
+if VimwikiGet('folding')
+  setlocal fdm=expr
+endif
+setlocal foldexpr=VimwikiFoldLevel(v:lnum)
+function! VimwikiFoldLevel(lnum) "{{{
   let line = getline(a:lnum)
-  let m = matchstr(line, s:rx_list_item)
-  if m != ''
-    let line = m.' [ ]'.strpart(line, len(m))
-    call setline(a:lnum, line)
+  let nline = getline(a:lnum + 1)
+
+  " Header folding...
+  if line =~ g:vimwiki_rxHeader
+    let n = vimwiki#count_first_sym(line)
+    return '>' . n
   endif
-endfunction "}}}
 
-" Script functions }}}
+  if g:vimwiki_fold_empty_lines == 0
+    let nnline = getline(nextnonblank(a:lnum + 1))
+    if nnline =~ g:vimwiki_rxHeader
+      let n = vimwiki#count_first_sym(nnline)
+      return '<' . n
+    endif
+  endif
 
-" Toggle list item between [ ] and [x]
-function! vimwiki_lst#ToggleListItem()"{{{
-  let current_lnum = line('.')
+  " List item folding...
+  let nnum = a:lnum + 1
 
-  if !s:is_cb_list_item(current_lnum)
-    if g:vimwiki_auto_checkbox
-      call s:create_cb_list_item(current_lnum)
+  let rx_list_item = '\('.
+        \ g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.
+        \ '\)'
+  if line =~ rx_list_item && nline =~ rx_list_item
+    return s:get_li_level(a:lnum, nnum)
+  " list is over, remove foldlevel
+  elseif line =~ rx_list_item && nline !~ rx_list_item
+    return s:get_li_level_last(a:lnum)
+  endif
+
+  return '='
+endfunction "}}}
+
+function! s:get_li_level(lnum, nnum) "{{{
+  if VimwikiGet('syntax') == 'media'
+    let level = s:count_first_sym(getline(a:nnum)) -
+          \ s:count_first_sym(getline(a:lnum))
+    if level > 0
+      return "a".level
+    elseif level < 0
+      return "s".abs(level)
+    else
+      return "="
+    endif
+  else
+    let level = ((indent(a:nnum) - indent(a:lnum)) / &sw)
+    if level > 0
+      return "a".level
+    elseif level < 0
+      return "s".abs(level)
+    else
+      return "="
     endif
-    return
   endif
+endfunction "}}}
 
-  let current_state = s:get_state(current_lnum)
-  if  current_state == 0
-    for lnum in s:get_child_items(current_lnum)
-      call s:set_state(lnum, 1)
-      let new_state = 1
-    endfor
+function! s:get_li_level_last(lnum) "{{{
+  if VimwikiGet('syntax') == 'media'
+    return "s".(s:count_first_sym(getline(a:lnum)) - 1)
   else
-    for lnum in s:get_child_items(current_lnum)
-      call s:set_state(lnum, 0)
-      let new_state = 0
-    endfor
+    return "s".(indent(a:lnum) / &sw - 1)
   endif
+endfunction "}}}
 
-  let c_lnum = current_lnum
-  while s:is_cb_list_item(c_lnum)
-    let all_items_checked = 1
-    for lnum in s:get_sibling_items(c_lnum)
-      if s:get_state(lnum) != 1
-        let all_items_checked = 0
-        break
-      endif
-    endfor
+setlocal foldtext=VimwikiFoldText()
+function! VimwikiFoldText() "{{{
+  let line = getline(v:foldstart)
+  return line.' ['.(v:foldend - v:foldstart).'] '
+endfunction "}}}
 
-    let parent_lnum = s:get_parent_item(c_lnum)
-    if parent_lnum == c_lnum
-      break
-    endif
-    call s:set_state(parent_lnum, all_items_checked)
+" FOLDING }}}
 
+" COMMANDS {{{
+command! -buffer Vimwiki2HTML
+      \ call vimwiki_html#Wiki2HTML(expand(VimwikiGet('path_html')),
+      \                             expand('%'))
+command! -buffer VimwikiAll2HTML
+      \ call vimwiki_html#WikiAll2HTML(expand(VimwikiGet('path_html')))
 
-    let c_lnum = parent_lnum
-  endwhile
-endfunction"}}}
-autoload\vimwiki_html.vim	[[[1
-914
-" Vimwiki autoload plugin file
-" Export to HTML
-" Author: Maxim Kim 
-" Home: http://code.google.com/p/vimwiki/
+command! -buffer VimwikiNextWord call vimwiki#WikiNextWord()
+command! -buffer VimwikiPrevWord call vimwiki#WikiPrevWord()
+command! -buffer VimwikiDeleteWord call vimwiki#WikiDeleteWord()
+command! -buffer VimwikiRenameWord call vimwiki#WikiRenameWord()
+command! -buffer VimwikiFollowWord call vimwiki#WikiFollowWord('nosplit')
+command! -buffer VimwikiGoBackWord call vimwiki#WikiGoBackWord()
+command! -buffer VimwikiSplitWord call vimwiki#WikiFollowWord('split')
+command! -buffer VimwikiVSplitWord call vimwiki#WikiFollowWord('vsplit')
 
-" Load only once {{{
-if exists("g:loaded_vimwiki_html_auto") || &cp
-  finish
+command! -buffer VimwikiToggleListItem call vimwiki_lst#ToggleListItem()
+" COMMANDS }}}
+
+" KEYBINDINGS {{{
+if g:vimwiki_use_mouse
+  nmap   
+  nmap   
+  noremap  <2-LeftMouse> :VimwikiFollowWord
+  noremap   :VimwikiSplitWord
+  noremap   :VimwikiVSplitWord
+  noremap   :VimwikiGoBackWord
 endif
-let g:loaded_vimwiki_html_auto = 1
-"}}}
 
-" Warn if html header or html footer do not exist only once. {{{
-let s:warn_html_header = 0
-let s:warn_html_footer = 0
-"}}}
-" TODO: move the next 2 functions into vimwiki#msg and
-function! s:msg(message) "{{{
-  echohl WarningMsg
-  echomsg 'vimwiki: '.a:message
-  echohl None
-endfunction "}}}
+if !hasmapto('VimwikiFollowWord')
+  nmap   VimwikiFollowWord
+endif
+noremap