Update the links when renaming markdown wikis
Two reasons whey the links in markdown wikis are not updated: 1. The markdown link pattern is wrong, should be []() rather than [][]; 2. The logic of getting wiki local var cannot get correct wiki index as: a. the renamed file's buffer is removed and %:p would return empty b. the function that gets the wiki local var depends on buffer's %:p value to find the wiki it belongs to and it would always return -1 and result in the default option values instead the user's option The fix is 1. fix the markdown link pattern regex; 2. keep the renamed file's buffer open during the period of updating the link
This commit is contained in:
committed by
Michael F. Schönitzer
parent
2366523001
commit
599a0e9083
@ -1340,11 +1340,22 @@ function! vimwiki#base#rename_link()
|
||||
execute ':update'
|
||||
endfor
|
||||
|
||||
" activate the renamed buffer
|
||||
execute ':b '.escape(cur_buffer[0], ' ')
|
||||
|
||||
" remove wiki buffers
|
||||
" rename the buffer name to the new name
|
||||
" execute ':file '.new_link
|
||||
|
||||
" leave the renamed buffer and remove the rest wiki buffers
|
||||
" the reason we leave the renamed buffer is because the get_wikilocal
|
||||
" function use the current file name to get the vars of current file's
|
||||
" wiki, but after calling rename function, %:p still returns empty
|
||||
" rather than the new full file path, so we just leave the renamed file's
|
||||
" buffer so that %:p would be the renamed full file path
|
||||
for bitem in blist
|
||||
execute 'bwipeout '.escape(bitem[0], ' ')
|
||||
if !vimwiki#path#is_equal(bitem[0], cur_buffer[0])
|
||||
execute 'bwipeout '.escape(bitem[0], ' ')
|
||||
endif
|
||||
endfor
|
||||
|
||||
let setting_more = &more
|
||||
@ -1353,6 +1364,12 @@ function! vimwiki#base#rename_link()
|
||||
" update links
|
||||
call s:update_wiki_links(wiki_nr, s:tail_name(old_fname), s:tail_name(new_link),old_fname)
|
||||
|
||||
" remove current buffer and reopen it after restoring all
|
||||
" buffers to put it at the end of all buffers, vim does not
|
||||
" support reorder the buffers so need to reopen it to put
|
||||
" it at the end
|
||||
execute 'bwipeout '.escape(cur_buffer[0], ' ')
|
||||
|
||||
" restore wiki buffers
|
||||
for bitem in blist
|
||||
if !vimwiki#path#is_equal(bitem[0], cur_buffer[0])
|
||||
@ -1361,7 +1378,6 @@ function! vimwiki#base#rename_link()
|
||||
endfor
|
||||
|
||||
call s:open_wiki_buffer([new_fname, cur_buffer[1]])
|
||||
" execute 'bwipeout '.escape(cur_buffer[0], ' ')
|
||||
|
||||
echomsg 'Vimwiki: '.old_fname.' is renamed to '.new_fname
|
||||
|
||||
|
Reference in New Issue
Block a user