From 191d9d843cecd540414726d05f8ef6d349ad9451 Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Sun, 26 Jan 2014 14:57:28 -0500 Subject: [PATCH] Add support for python syntactic whitespace Closes #18 - Stripping whitespace Add ipython readline and auto-indent notes --- README.mkd | 21 ++++++++++++++++++ doc/vim-tmux-runner.txt | 45 ++++++++++++++++++++++++++++++++++++++ plugin/vim-tmux-runner.vim | 22 ++++++++++++++++--- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/README.mkd b/README.mkd index 288dfda..c100441 100644 --- a/README.mkd +++ b/README.mkd @@ -37,6 +37,27 @@ cd bundles git clone https://github.com/christoomey/vim-tmux-runner.git ``` +## Python Notes + +If you are using python, or any other language with syntactic whitespace, you +will likely want to change the following settings to better support the +required whitespace: + +``` vim +let g:VtrStripLeadingWhitespace = 0 +let g:VtrClearEmptyLines = 0 +let g:VtrAppendNewline = 1 +``` + +Additionally, if you are using ipython, you will need to ensure it is +installed with proper readline support. Ref [this Stack Overflow thread][] and +answer for more detail. + +You will also need to start ipython with auto-indentation disabled, which can +be done with the following `ipython --no-autoindent`. + +[this Stack Overflow thread]: http://stackoverflow.com/a/1840304/2751777 + ## Development Status This plugin is currently very much an alpha. Although the major features are diff --git a/doc/vim-tmux-runner.txt b/doc/vim-tmux-runner.txt index 7a45139..377dd61 100644 --- a/doc/vim-tmux-runner.txt +++ b/doc/vim-tmux-runner.txt @@ -34,6 +34,9 @@ CONTENTS *vtr-contents* 3.9 ................................ |VtrClearOnReattach| 3.10 ............................... |VtrDetachedName| 3.11 ............................... |VtrClearSequence| + 3.12 ............................... |VtrStripLeadningWhitespace| + 3.13 ............................... |VtrClearEmptyLines| + 3.14 ............................... |VtrAppendNewline| ============================================================================== ABOUT (1) *VTR-About* @@ -398,5 +401,47 @@ insert mode. See the help file, ':help i_Ctrl-v', for more detail. Default: " " +------------------------------------------------------------------------------ + *VtrStripLeadningWhitespace* + +3.12 g:VtrStripLeadingWhitespace~ + +When interacting with most REPLs, indentation will automatically be added to +the beginning of lines based on the syntax. The setting causes VTR to strip +leading whitespace before sending lines to avoid doubly indented lines. + +By default this setting is enabled, but if you are using a language with +syntactic whitespace like python or coffeescript then you will likely want to +disable this setting. + + let g:VtrStripLeadingWhitespace = 0 + +Default: 1 + +------------------------------------------------------------------------------ + *VtrClearEmptyLines* + +3.13 g:VtrClearEmptyLines~ + +VTR will clear out empty lines in visually selected regions to avoid clutter in +the REPLs. If the blank lines are relevant, you can disable this behavior. + + let g:VtrClearEmptyLines = 0 + +Default: 1 + +------------------------------------------------------------------------------ + *VtrAppendNewline* + +3.14 g:VtrAppendNewline + +If you are using python or any language with syntactic whitespace, an empty +line might be needed to close the preceding context. To enable appending a new +line to any multi line send, use the following setting. + + let g:VtrAppendNewline = 1 + +Default: 0 + ============================================================================== vim:tw=78:ts=2:sw=2:expandtab:ft=help:norl: diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim index def3c90..6018772 100644 --- a/plugin/vim-tmux-runner.vim +++ b/plugin/vim-tmux-runner.vim @@ -342,10 +342,23 @@ function! s:SendSelectedToRunner() call s:SendTextToRunner(lines) endfunction +function! s:PrepareLines(lines) + let prepared = a:lines + if g:VtrStripLeadingWhitespace + let prepared = map(a:lines, 'substitute(v:val,"^\\s*","","")') + endif + if g:VtrClearEmptyLines + let prepared = filter(prepared, "!empty(v:val)") + endif + if g:VtrAppendNewline && len(a:lines) > 1 + let prepared = add(prepared, "\r") + endif + return prepared +endfunction + function! s:SendTextToRunner(lines) - let whitespace_stripped = map(a:lines, 'substitute(v:val,"^\\s*","","")') - let without_empty_lines = filter(whitespace_stripped, "!empty(v:val)") - let joined_lines = join(without_empty_lines, "\r") . "\r" + let prepared = s:PrepareLines(a:lines) + let joined_lines = join(prepared, "\r") . "\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) @@ -409,6 +422,9 @@ function! s:InitializeVariables() call s:InitVariable("g:VtrDetachedName", "VTR_Pane") call s:InitVariable("g:VtrClearSequence", " ") call s:InitVariable("g:VtrDisplayPaneNumbers", 1) + call s:InitVariable("g:VtrStripLeadingWhitespace", 1) + call s:InitVariable("g:VtrClearEmptyLines", 1) + call s:InitVariable("g:VtrAppendNewline", 0) let s:vtr_percentage = g:VtrPercentage let s:vtr_orientation = g:VtrOrientation endfunction