[nvim] Fix zettelkasten wiki fw/bw navigation
Fixed navigating backwards ignoring any files jumped to via the Zettelkasten function and only moving to the last wiki.vim jumped-to file. Now correctly navigates to any file in the chain, be that zk or wiki by invoking the correct wiki.vim page opening function.
This commit is contained in:
parent
6a22991026
commit
e913d1c176
2 changed files with 35 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
||||||
" PLUGIN: wiki.vim
|
" PLUGIN: wiki.vim
|
||||||
if $WIKIROOT ==? ""
|
if $WIKIROOT ==? ''
|
||||||
let g:wiki_root = expand('~/documents/notes')
|
let g:wiki_root = expand('~/documents/notes')
|
||||||
else
|
else
|
||||||
let g:wiki_root = $WIKIROOT
|
let g:wiki_root = $WIKIROOT
|
||||||
|
@ -28,61 +28,49 @@ let g:wiki_file_open = 'WikiFileOpen'
|
||||||
|
|
||||||
" Zettelkasten functionality
|
" Zettelkasten functionality
|
||||||
|
|
||||||
" Creates a Zettelkasten compatible unique datestamp
|
|
||||||
function s:Getdatestamp()
|
|
||||||
if !exists("*strftime")
|
|
||||||
:echoerr "Date Stamp creation needs strftime available on system!"
|
|
||||||
endif
|
|
||||||
return strftime("%y%m%d%H%M")
|
|
||||||
endfunction
|
|
||||||
command! Datestamp :echom s:Getdatestamp()
|
|
||||||
|
|
||||||
" Appends Zettelkasten timestamp to beginning of links
|
" Appends Zettelkasten timestamp to beginning of links
|
||||||
function! ZettelLink(text) abort
|
function! ZettelLinkCreate(text) abort
|
||||||
" lowercase and replace spaces with dashes (-) to make links uniform
|
" lowercase and replace spaces with dashes (-) to make links uniform
|
||||||
let l:text=substitute(tolower(a:text), '\s\+', '-', 'g')
|
let l:text=substitute(tolower(a:text), '\s\+', '-', 'g')
|
||||||
" prepend datestamp
|
" prepend datestamp
|
||||||
let l:text=substitute(l:text, '^', s:Getdatestamp() . ' '. '\0', 'g')
|
let l:text=substitute(l:text, '^', s:Datestamp() . ' '. '\0', 'g')
|
||||||
return l:text
|
return l:text
|
||||||
endfunction
|
endfunction
|
||||||
" sets wiki.vim to automatically apply datestamp function to created links
|
" sets wiki.vim to automatically apply datestamp function to created links
|
||||||
let g:wiki_map_link_create = "ZettelLink"
|
let g:wiki_map_link_create = 'ZettelLinkCreate'
|
||||||
|
|
||||||
|
let g:zettel_anchor_separator = ' '
|
||||||
|
let g:zettel_anchor_pattern = '[:/]\d\{10,14} '
|
||||||
" Returns the full path to the Zettel owning the anchor id passed in
|
" Returns the full path to the Zettel owning the anchor id passed in
|
||||||
function! s:GetZettelPath(anchor) abort
|
function! s:GetZettelPath(anchor) abort
|
||||||
" match first 10-digit-beggining file ending with .md
|
" match first 10-digit-beggining file ending with .md
|
||||||
" e.g. 1906061330 My example-Zettel.md
|
" e.g. 1906061330 My example-Zettel.md
|
||||||
let l:tomatch='/' . trim(a:anchor) . ' .*\.md'
|
let l:tomatch='/' . trim(a:anchor) . g:zettel_anchor_separator . '.*\.md'
|
||||||
let l:notes=split(globpath(g:wiki_root, '**'), '\n')
|
let l:allnotes=split(globpath(g:wiki_root, '**'), '\n')
|
||||||
|
|
||||||
let l:match=match(l:notes, l:tomatch)
|
" get absolute path
|
||||||
if l:match == -1
|
let l:matched = matchstr(l:allnotes, l:tomatch)
|
||||||
return ""
|
" make path relative to root to pass back to wiki.vim
|
||||||
else
|
let l:curfpath = expand('%:p:h')
|
||||||
return fnameescape(l:notes[l:match])
|
let l:matched = substitute(l:matched, l:curfpath, '', '')
|
||||||
endif
|
|
||||||
|
return l:matched
|
||||||
endfunction
|
endfunction
|
||||||
command! -nargs=1 ZettelOpen execute ":e " . s:GetZettelPath(<q-args>)
|
command! -nargs=1 ZettelOpen execute ":e " . s:GetZettelPath(<q-args>)
|
||||||
|
|
||||||
" Returns only the anchor id in a file name
|
|
||||||
" - returns empty string if nothing was found
|
|
||||||
function! s:ExtractAnchor(file) abort
|
|
||||||
return trim(matchstr(a:file, '[:/]\d\{10,14} '), ' \t\r:/')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Uses the Zettel Anchor ID instead of the whole link structure to traverse
|
" Uses the Zettel Anchor ID instead of the whole link structure to traverse
|
||||||
" the whole Wiki directory from its root and opens first fitting Zettel
|
" the whole Wiki directory from its root and opens first fitting Zettel
|
||||||
function! ZettelOpenAtCursor(...) abort
|
function! ZettelOpenAtCursor(...) abort
|
||||||
let l:link = wiki#link#get_at_cursor()
|
let l:link = wiki#link#get_at_cursor()
|
||||||
try
|
try
|
||||||
let l:zettel = s:GetZettelPath( s:ExtractAnchor(l:link.url) )
|
let l:zettel = s:GetZettelPath( s:ExtractZettelAnchor(l:link.url) )
|
||||||
|
|
||||||
" fall back to normal link opening otherwise
|
" fall back to normal link opening otherwise
|
||||||
if l:zettel ==? ""
|
if l:zettel ==? ''
|
||||||
call call(l:link.open, a:000, l:link)
|
call wiki#link#open()
|
||||||
else
|
else
|
||||||
execute ":e " . l:zettel
|
call wiki#page#open(l:zettel)
|
||||||
" call call(l:link.open, a:000, l:link)
|
|
||||||
endif
|
endif
|
||||||
catch /E716:/
|
catch /E716:/
|
||||||
call wiki#link#toggle(l:link)
|
call wiki#link#toggle(l:link)
|
||||||
|
@ -91,3 +79,18 @@ function! ZettelOpenAtCursor(...) abort
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
command! ZettelOpenAtCursor :call ZettelOpenAtCursor()
|
command! ZettelOpenAtCursor :call ZettelOpenAtCursor()
|
||||||
|
|
||||||
|
" Returns only the anchor id in a file name
|
||||||
|
" - returns empty string if nothing was found
|
||||||
|
function! s:ExtractZettelAnchor(file) abort
|
||||||
|
return trim(matchstr(a:file, g:zettel_anchor_pattern), ' \t\r:/')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Creates a Zettelkasten compatible unique datestamp
|
||||||
|
function s:Datestamp()
|
||||||
|
if !exists('*strftime')
|
||||||
|
:echoerr 'Date Stamp creation needs strftime available on system!'
|
||||||
|
endif
|
||||||
|
return strftime('%y%m%d%H%M')
|
||||||
|
endfunction
|
||||||
|
command! Datestamp :echom s:Datestamp()
|
||||||
|
|
|
@ -37,3 +37,4 @@ UNSC
|
||||||
plugin
|
plugin
|
||||||
Solidarność
|
Solidarność
|
||||||
transnationalism
|
transnationalism
|
||||||
|
heroization
|
||||||
|
|
Loading…
Reference in a new issue