Merge branch '1.0.0rc1'

Conflicts:
	plugin/vimux.vim
fix-tmux-next-3dot4 1.0.0
benmills 11 years ago
commit 7c54b7af6a

@ -61,7 +61,10 @@ process finishes and will see the output in the pane when it's finished.
Furthermore there are several handy commands all starting with 'Vimux': Furthermore there are several handy commands all starting with 'Vimux':
- |VimuxRunCommand| - |VimuxRunCommand|
- |VimuxRunLastCommand| - |VimuxSendText|
- |VimuxSendKeys|
- |VimuxOpenPane|
- |VimuxRunLastCommand|
- |VimuxCloseRunner| - |VimuxCloseRunner|
- |VimuxClosePanes| - |VimuxClosePanes|
- |VimuxCloseWindows| - |VimuxCloseWindows|
@ -70,22 +73,7 @@ Furthermore there are several handy commands all starting with 'Vimux':
- |VimuxPromptCommand| - |VimuxPromptCommand|
- |VimuxClearRunnerHistory| - |VimuxClearRunnerHistory|
Note:
Earlier the all commands had different names. There are still aliases for
convenience. Please chang your configuration according to the new naming
conventions!
The DEPRECATED commands:
- |PromptVimTmuxCommand|
- |RunLastVimTmuxCommand|
- |InspectVimTmuxRunner|
- |CloseVimTmuxRunner|
- |CloseVimTmuxPanes|
- |InterruptVimTmuxRunner|
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*RunVimTmuxCommand*
*VimuxRunCommand* *VimuxRunCommand*
VimuxRunCommand~ VimuxRunCommand~
@ -100,7 +88,32 @@ vimux from automatically sending a return after the command.
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*PromptVimTmuxCommand* *VimuxSendText*
VimuxSendText~
Send raw text to the runer pane. This command will not open a new pane if one
does not already exist. You will need to use VimuxOpenPane to do this. This
command can be used to interact with REPLs or other interactive terminal
programs that are not shells.
------------------------------------------------------------------------------
*VimuxSendKeys*
VimuxSendKeys~
Send keys to the runner pane. This command will not open a new pane if one
does not already exist. You will need to use VimuxOpenPane to do this. You can
use this command to send keys such as "Enter" or "C-c" to the runner pane.
------------------------------------------------------------------------------
*VimuxOpenPane*
VimuxOpenPane~
This will either opne a new pane or use the nearest pane and set it as the
vimux runner pane for the other vimux commands. You can control if this command
uses the nearest pane or always creates a new one with g:VimuxUseNearestPane
------------------------------------------------------------------------------
*VimuxPromptCommand* *VimuxPromptCommand*
VimuxPromptCommand~ VimuxPromptCommand~
@ -112,7 +125,6 @@ pane.
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*RunLastVimTmuxCommand*
*VimuxRunLastCommand* *VimuxRunLastCommand*
VimuxRunLastCommand~ VimuxRunLastCommand~
@ -123,7 +135,6 @@ Run the last command executed by `VimuxRunCommand`
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*InspectVimTmuxRunner*
*VimuxInspectRunner* *VimuxInspectRunner*
VimuxInspectRunner~ VimuxInspectRunner~
@ -135,7 +146,6 @@ pmode (scroll mode).
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*CloseVimTmuxRunner*
*VimuxCloseRunner* *VimuxCloseRunner*
VimuxCloseRunner~ VimuxCloseRunner~
@ -146,18 +156,6 @@ Close the tmux runner created by `VimuxRunCommand`
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*CloseVimTmuxPanes*
*VimuxClosePanes*
VimuxClosePanes~
Close all other tmux panes in the current window.
>
" Close all other tmux panes in current window
map <Leader>vx :VimuxClosePanes<CR>
>
------------------------------------------------------------------------------
*InterruptVimTmuxRunner*
*VimuxInterruptRunner* *VimuxInterruptRunner*
VimuxInterruptRunner~ VimuxInterruptRunner~
@ -194,22 +192,19 @@ Full Keybind Example~
map <Leader>rb :call VimuxRunCommand("clear; rspec " . bufname("%"))<CR> map <Leader>rb :call VimuxRunCommand("clear; rspec " . bufname("%"))<CR>
" Prompt for a command to run " Prompt for a command to run
map <Leader>rp :VimuxPromptCommand<CR> map <Leader>vp :VimuxPromptCommand<CR>
" Run last command executed by VimuxRunCommand " Run last command executed by VimuxRunCommand
map <Leader>rl :VimuxRunLastCommand<CR> map <Leader>vl :VimuxRunLastCommand<CR>
" Inspect runner pane " Inspect runner pane
map <Leader>ri :VimuxInspectRunner<CR> map <Leader>vi :VimuxInspectRunner<CR>
" Close all other tmux panes in current window
map <Leader>rx :VimuxClosePanes<CR>
" Close vim tmux runner opened by VimuxRunCommand " Close vim tmux runner opened by VimuxRunCommand
map <Leader>rq :VimuxCloseRunner<CR> map <Leader>vq :VimuxCloseRunner<CR>
" Interrupt any command running in the runner pane " Interrupt any command running in the runner pane
map <Leader>rs :VimuxInterruptRunner<CR> map <Leader>vx :VimuxInterruptRunner<CR>
> >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@ -220,11 +215,13 @@ Here is how to use vimux to send code to a REPL. This is similar to tslime.
First, add some helpful mappings. First, add some helpful mappings.
> >
" Prompt for a command to run function! VimuxSlime()
map <LocalLeader>vp :VimuxPromptCommand<CR> call VimuxSendText(@v)
call VimuxSendKeys("Enter")
endfunction
" If text is selected, save it in the v buffer and send that buffer it to tmux " If text is selected, save it in the v buffer and send that buffer it to tmux
vmap <LocalLeader>vs "vy :call VimuxRunCommand(@v . "\n", 0)<CR> vmap <LocalLeader>vs "vy :call VimuxSlime()<CR>
" Select current paragraph and send it to tmux " Select current paragraph and send it to tmux
nmap <LocalLeader>vs vip<LocalLeader>vs<CR> nmap <LocalLeader>vs vip<LocalLeader>vs<CR>

@ -3,16 +3,8 @@ if exists("g:loaded_vimux") || &cp
endif endif
let g:loaded_vimux = 1 let g:loaded_vimux = 1
if !has("ruby")
finish
end
" New style commands with 'normalized' names
command VimuxRunLastCommand :call VimuxRunLastCommand() command VimuxRunLastCommand :call VimuxRunLastCommand()
command VimuxCloseRunner :call VimuxCloseRunner() command VimuxCloseRunner :call VimuxCloseRunner()
command VimuxClosePanes :call VimuxClosePanes()
command VimuxCloseWindows :call VimuxCloseWindows()
command VimuxInspectRunner :call VimuxInspectRunner() command VimuxInspectRunner :call VimuxInspectRunner()
command VimuxScrollUpInspect :call VimuxScrollUpInspect() command VimuxScrollUpInspect :call VimuxScrollUpInspect()
command VimuxScrollDownInspect :call VimuxScrollDownInspect() command VimuxScrollDownInspect :call VimuxScrollDownInspect()
@ -20,341 +12,136 @@ command VimuxInterruptRunner :call VimuxInterruptRunner()
command VimuxPromptCommand :call VimuxPromptCommand() command VimuxPromptCommand :call VimuxPromptCommand()
command VimuxClearRunnerHistory :call VimuxClearRunnerHistory() command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
" DEPRECATED function! VimuxRunLastCommand()
command RunLastVimTmuxCommand :call VimuxRunLastCommand() if exists("g:VimuxRunnerPaneIndex")
command CloseVimTmuxRunner :call VimuxCloseRunner() call VimuxRunCommand(g:VimuxLastCommand)
command CloseVimTmuxPanes :call VimuxClosePanes() else
command CloseVimTmuxWindows :call VimuxCloseWindows() echo "No last vimux command."
command InspectVimTmuxRunner :call VimuxInspectRunner() endif
command InterruptVimTmuxRunner :call VimuxInterruptRunner() endfunction
command PromptVimTmuxCommand :call VimuxPromptCommand()
function! VimuxRunCommand(command, ...)
if !exists("g:VimuxRunnerPaneIndex") || _VimuxHasPane(g:VimuxRunnerPaneIndex) == -1
call VimuxOpenPane()
endif
" new style functions
function VimuxRunCommand(command, ...)
let l:autoreturn = 1 let l:autoreturn = 1
if exists("a:1") if exists("a:1")
let l:autoreturn = a:1 let l:autoreturn = a:1
endif endif
let s:_VimTmuxCmd = substitute(a:command, '`', '\\`', 'g') let resetSequence = _VimuxOption("g:VimuxResetSequence", "q C-u")
let s:_VimTmuxCmdAutoreturn = l:autoreturn let g:VimuxLastCommand = a:command
call VimuxSendKeys(resetSequence)
call VimuxSendText(a:command)
if l:autoreturn == 1 if l:autoreturn == 1
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd")) call VimuxSendKeys("Enter")
else
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd"), false)
endif endif
endfunction endfunction
" deprecated! function! VimuxSendText(text)
function RunVimTmuxCommand(command, ...) call VimuxSendKeys('"'.escape(a:text, '"').'"')
" TODO replace me with the direct function call! endfunction
let l:autoreturn = 1
if exists("a:1")
let l:autoreturn = a:1
endif
let s:_VimTmuxCmd = substitute(a:command, '`', '\\`', 'g')
let s:_VimTmuxCmdAutoreturn = l:autoreturn
if l:autoreturn == 1 function! VimuxSendKeys(keys)
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd")) if exists("g:VimuxRunnerPaneIndex")
call system("tmux send-keys -t ".g:VimuxRunnerPaneIndex." ".a:keys)
else else
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd"), false) echo "No vimux runner pane. Create one with VimuxOpenPane"
endif endif
endfunction endfunction
function! VimuxOpenPane()
let height = _VimuxOption("g:VimuxHeight", 20)
let orientation = _VimuxOption("g:VimuxOrientation", "v")
let nearestIndex = _VimuxNearestPaneIndex()
function VimuxRunLastCommand() if _VimuxOption("g:VimuxUseNearestPane", 1) == 1 && nearestIndex != -1
if exists("s:_VimTmuxCmd") let g:VimuxRunnerPaneIndex = nearestIndex
if s:_VimTmuxCmdAutoreturn == 1
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd"))
else
ruby CurrentTmuxSession.new.run_shell_command(Vim.evaluate("s:_VimTmuxCmd"), false)
endif
else else
echo "No last command" call system("tmux split-window -p ".height." -".orientation)
let g:VimuxRunnerPaneIndex = _VimuxTmuxPaneIndex()
call system("tmux last-pane")
endif endif
endfunction endfunction
" deprecated! function! VimuxCloseRunner()
function RunLastVimTmuxCommand() if exists("g:VimuxRunnerPaneIndex")
call VimuxRunLastCommand() call system("tmux kill-pane -t ".g:VimuxRunnerPaneIndex)
endfunction unlet g:VimuxRunnerPaneIndex
endif
function VimuxClearWindow()
if exists("s:_VimTmuxRunnerPane")
unlet s:_VimTmuxRunnerPane
end
endfunction endfunction
" deprecated! function! VimuxInspectRunner()
function ClearVimTmuxWindow() call system("tmux select-pane -t ".g:VimuxRunnerPaneIndex)
call VimuxClearWindow() call system("tmux copy-mode")
endfunction endfunction
function! VimuxScrollUpInspect()
" deprecated! call VimuxInspectRunner()
function CloseVimTmuxWindows() call system("tmux last-pane")
call VimuxCloseWindows() call VimuxSendKeys("C-u")
endfunction endfunction
function! VimuxScrollDownInspect()
function VimuxCloseRunner() call VimuxInspectRunner()
ruby CurrentTmuxSession.new.close_runner_pane call system("tmux last-pane")
call VimuxClearWindow() call VimuxSendKeys("C-d")
endfunction endfunction
" deprecated! function! VimuxInterruptRunner()
function CloseVimTmuxRunner() call VimuxSendKeys("^c")
call VimuxCloseRunner()
endfunction endfunction
function! VimuxClearRunnerHistory()
function VimuxClosePanes() if exists("g:VimuxRunnerPaneIndex")
ruby CurrentTmuxSession.new.close_other_panes call system("tmux clear-history -t ".g:VimuxRunnerPaneIndex)
call VimuxClearWindow() endif
endfunction endfunction
" deprecated! function! VimuxPromptCommand()
function CloseVimTmuxPanes() let l:command = input(_VimuxOption("g:VimuxPromptString", "Command? "))
call VimuxClosePanes() call VimuxRunCommand(l:command)
endfunction endfunction
function! _VimuxTmuxSession()
function VimuxInterruptRunner() return _VimuxTmuxProperty("S")
ruby CurrentTmuxSession.new.interrupt_runner
endfunction endfunction
" deprecated! function! _VimuxTmuxPaneIndex()
function InterruptVimTmuxRunner() return _VimuxTmuxProperty("P")
call VimuxInterruptRunner()
endfunction endfunction
function VimuxScrollDownInspect() function! _VimuxTmuxWindowIndex()
ruby CurrentTmuxSession.new.inspect_scroll_down return _VimuxTmuxProperty("I")
endfunction endfunction
function VimuxScrollUpInspect() function! _VimuxNearestPaneIndex()
ruby CurrentTmuxSession.new.inspect_scroll_up let panes = split(system("tmux list-panes"), "\n")
endfunction
function VimuxInspectRunner() for i in panes
ruby CurrentTmuxSession.new.inspect_runner if match(panes[i], "(active)") == -1
endfunction return split(panes[i], ":")[0]
endif
endfor
" deprecated! return -1
function InspectVimTmuxRunner()
call VimuxInspectRunner()
endfunction endfunction
function! _VimuxOption(option, default)
function VimuxPromptCommand() if exists(a:option)
let l:command = input("Command? ") return eval(a:option)
if exists("g:VimuxPromptString") else
let l:command = input(g:VimuxPromptString) return a:default
endif endif
call VimuxRunCommand(l:command)
endfunction endfunction
" deprecated! function! _VimuxTmuxProperty(property)
function PromptVimTmuxCommand() return substitute(system("tmux display -p '#".a:property."'"), '\n$', '', '')
call VimuxPromptCommand()
endfunction endfunction
function! _VimuxHasPane(index)
function VimuxClearRunnerHistory() return match(system("tmux list-panes"), a:index.":")
ruby CurrentTmuxSession.new.clear_runner_history
endfunction endfunction
ruby << EOF
class TmuxSession
def initialize(session, window, pane)
@session = session
@window = window
@pane = pane
@runner_pane = vim_cached_runner_pane
end
def vim_cached_runner_pane
if Vim.evaluate('exists("s:_VimTmuxRunnerPane")') != 0
Vim.evaluate('s:_VimTmuxRunnerPane')
else
nil
end
end
def vim_cached_runner_pane=(runner_pane)
Vim.command("let s:_VimTmuxRunnerPane = '#{runner_pane}'")
end
def clear_vim_cached_runner_pane
Vim.command("unlet s:_VimTmuxRunnerPane")
end
def clear_runner_history
_run("clear-history -t #{target(:pane => runner_pane)}")
end
def height
if Vim.evaluate('exists("g:VimuxHeight")') != 0
Vim.evaluate('g:VimuxHeight')
else
20
end
end
def orientation
if Vim.evaluate('exists("g:VimuxOrientation")') != 0 && ["h", "v"].include?(Vim.evaluate('g:VimuxOrientation'))
"-#{Vim.evaluate('g:VimuxOrientation')}"
else
"-v"
end
end
def reset_sequence
if Vim.evaluate('exists("g:VimuxResetSequence")') != 0
"#{Vim.evaluate('g:VimuxResetSequence')}"
else
"q C-u"
end
end
def inspect_runner
_run("select-pane -t #{target(:pane => runner_pane)}")
_run("copy-mode")
end
def inspect_send_command(cmd)
t = target(:pane => runner_pane)
_run("select-pane -t #{t}")
_run("copy-mode")
_send_command(cmd, t, false)
_move_up_pane
end
def inspect_scroll_up
inspect_send_command("C-u")
end
def inspect_scroll_down
inspect_send_command("C-d")
end
def current_panes
_run('list-panes').split("\n").map do |line|
line.split(':').first
end
end
def active_pane_id
_run('list-panes').split("\n").map do |line|
return line.split[-2] if line =~ /\(active\)/
end
end
def target(args={})
"'#{args.fetch(:session, @session)}':'#{args.fetch(:window, @window)}'.#{args.fetch(:pane, @pane)}"
end
def runner_pane
if @runner_pane.nil?
use_nearest_pane = Vim.evaluate('exists("g:VimuxUseNearestPane")') != 0
if use_nearest_pane && nearest_inactive_pane_id
_run("select-pane -t #{target(:pane => nearest_inactive_pane_id)}")
else
_run("split-window -p #{height} #{orientation}")
end
@runner_pane = active_pane_id
_send_command("cd #{`pwd`}", target(:pane => runner_pane))
Vim.command("let s:_VimTmuxRunnerPane = '#{@runner_pane}'")
end
_run('list-panes').split("\n").map do |line|
return line.split(':').first if line =~ /#{@runner_pane}/
end
@runner_pane = nil
runner_pane
end
def interrupt_runner
_run("send-keys -t #{target(:pane => runner_pane)} ^c")
end
def run_shell_command(command, auto_return = true)
reset_shell
_send_command(command, target(:pane => runner_pane), auto_return)
_move_up_pane
end
def close_runner_pane
_run("kill-pane -t #{target(:pane => runner_pane)}") unless @runner_pane.nil?
end
def close_other_panes
if _run("list-panes").split("\n").length > 1
_run("kill-pane -a")
end
end
def reset_shell
_run("send-keys -t #{target(:pane => runner_pane)} #{reset_sequence}")
end
def nearest_inactive_pane_id
panes = _run("list-pane").split("\n")
pane = panes.find { |p| p !~ /active/ }
pane ? pane.split(':').first : nil
end
def _move_up_pane
_run("select-pane -t #{target}")
end
def _send_command(command, target, auto_return = true)
_run("send-keys -t #{target} \"#{_escape_command(command)}\"")
_run("send-keys -t #{target} Enter") if auto_return
end
def _escape_command(command)
command.gsub('"', '\"').gsub('$', '\$').sub(/;\z/, '\;')
end
def _run(command)
`tmux #{command}`
end
end
class CurrentTmuxSession < TmuxSession
def initialize
if tmux?
session = self.get_session
window = self.get_property(:active, :window)
pane = self.get_property(:active, :pane)
super(session, window, pane)
else
raise "You are not in a tmux session"
end
end
def get_property(match, type)
_run("list-#{type.to_s}").split("\n").each do |line|
return line.split(':').first if line =~ /\(#{match.to_s}\)/
end
end
def get_session
_run("display -p '#S'").strip
end
def tmux?
`echo $TMUX` =~ /.+/ ? true : false
end
end
EOF

Loading…
Cancel
Save