diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2020-03-05 12:30:24 +0100 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-03-05 12:30:24 +0100 | 
| commit | e86e0ad36ef9501acbc3e8c63a1d4fab104e47cb (patch) | |
| tree | b9581527c6b4c0590bc79d5fd8ea5cfaf8df6d12 /autoload | |
| parent | 45ab4d80dd52f6ea40d8e9b7fa5cedd31d9ad9ec (diff) | |
| download | vim-polyglot-e86e0ad36ef9501acbc3e8c63a1d4fab104e47cb.tar.gz vim-polyglot-e86e0ad36ef9501acbc3e8c63a1d4fab104e47cb.zip | |
Update
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/terraform.vim | 29 | 
1 files changed, 21 insertions, 8 deletions
| diff --git a/autoload/terraform.vim b/autoload/terraform.vim index fcc7ba6e..f1a10244 100644 --- a/autoload/terraform.vim +++ b/autoload/terraform.vim @@ -6,21 +6,34 @@ set cpoptions&vim  " Ensure no conflict with arguments from the environment  let $TF_CLI_ARGS_fmt='' -function! terraform#fmt() -  let l:curw = winsaveview() +function! terraform#fmt() abort +  " Save the view. +  let curw = winsaveview() +    " Make a fake change so that the undo point is right.    normal! ix    normal! "_x + +  " Execute `terraform fmt`, redirecting stderr to a temporary file. +  let tmpfile = tempname() +  let shellredir_save = &shellredir +  let &shellredir = '>%s 2>'.tmpfile    silent execute '%!terraform fmt -no-color -' +  let &shellredir = shellredir_save + +  " If there was an error, undo any changes and show stderr.    if v:shell_error != 0 -    let output = getline(1, '$')      silent undo +    let output = readfile(tmpfile)      echo join(output, "\n")    endif -  call winrestview(l:curw) + +  " Delete the temporary file, and restore the view. +  call delete(tmpfile) +  call winrestview(curw)  endfunction -function! terraform#align() +function! terraform#align() abort    let p = '^.*=[^>]*$'    if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)      let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) @@ -31,8 +44,8 @@ function! terraform#align()    endif  endfunction -function! terraform#commands(ArgLead, CmdLine, CursorPos) -  let l:commands = [ +function! terraform#commands(ArgLead, CmdLine, CursorPos) abort +  let commands = [      \ 'apply',      \ 'console',      \ 'destroy', @@ -58,7 +71,7 @@ function! terraform#commands(ArgLead, CmdLine, CursorPos)      \ 'push',      \ 'state'    \ ] -  return join(l:commands, "\n") +  return join(commands, "\n")  endfunction  let &cpoptions = s:cpo_save | 
