amix / vim-zenroom2

A Vim extension that emulates iA Writer environment when editing Markdown, reStructuredText or text files
254 stars 21 forks source link

Should not override `g:goyo_callbacks` when already defined #4

Closed junegunn closed 9 years ago

junegunn commented 10 years ago

Related: https://github.com/junegunn/goyo.vim/pull/11 (/cc @leeor)

Hi, currently zenroom2 defines g:goyo_callbacks even when it's already defined in .vimrc, so the user cannot further customize the Goyo window when zenroom2 is installed.

I think there are two approaches you can take

  1. Do not override g:goyo_callback when it's already defined
  2. Call user callbacks in zenroom callbacks

The first option is simpler, but the documentation should mention that the user should explicitly call g:zenroom_goyo_before and g:zenroom_goyo_after in his callback functions, as described in https://github.com/junegunn/goyo.vim/pull/11#issuecomment-31337259

The second approach is also trivial to implement.

if exists('g:goyo_callbacks')
    let s:user_callbacks = copy(g:goyo_callbacks)
endif

function! g:zenroom_goyo_before()
    silent! call s:user_callbacks[0]()
    " ...
endfunction

function! g:zenroom_goyo_after()
    silent! call s:user_callbacks[1]()
    " ...
endfunction

The advantage of this approach is that the user doesn't need to do anything. But it could be confusing when the user updates or changes his callback function after zenroom2 is loaded (less likely though)

amix commented 10 years ago

I like solution 2)! Could you please provide a patch. Thanks!

junegunn commented 9 years ago

Hi, just to let you know, Goyo now recommends using GoyoEnter and GoyoLeave events instead of g:goyo_callbacks for customization. Since we can now register any number of custom callbacks to those events, this issue can be easily solved.