Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the current ElmFormat with a more lightweight version #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions autoload/elm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down