Specifically, I'd like to set the makeprg option only if it has not been changed yet. Any way to do this?
You can access the contents of an option using &
. So in this case you could check if the option is "empty" like this:
if &makeprg == ""
set makeprg=new_value
endif
--- EDIT ---
Xavier makes the good point that the default value of makeprg
is not an empty string. You can use set {option}&
to set an option to its default, so the following can be used to change the value only if the current value is the default:
function! SetMakePrg( new_value )
let cur_value=&makeprg
" let new_val=a:new_value
set makeprg&
if &makeprg == cur_value
" cur_value is default: set to new value
exe "set makeprg=" . a:new_value
else
" cur_value is not default: change it back
exe "set makeprg=" . cur_value
endif
endfunction
So calling call SetMakePrg("my_make")
will modify the option only if it is not currently the default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With