Skip to content

Commit

Permalink
Save and restore undo history when running elm format
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Hager committed Oct 1, 2016
1 parent 4fc33e2 commit 2a8eb1c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions autoload/elm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ fun! elm#Format()
endif

" save cursor position, folds and many other things
mkview!
let l:curw = {}
try
mkview!
catch
let l:curw = winsaveview()
endtry

" save our undo file to be restored after we are done.
let tmpundofile = tempname()
exe 'wundo! ' . tmpundofile

" write current unsaved buffer to a temporary file
let l:tmpname = tempname() . ".elm"
Expand All @@ -68,8 +77,16 @@ fun! elm#Format()
call elm#util#EchoLater("EchoError", "elm-format:", out)
endif

" save our undo history
silent! exe 'rundo ' . tmpundofile
call delete(tmpundofile)

" restore our cursor/windows positions, folds, etc..
silent! loadview
if empty(l:curw)
silent! loadview
else
call winrestview(l:curw)
endif
endf

" Query elm-oracle and echo the type and docs for the word under the cursor.
Expand Down

0 comments on commit 2a8eb1c

Please sign in to comment.