Skip to content

optional two spaces #86

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ let g:elm_setup_keybindings = 0

## Integration

### Automatically Format Upon Save

To automatically format your code before a save, add the following to your `.vimrc`

```vim
au BufWritePre *.elm call elm#Format()
```

### [Syntastic](https://github.com/scrooloose/syntastic)

Syntastic support should work out of the box, but we recommend the following settings:
Expand Down Expand Up @@ -113,6 +121,7 @@ let g:elm_detailed_complete = 0
let g:elm_format_autosave = 0
let g:elm_format_fail_silently = 0
let g:elm_setup_keybindings = 1
let g:elm_format_two_spaces = 1
```

* `:ElmMake [filename]` calls `elm-make` with the given file. If no file is given it uses the current file being edited.
Expand Down
4 changes: 4 additions & 0 deletions autoload/elm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ fun! elm#Format()
" 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('%'))
if get(g:, "elm_format_two_spaces", 0) == 1
call system("sed -e 's/^/~/' -e ': r' -e 's/^\\( *\\)~ /\\1 ~/' -e 't r' -e 's/~//' -i " . expand('%'))
endif
silent edit!
let &fileformat = old_fileformat
let &syntax = &syntax
Expand Down