diff --git a/autoload/elm.vim b/autoload/elm.vim index 6feb0b8..dcb5129 100644 --- a/autoload/elm.vim +++ b/autoload/elm.vim @@ -44,49 +44,9 @@ fun! elm#Format() return endif - " save cursor position, folds and many other things - 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" - call writefile(getline(1, '$'), l:tmpname) - - " call elm-format on the temporary file - let out = system("elm-format " . l:tmpname . " --output " . l:tmpname) - - " if there is no error - if v:shell_error == 0 - try | silent undojoin | catch | endtry - - " replace current file with temp file, then reload buffer - let old_fileformat = &fileformat - call rename(l:tmpname, expand('%')) - silent edit! - let &fileformat = old_fileformat - let &syntax = &syntax - elseif g:elm_format_fail_silently == 0 - 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.. - if empty(l:curw) - silent! loadview - else - call winrestview(l:curw) - endif + let l:curw = winsaveview() + :%! elm-format --stdin + call winrestview(l:curw) endf " Query elm-oracle and echo the type and docs for the word under the cursor.