From 5fc3931aecd8dccad028af61d700ed8f80e09ece Mon Sep 17 00:00:00 2001 From: Rowan Date: Mon, 23 Oct 2023 15:13:34 +0700 Subject: [PATCH] Improve nvim/vim to create undofile after :UndotreePersistUndo. - The undofile will only be created once the buffer has been written to the file. Therefore, it is necessary to write the buffer the first time the :UndotreePersistUndo command is called. - Echo "A persistence undo file has been created." once the persistence undofile has been created. - Add debug logging in the undotree#UndotreePersistUndo function. --- autoload/undotree.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/autoload/undotree.vim b/autoload/undotree.vim index ae8673d..6c19dab 100644 --- a/autoload/undotree.vim +++ b/autoload/undotree.vim @@ -1463,14 +1463,24 @@ function! undotree#UndotreeFocus() abort endfunction function! undotree#UndotreePersistUndo(goSetUndofile = 0) abort + call s:log("undotree#UndotreePersistUndo(" .. a:goSetUndofile .. ")") if ! &undofile if !isdirectory(g:undotree_UndoDir) call mkdir(g:undotree_UndoDir, 'p', 0700) + call s:log(" > [Dir " .. g:undotree_UndoDir .. "] created.") endif exe "set undodir=" .. g:undotree_UndoDir + call s:log(" > [set undodir=" .. g:undotree_UndoDir .. "] executed.") if filereadable(undofile(expand('%'))) || a:goSetUndofile setlocal undofile + call s:log(" > [setlocal undofile] executed") endif + if a:goSetUndofile + silent! write + echo "A persistence undo file has been created." + endif + else + call s:log(" > Undofile has been set. Do nothing.") endif endfunction