junegunn / goyo.vim

:tulip: Distraction-free writing in Vim
MIT License
4.5k stars 115 forks source link

Leaves Airline's tabline visible with only one buffer/tab #58

Closed ches closed 9 years ago

ches commented 9 years ago

This is minor, and I'll see if I can find a workaround myself when I have a few minutes to grok the Goyo code, but just wanted to make note when I saw it.

I use the following settings for Airline:

let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#tab_min_count = 2

Basically this means show a line for tabs at the top, only for real tabpages, and only when there is more than one. If I edit a single file in a Vim session and toggle Goyo on and off, the Airline tabline is left visible for only one tab.

junegunn commented 9 years ago

Thanks for the report. It looks more like an issue of airline. All goyo does about airline is that it executes AirlineToggle when entering the mode and AirlineToggle and AirlineRefresh on exit. I'm not a user of airline, so I don't think I'm going to further look into it.

ches commented 9 years ago

Thanks for your response Junegunn. On first glance I thought that I agreed with you, but on further inspection I think this is actually Goyo's responsibility, because it creates a new tab before getting the values in goyo_revert to restore later. Here is what happens:

  1. Goyo creates a new tab.
  2. Airline sets showtabline to 2 via a TabEnter autocommand because there is now more than one tab.
  3. Goyo now saves the value of showtabline into the goyo_revert dictionary. So it's not storing the user's original setting, it's storing Airline's, which I would argue is why this is Goyo's error.
  4. Goyo turns Airline off with AirlineToggle, which causes Airline to restore showtabline to the user's original value. At this point Airline has done the correct thing.
  5. User switches Goyo off.
  6. Goyo restores the value of 2 to showtabline, overwriting the user's actual original showtabline value which Airline had already restored when it was toggled off.

Fundamentally, I think it would be wise if Goyo saved all of its setting values to restore before changing any Vim state, e.g. creating a new tab. For demonstration, this patch fixes the problem:

diff --git a/autoload/goyo.vim b/autoload/goyo.vim
index e4a904f..0e9b881 100644
--- a/autoload/goyo.vim
+++ b/autoload/goyo.vim
@@ -161,6 +161,8 @@ endfunction
 function! s:goyo_on(width)
   let s:orig_tab = tabpagenr()

+  let orig_showtabline = &showtabline
+
   " New tab
   tab split

@@ -172,7 +174,7 @@ function! s:goyo_on(width)
   let t:goyo_pads = {}
   let t:goyo_revert =
     \ { 'laststatus':     &laststatus,
-    \   'showtabline':    &showtabline,
+    \   'showtabline':    orig_showtabline,
     \   'fillchars':      &fillchars,
     \   'winminwidth':    &winminwidth,
     \   'winwidth':       &winwidth,
junegunn commented 9 years ago

Okay, I see. Thanks for the investigation. I'll update the code and let you know.

junegunn commented 9 years ago

Could update and test if it solves the problem?

ches commented 9 years ago

Yep that resolves it, thanks for the quick response and the plugin!

junegunn commented 9 years ago

:+1: