christoomey / vim-tmux-runner

Vim and tmux, sittin' in a tree...
MIT License
291 stars 37 forks source link

Error: Reorient Runner fails when run after manual attach #32

Closed christoomey closed 9 years ago

christoomey commented 9 years ago

Two related issues here, both occuring when running :VtrReorientRunner after manually attaching via :VtrAttachToPane:

  1. The s:vim_pane variable is not set, causing the FocusVimPane function to throw an error.
  2. The orientation is assumed to be vertical, causing it to mess up if you use with a horizontal | split.

Currently, if you attach to an existing pane, the orientation is not set. This can theoretically be improved as the layout can be determined with:

$ tmux display-message -p "#{window_layout}"                                                                                                      
7d94,318x74,0,0[318x37,0,0,78,318x36,0,38{159x36,0,38,83,158x36,160,38,84}]

Where [s represent - splits, and {s represent | splits.

Unfortunately I don't think it is possible to handle all conditions as the window size and layouts are mutable and tmux-runner has no way of confirming if things have changed.


thinking more, I can simplify the problem by assuming that the Vim & runner will exist in the outermost split. An oversimplification, but likely true in the majority of cases. With that, I can determine the orientation by parsing the outermost / first orientation delimeter in the layout string:

function! CurrentMajorOrientation()
  let orientation_map = { '[': 'v', '{': 'h' }
  let layout = system("tmux display-message -p '#{window_layout}'")
  let outermost_orientation = substitute(layout, '[^[{]', '', 'g')[0]
  return orientation_map[outermost_orientation]
endfunction