Commits

Tamas Kovacs committed a2d63de

Pass python output to Vim in variable instead of redirecting stdout

Comments (0)

Files changed (2)

ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
 " Version:      0.9.9
-" Last Change:  25 Oct 2012
+" Last Change:  02 Nov 2012
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
     let s:refresh_disabled = 1
     silent execute 'python swank_output(1)'
     let s:refresh_disabled = 0
-    let msg = ''
-    redir => msg
+    let s:swank_action = ''
+    let s:swank_result = ''
     silent execute 'python swank_response("")'
-    redir END
 
-    if msg != ''
-        if s:swank_action == ':describe-symbol'
-            echo substitute(msg,'^\n*','','')
-        endif
+    if s:swank_action == ':describe-symbol' && s:swank_result != ''
+        echo substitute(s:swank_result,'^\n*','','')
     endif
     if s:swank_actions_pending
         let s:last_update = -1
 function! SlimvCommandGetResponse( name, cmd, timeout )
     let s:refresh_disabled = 1
     call SlimvCommand( a:cmd )
-    let msg = ''
     let s:swank_action = ''
+    let s:swank_result = ''
     let starttime = localtime()
     let cmd_timeout = a:timeout
     if cmd_timeout == 0
     endif
     while s:swank_action == '' && localtime()-starttime < cmd_timeout
         python swank_output( 0 )
-        redir => msg
         silent execute 'python swank_response("' . a:name . '")'
-        redir END
     endwhile
     let s:refresh_disabled = 0
-    return msg
+    return s:swank_result
 endfunction
 
 " Reload the contents of the REPL buffer from the output file if changed

ftplugin/swank.py

 # SWANK client for Slimv
 # swank.py:     SWANK client code for slimv.vim plugin
 # Version:      0.9.9
-# Last Change:  25 Sep 2012
+# Last Change:  02 Nov 2012
 # Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 # License:      This file is placed in the public domain.
 #               No warranty, express or implied.
 ############################################################################### 
 
 
-import sys
 import socket
 import time
 import select
     try:
         sock.send(t)
     except socket.error:
-        sys.stdout.write( 'Socket error when sending to SWANK server.\n' )
+        vim.command("let s:swank_result='Socket error when sending to SWANK server.\n'")
         swank_disconnect()
 
 def swank_recv_len(timeout):
         try:
             data = sock.recv(l)
         except socket.error:
-            sys.stdout.write( 'Socket error when receiving from SWANK server.\n' )
+            vim.command("let s:swank_result='Socket error when receiving from SWANK server.\n'")
             swank_disconnect()
             return rec
         while data and len(rec) < lenbytes:
                 try:
                     data = sock.recv(l)
                 except socket.error:
-                    sys.stdout.write( 'Socket error when receiving from SWANK server.\n' )
+                    vim.command("let s:swank_result='Socket error when receiving from SWANK server.\n'")
                     swank_disconnect()
                     return rec
     return rec
                 try:
                     data = sock.recv(needed)
                 except socket.error:
-                    sys.stdout.write( 'Socket error when receiving from SWANK server.\n' )
+                    vim.command("let s:swank_result='Socket error when receiving from SWANK server.\n'")
                     swank_disconnect()
                     return rec
                 if len(data) == 0:
-                    sys.stdout.write( 'Socket error when receiving from SWANK server.\n' )
+                    vim.command("let s:swank_result='Socket error when receiving from SWANK server.\n'")
                     swank_disconnect()
                     return rec
                 rec = rec + data
     finally:
         sock = None
         vim.command('let s:swank_connected = 0')
-        sys.stdout.write( 'Connection to SWANK server is closed.\n' )
+        vim.command("let s:swank_result='Connection to SWANK server is closed.\n'")
 
 def swank_input(formvar):
     global empty_last_line
         if not a.pending and (name == '' or name == a.name):
             vc = ":let s:swank_action='" + a.name + "'"
             vim.command(vc)
-            sys.stdout.write(a.result)
+            vim.command("let s:swank_result='%s'" % a.result.replace("'", "''"))
             actions.pop(a.id)
             actions_pending()
             return
     vc = ":let s:swank_action=''"
+    vc = ":let s:swank_result=''"
     vim.command(vc)
     actions_pending()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.