diff --git a/plugin/vimroom.vim b/plugin/vimroom.vim index dbe0352..5cc60e7 100644 --- a/plugin/vimroom.vim +++ b/plugin/vimroom.vim @@ -35,9 +35,9 @@ if !exists( "g:vimroom_sidebar_height" ) let g:vimroom_sidebar_height = 3 endif -" The GUI background color. Defaults to "black" -if !exists( "g:vimroom_guibackground" ) - let g:vimroom_guibackground = "black" +" Override background color +if exists( "g:vimroom_guibackground_override" ) + let g:vimroom_guibackground = g:vimroom_guibackground_override endif " The cterm background color. Defaults to "bg" @@ -72,49 +72,80 @@ endif " Plugin Code " -" Given the desired column width, and minimum sidebar width, determine -" the minimum window width necessary for splitting to make sense -let s:minwidth = g:vimroom_width + ( g:vimroom_min_sidebar_width * 2 ) + " Given the desired column width, and minimum sidebar width, determine + " the minimum window width necessary for splitting to make sense + let s:minwidth = g:vimroom_width + ( g:vimroom_min_sidebar_width * 2 ) -" Save the current color scheme for reset later -let s:scheme = "" -if exists( "g:colors_name" ) - let s:scheme = g:colors_name -endif -if exists( "&t_mr" ) + if exists( "&t_mr" ) let s:save_t_mr = &t_mr -end + end -" Save the current scrolloff value for reset later -let s:save_scrolloff = "" -if exists( "&scrolloff" ) +function! Savestatus() + " Save the current color scheme for reset later + let s:scheme = "" + if exists( "g:colors_name" ) + let s:scheme = g:colors_name + endif + " Save the current scrolloff value for reset later + let s:save_scrolloff = "" + if exists( "&scrolloff" ) let s:save_scrolloff = &scrolloff -end + end -" Save the current `laststatus` value for reset later -let s:save_laststatus = "" -if exists( "&laststatus" ) + " Save the current `laststatus` value for reset later + let s:save_laststatus = "" + if exists( "&laststatus" ) let s:save_laststatus = &laststatus -endif + endif -" Save the current `textwidth` value for reset later -let s:save_textwidth = "" -if exists( "&textwidth" ) + " Save the current `textwidth` value for reset later + let s:save_textwidth = "" + if exists( "&textwidth" ) let s:save_textwidth = &textwidth -endif + endif -" Save the current `number` and `relativenumber` values for reset later -let s:save_number = 0 -let s:save_relativenumber = 0 -if exists( "&number" ) + " Save the current `wrap` value for reset later + let s:save_wrap = 0 + if exists( "&wrap" ) + let s:save_wrap = &wrap + endif + + " Save the current `linebreak` value for reset later + let s:save_linebreak = 0 + if exists( "&linebreak" ) + let s:save_linebreak = &linebreak + endif + + " Save the current `number` and `relativenumber` values for reset later + let s:save_number = 0 + let s:save_relativenumber = 0 + if exists( "&number" ) let s:save_number = &number -endif -if exists ( "&relativenumber" ) + endif + if exists ( "&relativenumber" ) let s:save_relativenumber = &relativenumber -endif + endif +endfu + +" Get the current background color +function! Getbgcolor() + redir => s:currentcolors + silent highlight Normal + redir END + if match(s:currentcolors, "guibg=\\zs\\S\\+") + return matchstr(s:currentcolors, "guibg=\\zs\\S\\+") + elseif match(s:currentcolors, "ctermbg=\\zs\\S\\+") + return matchstr(s:currentcolors, "ctermbg=\\zs\\S\\+") + else + return 'black' + endfu + +" Get the ID of the buffer we're working in +let s:mainbufnr = bufnr("%") " We're currently in nonvimroomized state let s:active = 0 +silent call Savestatus() function! s:is_the_screen_wide_enough() return winwidth( winnr() ) >= s:minwidth @@ -127,6 +158,9 @@ endfunction function! VimroomToggle() if s:active == 1 let s:active = 0 + " unset sidebar-click disabling + autocmd! WinEnter * + " Close all other split windows if g:vimroom_sidebar_height wincmd j @@ -147,7 +181,7 @@ function! VimroomToggle() hi clear endif if s:save_t_mr != "" - exec( "set t_mr=" .s:save_t_mr ) + exec( "set t_mr=" . s:save_t_mr ) endif " Reset `scrolloff` and `laststatus` if s:save_scrolloff != "" @@ -159,16 +193,20 @@ function! VimroomToggle() if s:save_textwidth != "" exec( "set textwidth=" . s:save_textwidth ) endif + if s:save_linebreak != 0 + set linebreak + endif + if s:save_wrap != 0 + set wrap + endif if s:save_number != 0 set number endif if s:save_relativenumber != 0 set relativenumber endif - " Remove wrapping and linebreaks - set nowrap - set nolinebreak else + call Savestatus() if s:is_the_screen_wide_enough() let s:active = 1 let s:sidebar = s:sidebar_size() @@ -178,14 +216,14 @@ function! VimroomToggle() endif if g:vimroom_min_sidebar_width " Create the left sidebar - exec( "silent leftabove " . s:sidebar . "vsplit new" ) + exec( "silent leftabove " . s:sidebar . "vnew" ) setlocal noma setlocal nocursorline setlocal nonumber setlocal norelativenumber wincmd l " Create the right sidebar - exec( "silent rightbelow " . s:sidebar . "vsplit new" ) + exec( "silent rightbelow " . s:sidebar . "vnew" ) setlocal noma setlocal nocursorline setlocal nonumber @@ -194,14 +232,14 @@ function! VimroomToggle() endif if g:vimroom_sidebar_height " Create the top sidebar - exec( "silent leftabove " . g:vimroom_sidebar_height . "split new" ) + exec( "silent leftabove " . g:vimroom_sidebar_height . "new" ) setlocal noma setlocal nocursorline setlocal nonumber setlocal norelativenumber wincmd j " Create the bottom sidebar - exec( "silent rightbelow " . g:vimroom_sidebar_height . "split new" ) + exec( "silent rightbelow " . g:vimroom_sidebar_height . "new" ) setlocal noma setlocal nocursorline setlocal nonumber @@ -221,6 +259,10 @@ function! VimroomToggle() if s:save_scrolloff != "" exec( "set scrolloff=".g:vimroom_scrolloff ) endif + + " clicking on any of the sidebar windows returns cursor to main window + let s:mainbufwin = bufwinnr(s:mainbufnr) + autocmd! WinEnter * exe s:mainbufwin . "wincmd w" " Setup navigation over "display lines", not "logical lines" if " mappings for the navigation keys don't already exist. @@ -237,6 +279,13 @@ function! VimroomToggle() endtry endif + " The GUI background color + if !exists( "g:vimroom_guibackground_override" ) + let g:vimroom_guibackground = Getbgcolor() + else + let g:vimroom_guibackground = g:vimroom_guibackground_override + endif + " Hide distracting visual elements if has('gui_running') let l:highlightbgcolor = "guibg=" . g:vimroom_guibackground @@ -266,3 +315,4 @@ command -nargs=0 VimroomToggle call VimroomToggle() if !hasmapto( 'VimroomToggle' ) nmap V VimroomToggle endif +