Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add CoffeeScript REPL support for tmux #13

Closed
wants to merge 4 commits into from

2 participants

@epeli

The CoffeeScript REPL uses special key binding for multi-line input (Ctrl-v). So we need to enter this mode before we can send code to the CoffeeScript REPL. That's why I added hooks which can be executed before slime sends the code.

I don't use GNU screen so I don't know how to implement this for it, but I added the hooks for it too.

Also note that multi-line REPL support is only in master branch of CoffeeScript, but I think it's coming with next release, 1.2.1. See:

jashkenas/coffeescript#1979

@jpalardy
Owner

Interesting. I'm going to have to review this… and try to understand what it means from screen.

@jpalardy
Owner

Went through the code. This is useful stuff.

However, I'm not sure why the "prefix" and "postfix" couldn't be concatenated to the string as it is done in the Python and Scala ftplugin. Ctrl-v and ctrl-d could probably be piped with the rest -- at least in the tmux version. I'm aware there are issues on the screen side of this.

Can you try again on another branch?

@jpalardy jpalardy closed this pull request from a commit
@jpalardy support for CoffeeScript
closes #13
d0cea52
@jpalardy jpalardy closed this in d0cea52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2012
  1. @epeli
  2. @epeli

    Add CoffeeScript support for tmux.

    epeli authored
    CoffeeScript has multi-line input support in 1.2.1=< which is not
    released yet. See:
    
    jashkenas/coffeescript#1979
  3. @epeli
  4. @epeli
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 0 deletions.
  1. +12 −0 ftplugin/coffee/slime.vim
  2. +21 −0 plugin/slime.vim
View
12 ftplugin/coffee/slime.vim
@@ -0,0 +1,12 @@
+
+
+" CoffeeScript REPL enters multi-line mode with Ctrl+v
+function! _PreTmux_coffee(socket_name, target_pane)
+ call system("tmux -L " . a:socket_name . " send-keys C-v -t " . a:target_pane)
+endfunction
+
+" Exit multi-line REPL mode with Ctrl+d
+function! _PostTmux_coffee(socket_name, target_pane)
+ call system("tmux -L " . a:socket_name . " send-keys C-d -t " . a:target_pane)
+endfunction
+
View
21 plugin/slime.vim
@@ -32,8 +32,14 @@ let g:slime_loaded = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:ScreenSend(config, text)
+
+ call s:ExecFileTypeFn("_PreScreen_", [a:config["sessionname"], a:config["windowname"]])
+
let escaped_text = s:_EscapeText(a:text)
call system("screen -S " . a:config["sessionname"] . " -p " . a:config["windowname"] . " -X stuff " . escaped_text)
+
+ call s:ExecFileTypeFn("_PostScreen_", [a:config["socket_name"], a:config["target_pane"]])
+
endfunction
" Leave this function exposed as it's called outside the plugin context
@@ -55,9 +61,15 @@ endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:TmuxSend(config, text)
+
+ call s:ExecFileTypeFn("_PreTmux_", [a:config["socket_name"], a:config["target_pane"]])
+
let escaped_text = s:_EscapeText(a:text)
call system("tmux -L " . a:config["socket_name"] . " set-buffer " . escaped_text)
call system("tmux -L " . a:config["socket_name"] . " paste-buffer -t " . a:config["target_pane"])
+
+ call s:ExecFileTypeFn("_PostTmux_", [a:config["socket_name"], a:config["target_pane"]])
+
endfunction
function! s:TmuxConfig()
@@ -86,6 +98,15 @@ function! s:_EscapeText(text)
return substitute(shellescape(transformed_text), "\\\\\\n", "\n", "g")
endfunction
+function s:ExecFileTypeFn(fn_name, args)
+ if exists("&filetype")
+ let fullname = a:fn_name . &filetype
+ if exists("*" . fullname)
+ call call(fullname, a:args)
+ end
+ end
+endfunction
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Public interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Something went wrong with that request. Please try again.