Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for calling custom functions during escape #7

Merged
merged 3 commits into from

2 participants

@caio

With this patchset, the EscapeText function now calls _EscapeText&filetype before sending the data to screen/tmux. This can be used to wrap the data with instructions to a interpreter, or precompiling the selected text to an intermediary format, or whatever.

An example escaper for the python &filetype which does nothing to the given data:

function! _EscapeText_python(text)
  return a:text
endfunction
caio added some commits
@caio caio Add support for calling custom functions during escape
Custom functions must be named as _EscapeText_&filetype, ex:
_EscapeText_scala
e0b0808
@caio caio Add custom escape for scala in order to use :paste mode ab3c5bc
@caio caio Add custom escaper for python
Somehow the python REPL loses the newline information when pasting.
Convert them to the CRLF character before sending.
ffb3c4e
@jpalardy jpalardy merged commit c029aec into jpalardy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2011
  1. @caio

    Add support for calling custom functions during escape

    caio authored
    Custom functions must be named as _EscapeText_&filetype, ex:
    _EscapeText_scala
  2. @caio
  3. @caio

    Add custom escaper for python

    caio authored
    Somehow the python REPL loses the newline information when pasting.
    Convert them to the CRLF character before sending.
This page is out of date. Refresh to see the latest.
View
3  ftplugin/python/slime.vim
@@ -0,0 +1,3 @@
+function! _EscapeText_python(text)
+ return substitute(a:text, "\n", "
+", "g")
View
3  ftplugin/scala/slime.vim
@@ -0,0 +1,3 @@
+function! _EscapeText_scala(text)
+ return ":paste\n" . a:text . ""
+endfunction
View
11 plugin/slime.vim
@@ -73,7 +73,16 @@ endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:_EscapeText(text)
- return substitute(shellescape(a:text), "\\\\\\n", "\n", "g")
+ let transformed_text = a:text
+
+ if exists("&filetype")
+ let custom_escape = "_EscapeText_" . &filetype
+ if exists("*" . custom_escape)
+ let transformed_text = call(custom_escape, [a:text])
+ end
+ end
+
+ return substitute(shellescape(transformed_text), "\\\\\\n", "\n", "g")
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Something went wrong with that request. Please try again.