Permalink
Browse files

Add an optional argument to RunVimTmuxCommand to stop sending a retur…

…n after the command. Fixes #9
  • Loading branch information...
benmills committed Apr 20, 2012
1 parent 06ba414 commit c853343e6fdc066c2be655b5cdf6fc2e51ed4bd9
Showing with 23 additions and 9 deletions.
  1. +6 −3 README.mkd
  2. +17 −6 plugin/vimux.vim
View
@@ -22,11 +22,14 @@ Otherwise download the latest [tarball](https://github.com/benmills/vimux/tarbal
## Usage
### RunVimTmuxCommand
-Run a system command in a small horizontal split bellow the current pane vim is in.
+Run a system command in a small horizontal split bellow the current pane vim is in. You can optionally pass a second argument to stop vimux from automatically sending a return after the command.
```viml
" Run the current file with rspec
map <Leader>rb :call RunVimTmuxCommand("clear; rspec " . bufname("%"))<CR>
+
+" Run command without sending sending a return
+map <Leader>rq :call RunVimTmuxCommand("clear; rspec " . bufname("%"), 0)<CR>
```
### PromptVimTmuxCommand
@@ -101,13 +104,13 @@ Here is how to use vimux to send code to a REPL. This is similar to tslime. Firs
map <LocalLeader>vp :PromptVimTmuxCommand<CR>
" If text is selected, save it in the v buffer and send that buffer it to tmux
-vmap <LocalLeader>vs "vy :call RunVimTmuxCommand(@v)<CR>
+vmap <LocalLeader>vs "vy :call RunVimTmuxCommand(@v . "\n", 0)<CR>
" Select current paragraph and send it to tmux
nmap <LocalLeader>vs vip<LocalLeader>vs<CR>
```
-Now, open a clojure file. Let's say your leader is backslash (\). Type \vp, and then type lein repl at the prompt. This opens a tmux split running a REPL. Then, select text or put the cursor on a function and type \vs. This will send it to the REPL and evaluate it.
+Now, open a clojure file. Let's say your leader is backslash (\). Type \vp, and then type lein repl at the prompt. This opens a tmux split running a REPL. Then, select text or put the cursor on a function and type \vs. This will send it to the REPL and evaluate it. The reason we pass `0` to `RunVimTmuxCommand` is to stop the normal return that is sent to the runner pane and use our own new line so the clojure REPL will evaluate the selected text without adding an extra return. Thanks to @trptcolin for discovering this issue.
## Options
View
@@ -14,9 +14,20 @@ command InspectVimTmuxRunner :call InspectVimTmuxRunner()
command InterruptVimTmuxRunner :call InterruptVimTmuxRunner()
command PromptVimTmuxCommand :call PromptVimTmuxCommand()
-function RunVimTmuxCommand(command)
+function RunVimTmuxCommand(command, ...)
+ let l:autoreturn = 1
+
+ if exists("a:1")
+ let l:autoreturn = a:1
+ endif
+
let g:_VimTmuxCmd = a:command
- ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"))
+
+ if l:autoreturn == 1
+ ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"))
+ else
+ ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("g:_VimTmuxCmd"), false)
+ endif
endfunction
function RunLastVimTmuxCommand()
@@ -152,9 +163,9 @@ class TmuxSession
_run("send-keys -t #{target(:pane => runner_pane)} ^c")
end
- def run_shell_command(command)
+ def run_shell_command(command, auto_return = true)
reset_shell
- _send_command(command, target(:pane => runner_pane))
+ _send_command(command, target(:pane => runner_pane), auto_return)
_move_up_pane
end
@@ -178,9 +189,9 @@ class TmuxSession
_run("select-pane -t #{target}")
end
- def _send_command(command, target)
+ def _send_command(command, target, auto_return = true)
_run("send-keys -t #{target} \"#{command.gsub('"', '\"')}\"")
- _run("send-keys -t #{target} Enter")
+ _run("send-keys -t #{target} Enter") if auto_return
end
def _run(command)

0 comments on commit c853343

Please sign in to comment.