diff --git a/plugin/tidal.vim b/plugin/tidal.vim index 791615d..2337927 100644 --- a/plugin/tidal.vim +++ b/plugin/tidal.vim @@ -98,6 +98,10 @@ if !exists("g:tidal_sc_boot_cmd") let g:tidal_sc_boot_cmd = g:tidal_sclang . " " . g:tidal_sc_boot endif +if !exists('g:tidal_split_direction') + let g:tidal_split_direction = 'below' " below, left, right +endif + if filereadable(s:parent_path . "/.dirt-samples") let &l:dictionary .= ',' . s:parent_path . "/.dirt-samples" endif @@ -135,11 +139,9 @@ function! s:TmuxConfig() abort endif endfunction - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Terminal """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - let s:tidal_term_ghci = -1 let s:tidal_term_sc = -1 @@ -147,49 +149,87 @@ let s:tidal_term_sc = -1 " ===================================== function! s:TerminalOpen() if has('nvim') - let current_win = winnr() - + let current_buf = bufnr('%') + let current_width = winwidth(0) + if s:tidal_term_ghci == -1 - " force terminal split to open below current pane - :exe "set splitbelow" - execute "split term://" . g:tidal_ghci . " -ghci-script=" . g:tidal_boot + if g:tidal_split_direction == 'below' + :exe "set splitbelow" + execute "split term://" . g:tidal_ghci . " -ghci-script=" . g:tidal_boot + elseif g:tidal_split_direction == 'right' + :exe "set splitright" + execute "vsplit term://" . g:tidal_ghci . " -ghci-script=" . g:tidal_boot + " Set terminal width to 1/3, leaving main window at 2/3 + execute "vertical resize " . (current_width / 3) + elseif g:tidal_split_direction == 'left' + execute "leftabove vsplit term://" . g:tidal_ghci . " -ghci-script=" . g:tidal_boot + " Set terminal width to 1/3, leaving main window at 2/3 + execute "vertical resize " . (current_width / 3) + endif + let s:tidal_term_ghci = b:terminal_job_id - - " Give tidal a moment to start up so following commands can take effect sleep 500m - - " Make terminal scroll to follow output :exe "normal G" - :exe "normal 10\_" + + if g:tidal_split_direction == 'below' + :exe "normal 10\_" + endif endif - + if g:tidal_sc_enable == 1 && s:tidal_term_sc == -1 - execute "vsplit term://" . g:tidal_sc_boot_cmd + if g:tidal_split_direction == 'below' + execute "vsplit term://" . g:tidal_sc_boot_cmd + else + execute "split term://" . g:tidal_sc_boot_cmd + endif let s:tidal_term_sc = b:terminal_job_id - - " Make terminal scroll to follow output :exe "normal G" endif - - execute current_win .. "wincmd w" + + " Find and switch to the window containing our original buffer + let target_win = bufwinnr(current_buf) + if target_win != -1 + execute target_win .. "wincmd w" + endif + elseif has('terminal') - " Keep track of the current window number so we can switch back. - let current_win = winnr() - - " Open a Terminal with GHCI with tidal booted. + let current_buf = bufnr('%') + let current_width = winwidth(0) + if s:tidal_term_ghci == -1 - execute "below split" - let s:tidal_term_ghci = term_start((g:tidal_ghci . " -ghci-script=" . g:tidal_boot), #{ - \ term_name: 'tidal', - \ term_rows: 10, - \ norestore: 1, - \ curwin: 1, - \ }) + if g:tidal_split_direction == 'below' + execute "below split" + let s:tidal_term_ghci = term_start((g:tidal_ghci . " -ghci-script=" . g:tidal_boot), #{ + \ term_name: 'tidal', + \ term_rows: 10, + \ norestore: 1, + \ curwin: 1, + \ }) + elseif g:tidal_split_direction == 'right' + execute "vert rightbelow split" + let s:tidal_term_ghci = term_start((g:tidal_ghci . " -ghci-script=" . g:tidal_boot), #{ + \ term_name: 'tidal', + \ term_cols: current_width / 3, + \ norestore: 1, + \ curwin: 1, + \ }) + elseif g:tidal_split_direction == 'left' + execute "vert leftabove split" + let s:tidal_term_ghci = term_start((g:tidal_ghci . " -ghci-script=" . g:tidal_boot), #{ + \ term_name: 'tidal', + \ term_cols: current_width / 3, + \ norestore: 1, + \ curwin: 1, + \ }) + endif endif - - " Open a terminal with supercollider running. + if g:tidal_sc_enable == 1 && s:tidal_term_sc == -1 - execute "vert split" + if g:tidal_split_direction == 'below' + execute "vert split" + else + execute "below split" + endif let s:tidal_term_sc = term_start(g:tidal_sc_boot_cmd, #{ \ term_name: 'supercollider', \ term_rows: 10, @@ -197,9 +237,12 @@ function! s:TerminalOpen() \ curwin: 1, \ }) endif - - " Return focus to the original window. - execute current_win .. "wincmd w" + + " Find and switch to the window containing our original buffer + let target_win = bufwinnr(current_buf) + if target_win != -1 + execute target_win .. "wincmd w" + endif endif endfunction @@ -215,6 +258,7 @@ endfunction " These two are unnecessary AFAIK. function! s:TerminalPaneNames(A,L,P) endfunction + function! s:TerminalConfig() abort endfunction