Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow _EscapeText_* to return string or array

A string gets converted to an array of 1 item.

Array items are sent sequentially. This is useful to wrap, or prefix the
text with character sequences.

Why? Because CoffeeScript flushed the input after a CTRL-v and we
needed to send the content in multiple parts. See next commit.
  • Loading branch information...
commit 179bdc2ec7c4d6655d4dd8fe1cf937be43026107 1 parent 96d4463
@jpalardy jpalardy authored
View
2  ftplugin/python/slime.vim
@@ -1,4 +1,6 @@
+
function! _EscapeText_python(text)
let no_empty_lines = substitute(a:text, '\n\s*\ze\n', "", "g")
return substitute(no_empty_lines, "\n", "
", "g")
+endfunction
View
4 ftplugin/scala/slime.vim
@@ -1,3 +1,5 @@
+
function! _EscapeText_scala(text)
- return ":paste\n" . a:text . ""
+ return [":paste\n", a:text, ""]
endfunction
+
View
26 plugin/slime.vim
@@ -69,16 +69,24 @@ function! s:SID()
endfun
function! s:_EscapeText(text)
- 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])
+ let result = call(custom_escape, [a:text])
end
end
- return transformed_text
+ " use a:text if the ftplugin didn't kick in
+ if !exists("result")
+ let result = a:text
+ end
+
+ " return an array, regardless
+ if type(result) == type("")
+ return [result]
+ else
+ return result
+ end
endfunction
function! s:SlimeSendOp(type, ...) abort
@@ -145,8 +153,14 @@ function! s:SlimeSend(text)
let v:errmsg = 'slime: ' . msg
throw v:errmsg
end
- let transformed_text = s:_EscapeText(a:text)
- call s:SlimeDispatch('Send', b:slime_config, transformed_text)
+
+ " this used to return a string, but some receivers (coffee-script)
+ " will flush the rest of the buffer given a special sequence (ctrl-v)
+ " so we, possibly, send many strings -- but probably just one
+ let pieces = s:_EscapeText(a:text)
+ for piece in pieces
+ call s:SlimeDispatch('Send', b:slime_config, piece)
+ endfor
endfunction
function! s:SlimeConfig() abort
Please sign in to comment.
Something went wrong with that request. Please try again.