Allow switching of buffers in Goyo mode (Fix #31)

This commit is contained in:
Junegunn Choi
2014-11-24 02:16:35 +09:00
parent 8b74a603e5
commit b16a80ac9e
2 changed files with 28 additions and 26 deletions

View File

@@ -96,8 +96,7 @@ Pros.
1. Works well with splits. Doesn't mess up with the current window arrangement 1. Works well with splits. Doesn't mess up with the current window arrangement
1. Works well with popular statusline plugins 1. Works well with popular statusline plugins
1. Prevents accessing the empty windows around the central buffer 1. Prevents accessing the empty windows around the central buffer
1. Can be closed with any of `:q[uit]`, `:clo[se]`, `:tabc[lose]`, `:bd[elete]`, 1. Can be closed with any of `:q[uit]`, `:clo[se]`, `:tabc[lose]`, or `:Goyo`
or `:Goyo`
1. Can dynamically change the width of the window 1. Can dynamically change the width of the window
1. Adjusts its colors when color scheme is changed 1. Adjusts its colors when color scheme is changed
1. Realigns the window when the terminal (or window) is resized or when the size 1. Realigns the window when the terminal (or window) is resized or when the size

View File

@@ -1,4 +1,4 @@
" Copyright (c) 2013 Junegunn Choi " Copyright (c) 2014 Junegunn Choi
" "
" MIT License " MIT License
" "
@@ -33,13 +33,12 @@ function! s:set_color(group, attr, color)
execute printf("hi %s %s%s=%s", a:group, gui ? 'gui' : 'cterm', a:attr, a:color) execute printf("hi %s %s%s=%s", a:group, gui ? 'gui' : 'cterm', a:attr, a:color)
endfunction endfunction
function! s:blank() function! s:blank(repel)
let main = bufwinnr(t:goyo_master) if bufwinnr(t:goyo_pads.r) <= bufwinnr(t:goyo_pads.l) + 1
if main != -1 \ || bufwinnr(t:goyo_pads.b) <= bufwinnr(t:goyo_pads.t) + 3
execute main . 'wincmd w'
else
call s:goyo_off() call s:goyo_off()
endif endif
execute 'wincmd' a:repel
endfunction endfunction
function! s:init_pad(command) function! s:init_pad(command)
@@ -59,12 +58,12 @@ function! s:init_pad(command)
return bufnr return bufnr
endfunction endfunction
function! s:setup_pad(bufnr, vert, size) function! s:setup_pad(bufnr, vert, size, repel)
let win = bufwinnr(a:bufnr) let win = bufwinnr(a:bufnr)
execute win . 'wincmd w' execute win . 'wincmd w'
execute (a:vert ? 'vertical ' : '') . 'resize ' . max([0, a:size]) execute (a:vert ? 'vertical ' : '') . 'resize ' . max([0, a:size])
augroup goyop augroup goyop
autocmd WinEnter,CursorMoved <buffer> nested call s:blank() execute 'autocmd WinEnter,CursorMoved <buffer> nested call s:blank("'.a:repel.'")'
autocmd WinLeave <buffer> call s:hide_statusline() autocmd WinLeave <buffer> call s:hide_statusline()
augroup END augroup END
@@ -93,10 +92,10 @@ function! s:resize_pads()
augroup goyop augroup goyop
autocmd! autocmd!
augroup END augroup END
call s:setup_pad(t:goyo_pads.t, 0, tmargin - 1) call s:setup_pad(t:goyo_pads.t, 0, tmargin - 1, 'j')
call s:setup_pad(t:goyo_pads.b, 0, bmargin - 2) call s:setup_pad(t:goyo_pads.b, 0, bmargin - 2, 'k')
call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1) call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1, 'l')
call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1) call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1, 'h')
endfunction endfunction
function! s:tranquilize() function! s:tranquilize()
@@ -119,6 +118,18 @@ function! s:hide_statusline()
let &l:statusline = repeat(' ', winwidth(0)) let &l:statusline = repeat(' ', winwidth(0))
endfunction endfunction
function! s:hide_linenr()
if !get(g:, 'goyo_linenr', 0)
setlocal nonu
if exists('&rnu')
setlocal nornu
endif
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
endfunction
function! s:goyo_on(width) function! s:goyo_on(width)
let s:orig_tab = tabpagenr() let s:orig_tab = tabpagenr()
@@ -177,16 +188,7 @@ function! s:goyo_on(width)
silent! call lightline#disable() silent! call lightline#disable()
endif endif
if !get(g:, 'goyo_linenr', 0) call s:hide_linenr()
setlocal nonu
if exists('&rnu')
setlocal nornu
endif
endif
if exists('&colorcolumn')
setlocal colorcolumn=
endif
" Global options " Global options
let &winheight = max([&winminheight, 1]) let &winheight = max([&winminheight, 1])
set winminheight=1 set winminheight=1
@@ -217,11 +219,11 @@ function! s:goyo_on(width)
augroup goyo augroup goyo
autocmd! autocmd!
autocmd BufWinLeave <buffer> call s:goyo_off()
autocmd TabLeave * call s:goyo_off() autocmd TabLeave * call s:goyo_off()
autocmd VimResized * call s:resize_pads() autocmd VimResized * call s:resize_pads()
autocmd ColorScheme * call s:tranquilize() autocmd ColorScheme * call s:tranquilize()
autocmd WinEnter,WinLeave <buffer> call s:hide_statusline() autocmd BufWinEnter * call s:hide_linenr() | call s:hide_statusline()
autocmd WinEnter,WinLeave * call s:hide_statusline()
augroup END augroup END
call s:hide_statusline() call s:hide_statusline()
@@ -268,6 +270,7 @@ function! s:goyo_off()
tabclose tabclose
execute 'normal! '.s:orig_tab.'gt' execute 'normal! '.s:orig_tab.'gt'
if winbufnr(0) == goyo_orig_buffer if winbufnr(0) == goyo_orig_buffer
" Doesn't work if window closed with `q`
execute printf('normal! %dG%d|', line, col) execute printf('normal! %dG%d|', line, col)
endif endif