vimwiki

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

commit 59402cdf8b0d21226da4eee4d87bfba2ff8e43f5
parent fea8bee382b2051b0137fd2cacf0862823ee69b3
Author: Tinmarino <tinmarino@gmail.com>
Date:   Fri, 10 Mar 2023 13:54:40 -0300

Highlight markdown typeface more compliant with Github Flavoured Markdown

Diffstat:
Mautoload/vimwiki/base.vim | 41+++++++++++++++++++++++++++--------------
Mautoload/vimwiki/diary.vim | 19+++++++++++--------
Mautoload/vimwiki/html.vim | 10+++++-----
Mautoload/vimwiki/u.vim | 59+++++++++++++++++++++++++++++++++++++++++++++++++----------
Mautoload/vimwiki/vars.vim | 4++--
Mftplugin/vimwiki.vim | 2--
6 files changed, 94 insertions(+), 41 deletions(-)

diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim @@ -500,7 +500,7 @@ function! vimwiki#base#goto(...) abort " Save current file pos let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')] - call vimwiki#base#edit_file(':e', + call vimwiki#base#edit_file('edit', \ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'), \ anchor, \ vimwiki_prev_link, @@ -1120,7 +1120,7 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort " which happens if we jump to an achor in the current file. " This hack is necessary because apparently Vim messes up the result of " getpos() directly after this command. Strange. - if !(a:command ==# ':e ' && vimwiki#path#is_equal(a:filename, expand('%:p'))) + if !(a:command =~# ':\?[ed].*' && vimwiki#path#is_equal(a:filename, expand('%:p'))) try execute a:command fname catch /E37:/ @@ -1130,6 +1130,10 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort catch /E325:/ call vimwiki#u#warn('Vim couldn''t open the file, probably because a swapfile already exists. See :h E325.') return + catch /E319:/ + call vimwiki#u#warn('Vim couldn''t open the file, cannot launch the drop command. See :h E319.') + execute 'edit' fname + return endtry " If the opened file was not already loaded by Vim, an autocommand is " triggered at this point @@ -1391,7 +1395,7 @@ endfunction function! s:open_wiki_buffer(item) abort " Edit wiki file. " Called: by rename_file: Usefull for buffer commands - call vimwiki#base#edit_file(':e', a:item[0], '') + call vimwiki#base#edit_file('edit', a:item[0], '') if !empty(a:item[1]) call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0]) endif @@ -1665,23 +1669,26 @@ function! vimwiki#base#follow_link(split, ...) abort endif if a:split ==# 'hsplit' - let cmd = ':split ' + let cmd = 'split' elseif a:split ==# 'vsplit' - let cmd = ':vsplit ' + let cmd = 'vsplit' elseif a:split ==# 'badd' - let cmd = ':badd ' + let cmd = 'badd' elseif a:split ==# 'tab' - let cmd = ':tabnew ' + let cmd = 'tabnew' elseif a:split ==# 'tabdrop' " Use tab drop if we've already got the file open in an existing tab - let cmd = ':tab drop ' + let cmd = 'tab edit' + if exists(':drop') == 2 + let cmd = 'tab drop' + endif else " Same as above - doing this by default reduces incidence of multiple " tabs with the same file. We default to :e just in case :drop doesn't " exist in the current build. - let cmd = ':e ' - if exists(':drop') - let cmd = ':drop ' + let cmd = 'edit' + if exists(':drop') == 2 && has('windows') + let cmd = 'drop' endif endif @@ -1691,7 +1698,7 @@ function! vimwiki#base#follow_link(split, ...) abort let previous_window_nr = winnr('#') if previous_window_nr > 0 && previous_window_nr != winnr() execute previous_window_nr . 'wincmd w' - let cmd = ':e' + let cmd = ':edit' endif endif @@ -1739,8 +1746,14 @@ function! vimwiki#base#go_back_link() abort " Jump to target with edit_file if !empty(prev_link) " go back to saved wiki link - call vimwiki#base#edit_file(':e ', prev_link[0], '') - call setpos('.', prev_link[1]) + " Change file if required lazy + let file = prev_link[0] + let pos = prev_link[1] + " Removed the filereadable check for Vader + if !(vimwiki#path#is_equal(file, expand('%:p'))) + call vimwiki#base#edit_file('edit', file, '') + endif + call setpos('.', pos) else " maybe we came here by jumping to a tag -> pop from the tag stack silent! pop! diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim @@ -299,20 +299,23 @@ function! vimwiki#diary#make_note(wnum, ...) abort call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr). \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr)) - let cmd = 'edit' + let cmd = ':edit' if a:0 if a:1 == 1 - let cmd = 'tabedit' + let cmd = ':tabedit' elseif a:1 == 2 - let cmd = 'split' + let cmd = ':split' elseif a:1 == 3 - let cmd = 'vsplit' + let cmd = ':vsplit' elseif a:1 == 4 - let cmd = 'tab drop' + let cmd = ':tab edit' + if exists(':drop') == 2 + let cmd = ':tab drop' + endif elseif a:1 == 5 - let cmd = 'drop' - if exists(':drop') - let cmd = 'drop' + let cmd = ':edit' + if exists(':drop') == 2 + let cmd = ':drop' endif endif endif diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim @@ -1884,26 +1884,26 @@ function! s:convert_file(path_html, wikifile) abort endif call vimwiki#path#mkdir(path_html) - if g:vimwiki_global_vars['listing_hl'] > 0 && has("unix") + if g:vimwiki_global_vars['listing_hl'] > 0 && has('unix') let i = 0 while i < len(html_lines) - if html_lines[i] =~ '^<pre .*type=.\+>' + if html_lines[i] =~# '^<pre .*type=.\+>' let type = split(split(split(html_lines[i], 'type=')[1], '>')[0], '\s\+')[0] let attr = split(split(html_lines[i], '<pre ')[0], '>')[0] let start = i + 1 let cur = start - while html_lines[cur] !~ '^<\/pre>' + while html_lines[cur] !~# '^<\/pre>' let cur += 1 endwhile let tmp = ('tmp'. split(system('mktemp -p . --suffix=.' . type, 'silent'), 'tmp')[-1])[:-2] - call system('echo ' . shellescape(join(html_lines[start:cur - 1], '\n')) . ' > ' . tmp) + call system('echo ' . shellescape(join(html_lines[start : cur - 1], '\n')) . ' > ' . tmp) call system(g:vimwiki_global_vars['listing_hl_command'] . ' ' . tmp . ' > ' . tmp . '.html') let html_out = system('cat ' . tmp . '.html') call system('rm ' . tmp . ' ' . tmp . '.html') let i = cur - let html_lines = html_lines[0:start - 1] + split(html_out, '\n') + html_lines[cur:] + let html_lines = html_lines[0 : start - 1] + split(html_out, '\n') + html_lines[cur : ] endif let i += 1 endwhile diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim @@ -304,18 +304,55 @@ function! vimwiki#u#hi_expand_regex(lst) abort " :param: list<list,delimiters>> with reduced regex " Return: list with extended regex delimiters (not inside a word) " -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*\%(\s\|$\)\@=']] + " Note: For purposes of this definition, the beginning and the end of the line count as Unicode whitespace. " See: https://github.github.com/gfm/#left-flanking-delimiter-run let res = [] - let p = vimwiki#u#get_punctuation_string() - for delimiters in a:lst - let r_prefix = '\(^\|[[:space:]]\@<=\)' - " Regex Start: not preceded by backslash, not ended by space - let r_start = r_prefix . delimiters[0] . '\S\@=' - " Regex End: not preceded by backslash or space, ended by punctuation or space - let r_prefix = '\(^\|[^[:space:]\\]\@<=\)' - let r_end = r_prefix . delimiters[1] . '\%(\_[[:space:]' . p . ']\)\@=' + let punctuation = vimwiki#u#get_punctuation_string() + + " Iterate on (left delimiter, right delimiter pair) + for a_delimiter in a:lst + let r_left_del = a_delimiter[0] + let r_right_del = a_delimiter[1] + + " Regex Start: + " Left-Flanking is not followed by space (or ned of line) + let r_left_prefix = '\%(^\|[[:space:]]\@<=\)' + let r_left_prefix = '\\\@<!' + " -- not followed by Unicode whitespace, + let r_left_suffix = '\%([^[:space:]]\@=\)' + + " Left Case1: not followed by punctuation + let r_left_suffix1 = '\%(\%([^[:space:]' . punctuation . ']\)\@=\)' + " -- Can escape the leftflank + let r_left_prefix1 = '\%(^\|\\\@<!\)' + + " Left Case2: followed by punctuation so must be preceded by Unicode whitespace or start of line or a punctuation character. + let r_left_suffix2 = '\%([' . punctuation . ']\@=\)' + let r_left_prefix2 = '\%(\%(^\|[[:space:]' . punctuation . ']\)\@<=\)' + + " Left Concatenate + let r_start = '\%(' . r_left_prefix1 . r_left_del . r_left_suffix1 + let r_start .= '\|' . r_left_prefix2 . r_left_del . r_left_suffix2 . '\)' + + " Regex End: + " not preceded by Unicode whitespace + let r_right_prefix = '\(^\|[^[:space:]]\@<=\)' + + " Right Case1: not preceded by a punctuation character (or start of line) + let r_right_prefix1 = '\%(\%(^\|[^[:space:]' . punctuation . ']\)\@<=\)' + let r_right_suffix1 = '' + + " Right Case2: preceded by a punctuation character and followed by Unicode whitespace or end of line or a punctuation character + let r_right_prefix2 = '\%([' . punctuation . ']\@<=\)' + let r_right_suffix2 = '\%(\%($\|[[:space:]' . punctuation . ']\)\@<=\)' + + " Right Concatenate + let r_end = '\%(' . r_right_prefix1 . r_right_del . r_right_suffix1 + let r_end .= '\|' . r_right_prefix2 . r_right_del . r_right_suffix2 . '\)' + call add(res, [r_start, r_end]) endfor + return res endfunction @@ -337,9 +374,9 @@ function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort endif " Craft command + " \ 'skip="\\' . a:tag_pre . '" ' . let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiDelimiter ' . \ opt_is_contained . - \ 'skip="\\' . a:tag_pre . '" ' . \ 'start="' . a:tag_pre . '" ' . \ 'end="' . a:tag_post . '" ' . \ 'keepend ' . @@ -442,5 +479,7 @@ function! vimwiki#u#hi_typeface(dic) abort " Prevent var_with_underscore to trigger italic text " -- See $VIMRUNTIME/syntax/markdown.vim - syn match VimwikiError "\w\@<=[_*]\w\@=" + " But leave + " -- See https://github.github.com/gfm/#example-364 + syn match VimwikiError "\w\@<=_\w\@=" endfunction diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim @@ -755,9 +755,9 @@ function! s:get_markdown_syntaxlocal() abort \ 'underline': vimwiki#u#hi_expand_regex([]), \ 'bold_italic': vimwiki#u#hi_expand_regex([['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']]), \ 'code': [ - \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=', + \ ['\%(^\|[^`\\]\)\@<=`\%($\|[^`]\)\@=', \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='], - \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=', + \ ['\%(^\|[^`\\]\)\@<=``\%($\|[^`]\)\@=', \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='], \ ], \ 'del': [['\~\~', '\~\~']], diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim @@ -452,8 +452,6 @@ if str2nr(vimwiki#vars#get_global('key_mappings').links) call vimwiki#u#map_key('n', '+', '<Plug>VimwikiNormalizeLink') call vimwiki#u#map_key('v', '+', '<Plug>VimwikiNormalizeLinkVisual') call vimwiki#u#map_key('v', '<CR>', '<Plug>VimwikiNormalizeLinkVisualCR') - call vimwiki#u#map_key('n', '<D-CR>', '<Plug>VimwikiTabDropLink') - call vimwiki#u#map_key('n', '<C-S-CR>', '<Plug>VimwikiTabDropLink', 1) call vimwiki#u#map_key('n', '<BS>', '<Plug>VimwikiGoBackLink') call vimwiki#u#map_key('n', '<TAB>', '<Plug>VimwikiNextLink') call vimwiki#u#map_key('n', '<S-TAB>', '<Plug>VimwikiPrevLink')