about summary refs log tree commit diff stats
path: root/vimrc.vim
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-09-07 16:39:03 -0700
committerKartik Agaram <vc@akkartik.com>2019-09-07 16:39:03 -0700
commit2844327aa793ab57650410f59d334b90aad2103b (patch)
tree1fb46afdbbc3938d4e6f817d383fc32ccc21a051 /vimrc.vim
parent8d5968b0dd23eba3f048ac601b2f4cae250a50ac (diff)
downloadmu-2844327aa793ab57650410f59d334b90aad2103b.tar.gz
5639 - tmux support for running a single test
Keep the top/left most pane for a shell, and try hitting `<Leader>t` from
within a test.

If you hit `<Leader>t` from within code, it will try to remember what test
you ran last and rerun that.
Diffstat (limited to 'vimrc.vim')
-rw-r--r--vimrc.vim53
1 files changed, 35 insertions, 18 deletions
diff --git a/vimrc.vim b/vimrc.vim
index b84df46f..445abbd3 100644
--- a/vimrc.vim
+++ b/vimrc.vim
@@ -77,24 +77,41 @@ command! -nargs=0 L exec "%!grep -a label |grep -v clear-stream:loop"
 " run test cursor around cursor
 " Unfortunately this only works with Linux at the moment.
 " Some compiler passes take too long to run in emulated mode.
-" this solution is unfortunate, but seems forced:
-"   can't put initial cursor movement inside function because we rely on <C-r><C-w> to grab word at cursor
-"   can't put final cursor movement out of function because that disables the wait for <CR> prompt; function must be final operation of map
-"   can't avoid the function because that disables the wait for <CR> prompt
-" known issue:
-"   cursor on '#' causes error
-noremap <Leader>t {j0:call RunTestMoveCursor("<C-r><C-w>")<CR>
-function RunTestMoveCursor(arg)
-  exec "!./run_one_test ".expand("%")." ".a:arg
-  exec "normal \<C-o>"
-endfunction
-function RunTestMoveCursorAndMaybeOpenTrace(arg)
-  exec "!./run_one_test ".expand("%")." ".a:arg
-  exec "normal \<C-o>"
-  if v:shell_error
-    noautocmd vertical split last_run
-  endif
-endfunction
+if empty($TMUX)
+  " hack: need to move cursor at outside function at start (`{j0`), but inside function at end (`<C-o>`)
+  " this solution is unfortunate, but seems forced:
+  "   can't put initial cursor movement inside function because we rely on <C-r><C-w> to grab word at cursor
+  "   can't put final cursor movement out of function because that disables the wait for <CR> prompt; function must be final operation of map
+  "   can't avoid the function because that disables the wait for <CR> prompt
+  " known issue:
+  "   cursor on '#' causes error
+  noremap <Leader>t {j0:call RunTestMoveCursor("<C-r><C-w>")<CR>
+  function RunTestMoveCursor(arg)
+    exec "!./run_one_test ".expand("%")." ".a:arg
+    exec "normal \<C-o>"
+  endfunction
+  function RunTestMoveCursorAndMaybeOpenTrace(arg)
+    exec "!./run_one_test ".expand("%")." ".a:arg
+    exec "normal \<C-o>"
+    if v:shell_error
+      noautocmd vertical split last_run
+    endif
+  endfunction
+else
+  " we have tmux; we don't need to show any output in the Vim pane so life is simpler
+  " assume the left-most window is for the shell
+  noremap <Leader>t {j0:silent! call RunTestInFirstPane("<C-r><C-w>")<CR><C-o>
+  function RunTestInFirstPane(arg)
+    call RunInFirstPane("./run_one_test ".expand("%")." ".a:arg)
+  endfunction
+  function RunInFirstPane(arg)
+    exec "!tmux select-pane -t :0.0"
+    exec "!tmux send-keys '".a:arg."' C-m"
+    exec "!tmux last-pane"
+    " for some reason my screen gets messed up, so force a redraw
+    exec "!tmux send-keys 'C-l'"
+  endfunction
+endif
 
 set switchbuf=useopen
 if exists("&splitvertical")