Strip whitespace when sending lines
Closes #12 - Trim leading whitespace before sending
This commit is contained in:
parent
0470d5cb3f
commit
626531af5d
@ -309,23 +309,25 @@ function! s:GetVisualSelection()
|
|||||||
let lines = getline(lnum1, lnum2)
|
let lines = getline(lnum1, lnum2)
|
||||||
let lines[-1] = lines[-1][: col2 - 2]
|
let lines[-1] = lines[-1][: col2 - 2]
|
||||||
let lines[0] = lines[0][col1 - 1:]
|
let lines[0] = lines[0][col1 - 1:]
|
||||||
return join(lines, "\n")
|
return lines
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SendLineToRunner()
|
function! s:SendLineToRunner()
|
||||||
let line = getline('.')
|
let line = [getline('.')]
|
||||||
call s:SendTextToRunner(line)
|
call s:SendTextToRunner(line)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SendSelectedToRunner()
|
function! s:SendSelectedToRunner()
|
||||||
let selected_text = s:GetVisualSelection()
|
let lines = s:GetVisualSelection()
|
||||||
call s:SendTextToRunner(selected_text)
|
call s:SendTextToRunner(lines)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SendTextToRunner(text)
|
function! s:SendTextToRunner(lines)
|
||||||
let escaped_text = substitute(a:text, "'", "'\\\\''", 'g')
|
let whitespace_stripped = map(a:lines, 'substitute(v:val,"^\\s*","","")')
|
||||||
call s:SendTmuxCommand(join(["set-buffer", "'" . escaped_text . "'"]))
|
let without_empty_lines = filter(whitespace_stripped, "!empty(v:val)")
|
||||||
let targeted_cmd = s:TargetedTmuxCommand("paste-buffer", s:runner_pane)
|
let joined_lines = join(without_empty_lines, "\r")
|
||||||
|
let send_keys_cmd = s:TargetedTmuxCommand("send-keys", s:runner_pane)
|
||||||
|
let targeted_cmd = send_keys_cmd . ' ' . shellescape(joined_lines)
|
||||||
call s:SendTmuxCommand(targeted_cmd)
|
call s:SendTmuxCommand(targeted_cmd)
|
||||||
call s:SendEnterSequence()
|
call s:SendEnterSequence()
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user