hashivim / vim-terraform

basic vim/terraform integration
http://hashivim.github.io/vim-terraform
ISC License
1.07k stars 111 forks source link

Check if fmt is necessary before running fmt #178

Closed 0az closed 1 year ago

0az commented 1 year ago

This is a hack, but this keeps terraform#fmt from setting modified unnecessarily.

A non-robust alternate implementation from my vimrc before I installed vim-terraform is as follows:

function! s:fmt()
    if &modified || ! &modifiable
        let pos = winsaveview()
        exe 'silent %!terraform fmt -'
        call winrestview(pos)
    else
        call system('terraform fmt ' .. shellescape(expand('%')))
        checkt
    endif
endfunc
0az commented 1 year ago

PR comments addressed.

I think I'm okay with this, though running the formatter twice is not ideal.

Yeah, a better solution might be checking &modified || ! &modifiable, but that has its own complexities…

dimbleby commented 1 year ago

well, we'll see if anyone complains. Thanks!