slimv

Discussion of programming Lisps using vi or vim
Post Reply
dmgenp
Posts: 13
Joined: Sat Jun 28, 2008 10:15 am

slimv

Post by dmgenp » Fri Feb 26, 2010 12:00 pm

There's another active project for common lisp/clojure integration, quite useable: http://www.vim.org/scripts/script.php?script_id=2531

There was one problem - on linux, if you use sbcl, and drop into sbcl debugger, there was no method to enter anything, so you basically stuck. Problem was what sbcl debugger talks with the terminal directly, bypassing stdio. So I had to patch the python script to use Pty module.
Sent the patch to the author, hope he'll fix the next version.

patch should apply against v. 0.56

Code: Select all

diff -ur orig/slimv.py changed/slimv.py
--- orig/slimv.py       2010-02-11 00:10:08.989006208 +0500
+++ changed/slimv.py    2010-02-11 00:09:23.369016555 +0500
@@ -14,6 +14,7 @@
 ###############################################################################

 import os
+import pty
 import sys
 import getopt
 import time
@@ -315,7 +316,7 @@
                         # and also write it to the display (display queue buffer)
                         self.buffer.writebegin()
                         self.buffer.write_nolock( received )
-                        self.inp.write( received )
+                        os.write(self.inp.fileno(), received)
                         self.buffer.writeend()

             conn.close()
@@ -385,14 +386,24 @@
     cmd = shlex.split( lisp_exp )

     # Start Lisp
-    repl = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT )
+    if not mswindows:
+       repl_pid, repl_fd = pty.fork()
+       if repl_pid == 0:
+           os.execvp(cmd[0], cmd)
+           os._exit(1)
+       repl_stdin = repl_stdout = os.fdopen(repl_fd)
+    else:
+       r = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT )
+       repl_stdin = r.stdin
+       repl_stout = r.stdout
+

     buffer = repl_buffer( sys.stdout )

     # Create and start helper threads
-    sl = socket_listener( repl.stdin, buffer, repl.pid )
+    sl = socket_listener( repl_stdin, buffer, repl_pid )
     sl.start()
-    ol = output_listener( repl.stdout, buffer )
+    ol = output_listener( repl_stdout, buffer )
     ol.start()

     # Allow Lisp to start, confuse it with some fancy Slimv messages
@@ -407,7 +418,7 @@
             # Read input from the console and write it
             # to the stdin of REPL
             text = raw_input()
-            repl.stdin.write( text + newline )
+            os.write(repl_stdin.fileno(), text + newline)
             buffer.write( text + newline, True )
         except EOFError:
             # EOF (Ctrl+Z on Windows, Ctrl+D on Linux) pressed?
@@ -431,7 +442,7 @@
     # Send exit command to child process and
     # wake output listener up at the same time
     try:
-        repl.stdin.close()
+        repl_stdin.close()
     except:
         # We don't care if this above fails, we'll exit anyway
         pass


dmgenp
Posts: 13
Joined: Sat Jun 28, 2008 10:15 am

Re: slimv

Post by dmgenp » Thu Mar 25, 2010 3:02 am

another hint: when working with threads under sbcl, if debugger is invoked within non-main thread, use (sb-thread:release-foreground) to switch to that thread to choose the restart.

perryl8898
Posts: 5
Joined: Thu Jan 06, 2011 12:21 pm

Re: slimv

Post by perryl8898 » Thu Jan 06, 2011 12:26 pm

dmgenp wrote:another hint: when working with threads under sbcl, if debugger is invoked within non-main thread, use (sb-thread:release-foreground) to switch to that thread to choose the restart.
I didn't know that you could use sb-thread:release-foreground to switch threads. Tips like this make this forum helpful. Thanks for pointing out something that is helpful to us all. i will try this next time I am in this situation.

Post Reply