Add detach and reattach commands
This commit is contained in:
		
							parent
							
								
									1237988753
								
							
						
					
					
						commit
						ddb36560a0
					
				| @ -1,3 +1,7 @@ | |||||||
|  | " TODO: guards on methods that expect pane, window to exist | ||||||
|  | " TODO: full command and option docs | ||||||
|  | " TODO: maximize command | ||||||
|  | 
 | ||||||
| function! s:InitVariable(var, value) | function! s:InitVariable(var, value) | ||||||
|     if !exists(a:var) |     if !exists(a:var) | ||||||
|         let escaped_value = substitute(a:value, "'", "''", "g") |         let escaped_value = substitute(a:value, "'", "''", "g") | ||||||
| @ -17,6 +21,8 @@ function! s:InitializeVariables() | |||||||
|     call s:InitVariable("g:VtrUseVtrMaps", 1) |     call s:InitVariable("g:VtrUseVtrMaps", 1) | ||||||
|     call s:InitVariable("g:VtrClearOnResize", 1) |     call s:InitVariable("g:VtrClearOnResize", 1) | ||||||
|     call s:InitVariable("g:VtrClearOnReorient", 1) |     call s:InitVariable("g:VtrClearOnReorient", 1) | ||||||
|  |     call s:InitVariable("g:VtrClearOnReattach", 1) | ||||||
|  |     call s:InitVariable("g:VtrDetachedName", "VTR_Pane") | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:OpenRunnerPane() | function! s:OpenRunnerPane() | ||||||
| @ -34,6 +40,12 @@ function! s:OpenRunnerPane() | |||||||
|     endif |     endif | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
|  | function! s:DetachRunnerPane() | ||||||
|  |     call s:BreakRunnerPaneToTempWindow() | ||||||
|  |     let cmd = join(["rename-window -t", s:detached_window, g:VtrDetachedName]) | ||||||
|  |     call s:SendTmuxCommand(cmd) | ||||||
|  | endfunction | ||||||
|  | 
 | ||||||
| function! s:KillRunnerPane() | function! s:KillRunnerPane() | ||||||
|     let targeted_cmd = s:TargetedTmuxCommand("kill-pane", s:runner_pane) |     let targeted_cmd = s:TargetedTmuxCommand("kill-pane", s:runner_pane) | ||||||
|     call s:SendTmuxCommand(targeted_cmd) |     call s:SendTmuxCommand(targeted_cmd) | ||||||
| @ -138,7 +150,7 @@ function! s:FocusVimPane() | |||||||
|     call s:FocusTmuxPane(s:vim_pane) |     call s:FocusTmuxPane(s:vim_pane) | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:TempWindowNumber() | function! s:LastWindowNumber() | ||||||
|     return split(s:SendTmuxCommand("list-windows"), '\n')[-1][0] |     return split(s:SendTmuxCommand("list-windows"), '\n')[-1][0] | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| @ -146,23 +158,36 @@ function! s:BreakRunnerPaneToTempWindow() | |||||||
|     let targeted_cmd = s:TargetedTmuxCommand("break-pane", s:runner_pane) |     let targeted_cmd = s:TargetedTmuxCommand("break-pane", s:runner_pane) | ||||||
|     let full_command = join([targeted_cmd, "-d"]) |     let full_command = join([targeted_cmd, "-d"]) | ||||||
|     call s:SendTmuxCommand(full_command) |     call s:SendTmuxCommand(full_command) | ||||||
|     return s:TempWindowNumber() |     let s:detached_window = s:LastWindowNumber() | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:ToggleOrientationVariable() | function! s:ToggleOrientationVariable() | ||||||
|     let g:VtrOrientation = (g:VtrOrientation == "v" ? "h" : "v") |     let g:VtrOrientation = (g:VtrOrientation == "v" ? "h" : "v") | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
|  | function! s:_ReattachPane() | ||||||
|  |     let join_cmd = join(["join-pane", "-s", ":".s:detached_window.".0", | ||||||
|  |         \ "-p", g:VtrPercentage, "-".g:VtrOrientation]) | ||||||
|  |     call s:SendTmuxCommand(join_cmd) | ||||||
|  |     unlet s:detached_window | ||||||
|  | endfunction | ||||||
|  | 
 | ||||||
|  | function! s:ReattachPane() | ||||||
|  |     call s:_ReattachPane() | ||||||
|  |     call s:FocusVimPane() | ||||||
|  |     if g:VtrClearOnReattach | ||||||
|  |         call s:SendClearSequence() | ||||||
|  |     endif | ||||||
|  | endfunction | ||||||
|  | 
 | ||||||
| function! s:ReorientRunner() | function! s:ReorientRunner() | ||||||
|     let temp_window = s:BreakRunnerPaneToTempWindow() |     let temp_window = s:BreakRunnerPaneToTempWindow() | ||||||
|     call s:ToggleOrientationVariable() |     call s:ToggleOrientationVariable() | ||||||
|     let join_cmd = join(["join-pane", "-s", ":".temp_window.".0", |     call s:_ReattachPane() | ||||||
|         \ "-p", g:VtrPercentage, "-".g:VtrOrientation]) |     call s:FocusVimPane() | ||||||
|     call s:SendTmuxCommand(join_cmd) |  | ||||||
|     if g:VtrClearOnReorient |     if g:VtrClearOnReorient | ||||||
|         call s:SendClearSequence() |         call s:SendClearSequence() | ||||||
|     endif |     endif | ||||||
|     call s:FocusVimPane() |  | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:HighlightedPrompt(prompt) | function! s:HighlightedPrompt(prompt) | ||||||
| @ -185,6 +210,9 @@ function! s:DefineCommands() | |||||||
|     command! VTRSendCommandToRunner :call s:SendCommandToRunner() |     command! VTRSendCommandToRunner :call s:SendCommandToRunner() | ||||||
|     command! VTRReorientRunner :call s:ReorientRunner() |     command! VTRReorientRunner :call s:ReorientRunner() | ||||||
|     command! VTRResizePane :call s:ResizeRunnerPane() |     command! VTRResizePane :call s:ResizeRunnerPane() | ||||||
|  |     command! VTRDetachPane :call s:DetachRunnerPane() | ||||||
|  |     command! VTRReattachPane :call s:ReattachPane() | ||||||
|  |     command! VTRClearRunner :call s:SendClearSequence() | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:DefineKeymaps() | function! s:DefineKeymaps() | ||||||
| @ -195,9 +223,14 @@ function! s:DefineKeymaps() | |||||||
|         nmap ,or :VTROpenRunner<cr> |         nmap ,or :VTROpenRunner<cr> | ||||||
|         nmap ,kr :VTRKillRunner<cr> |         nmap ,kr :VTRKillRunner<cr> | ||||||
|         nmap ,fr :VTRFocusRunnerPane<cr> |         nmap ,fr :VTRFocusRunnerPane<cr> | ||||||
|  |         nmap ,dr :VTRDetachPane<cr> | ||||||
|  |         nmap ,ar :VTRReattachPane<cr> | ||||||
|  |         nmap ,cr :VTRClearRunner<cr> | ||||||
|     endif |     endif | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| call s:InitializeVariables() | call s:InitializeVariables() | ||||||
| call s:DefineCommands() | call s:DefineCommands() | ||||||
| call s:DefineKeymaps() | call s:DefineKeymaps() | ||||||
|  | 
 | ||||||
|  | " vim: set fdm=marker | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user