From c853343e6fdc066c2be655b5cdf6fc2e51ed4bd9 Mon Sep 17 00:00:00 2001 From: benmills Date: Fri, 20 Apr 2012 17:47:54 -0500 Subject: [PATCH] Add an optional argument to RunVimTmuxCommand to stop sending a return after the command. Fixes #9 --- README.mkd | 9 ++++++--- plugin/vimux.vim | 23 +++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.mkd b/README.mkd index ccc7ea9..ebdc255 100644 --- a/README.mkd +++ b/README.mkd @@ -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 rb :call RunVimTmuxCommand("clear; rspec " . bufname("%")) + +" Run command without sending sending a return +map rq :call RunVimTmuxCommand("clear; rspec " . bufname("%"), 0) ``` ### PromptVimTmuxCommand @@ -101,13 +104,13 @@ Here is how to use vimux to send code to a REPL. This is similar to tslime. Firs map vp :PromptVimTmuxCommand " If text is selected, save it in the v buffer and send that buffer it to tmux -vmap vs "vy :call RunVimTmuxCommand(@v) +vmap vs "vy :call RunVimTmuxCommand(@v . "\n", 0) " Select current paragraph and send it to tmux nmap vs vipvs ``` -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 diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 72dc0bd..b30b46f 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -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)