Commits

Tamas Kovacs committed fd081ab

Version 0.7.3

Added compatibility with Python 3.x, bugfixes: input lines for REPL were doubled on Linux (thanks to Andrew Hills), however not yet fixed for SBCL, enclose Slimv path in double quotes if contains space, select form when standing on prefix character (e.g. ' or `).

Comments (0)

Files changed (3)

-*slimv.txt*                    Slimv                 Last Change: 16 Nov 2010
+*slimv.txt*                    Slimv                 Last Change: 05 Dec 2010
 
 Slimv                                                                  *slimv*
-                               Version 0.7.2
+                               Version 0.7.3
 
 The Superior Lisp Interaction Mode for Vim.
 This plugin is aimed to help Lisp development by interfacing between Vim and
 ===============================================================================
 CHANGE LOG                                                    *slimv-changelog*
 
+0.7.3  - Added compatibility with Python 3.x.
+       - Bugfix: input lines for REPL were doubled on Linux (thanks to
+         Andrew Hills), however not yet fixed for SBCL.
+       - Bugfix: enclose Slimv path in double quotes if it contains space.
+       - Bugfix: select form when standing on prefix character (e.g. ' or `).
+
 0.7.2  - Added autodetection for /usr/local/bin/clojure on Linux.
        - Added special characters to Lisp keyword selection (iskeyword).
        - Run Vim's original ftplugin/lisp.vim for Clojure filetype.
 Taylor R. Campbell for the Emacs paredit.el script.
 Thanks to the Vim community for testing, commenting and patching the script,
 especially to Philipp Marek, Vlad Hanciuta, Marcin Fatyga, Dmitry Petukhov,
-Daniel Solano G�mez, Brian Kropf, Len Weincier, Andreas Salwasser, Jon Thacker.
+Daniel Solano G�mez, Brian Kropf, Len Weincier, Andreas Salwasser, Jon Thacker,
+Andrew Hills.
 Last but not least many thanks to my wife Andrea (for the Italians out there:
 hey, this is a female name in Hungary :) for her support and patience.
 

ftplugin/slimv.py

-#!/usr/bin/env python
+#!/usr/bin/env python)
 
 ###############################################################################
 #
 # Client/Server code for Slimv
 # slimv.py:     Client/Server code for slimv.vim plugin
-# Version:      0.6.2
-# Last Change:  01 Jun 2010
+# Version:      0.7.3
+# Last Change:  04 Dec 2010
 # Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 # License:      This file is placed in the public domain.
 #               No warranty, express or implied.
 slimv_path  = 'slimv.py'    # Path of this script (determined later)
 run_cmd     = ''            # Complex server-run command (if given via command line args)
 
-newline     = '\n'
-
 # Check if we're running Windows or Mac OS X, otherwise assume Linux
 mswindows = (sys.platform == 'win32')
 darwin = (sys.platform == 'darwin')
     """Print diagnostic messages according to the actual debug level.
     """
     if debug_level >= level:
-        print s
+        sys.stdout.write( s + "\n" )
+
+def str2stream( str ):
+    """Converts string to stream format. Needed for Python 3.x compatibility.
+    """
+    if sys.version_info[0] < 3:
+        return str
+    else:
+        return bytearray( str, 'utf-8' )
+
+def stream2str( arr ):
+    """Converts stream format to string. Needed for Python 3.x compatibility.
+    """
+    if sys.version_info[0] < 3:
+        return arr
+    else:
+        return arr.decode( 'utf-8' )
 
 
 ###############################################################################
     s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
     try:
         s.connect( ( 'localhost', PORT ) )
-    except socket.error, msg:
+    except socket.error:
         if autoconnect:
             # We need to try to start the server automatically
             s.close()
             s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
             try:
                 s.connect( ( 'localhost', PORT ) )
-            except socket.error, msg:
+            except socket.error:
                 s.close()
                 s =  None
         else:   # not autoconnect
-            print "Server not found"
+            sys.stdout.write( "Server not found\n" )
             s = None
     return s
 
     """
     l = len(line)
     lstr = chr(l&255) + chr((l>>8)&255) + chr((l>>16)&255) + chr((l>>24)&255)
-    server.send( lstr )     # send message length first
-    server.send( line )     # then the message itself
+    server.send( str2stream( lstr ) )     # send message length first
+    server.send( str2stream( line ) )     # then the message itself
 
 
 def client_file( input_filename ):
             except:
                 # OK, at least we tried
                 pass
-            self.write_nolock( newline + ';;; Slimv client is connected to REPL on port ' + str(PORT) + '.' + newline, True )
+            self.write_nolock( '\n;;; Slimv client is connected to REPL on port ' + str(PORT) + '.\n', True )
             user = None
             if mswindows:
                 user = os.getenv('USERNAME')
             else:
                 user = os.getenv('USER')
             if not user:
-                self.write_nolock( ';;; This could be the start of a beautiful program.' + newline + newline, True )
+                self.write_nolock( ';;; This could be the start of a beautiful program.\n\n', True )
             else:
-                self.write_nolock( ';;; ' + user + ', this could be the start of a beautiful program.' + newline + newline, True )
+                self.write_nolock( ';;; ' + user + ', this could be the start of a beautiful program.\n\n', True )
         self.sema.release()
 
     def writebegin( self ):
         if not fileonly:
             try:
                 # Write all lines to the display
-                os.write( self.output.fileno(), text )
+                os.write( self.output.fileno(), str2stream( text ) )
             except:
                 pass
 
                         #file.write( text )
                         if self.buffer != '':
                             # There is output pending
-                            os.write(file.fileno(), self.buffer )
+                            os.write( file.fileno(), str2stream( self.buffer ) )
                             self.buffer = ''
-                        os.write(file.fileno(), text )
+                        os.write( file.fileno(), str2stream( text ) )
                     finally:
                         file.close()
                     tries = 0
                 lstr = ''
                 # Read length first, it comes in 4 bytes
                 try:
-                    lstr = conn.recv(4)
+                    lstr = stream2str( conn.recv(4) )
                     if len( lstr ) <= 0:
                         break
                 except:
                         # Read the message itself
                         received = ''
                         while len( received ) < l:
-                            r = conn.recv(l)
+                            r = stream2str( conn.recv(l) )
                             if len( r ) == 0:
                                 break
                             received = received + r
                         # and also write it to the display (display queue buffer)
                         self.buffer.writebegin()
                         self.buffer.write_nolock( received )
-                        os.write(self.inp.fileno(), received)
+                        os.write( self.inp.fileno(), str2stream( received ) )
                         self.buffer.writeend()
 
             conn.close()
                 # Read input from the stdout of REPL
                 # and write it to the display (display queue buffer)
                 if mswindows:
-                    c = self.out.read( 1 )
+                    c = stream2str( self.out.read( 1 ) )
                     if ord( c ) == 0x0D:
                         # Special handling of 0x0D+0x0A on Windows
-                        c2 = self.out.read( 1 )
+                        c2 = stream2str( self.out.read( 1 ) )
                         if ord( c2 ) == 0x0A:
                             self.buffer.write( '\n' )
                         else:
                     else:
                         self.buffer.write( c )
                 elif darwin:
-                    c = self.out.read( 1 )
+                    c = stream2str( self.out.read( 1 ) )
                     self.buffer.write( c )
                 else:
-                    c = self.out.read( 1 )
+                    c = stream2str( self.out.read( 1 ) )
                     if ord( c ) != 0x0D:
                         self.buffer.write( c )
             except:
     s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
     try:
         s.connect( ( 'localhost', PORT ) )
-    except socket.error, msg:
+    except socket.error:
         # Server not found, our time has come, we'll start a new server in a moment
         pass
     else:
         # Server found, nothing to do here
         s.close()
-        print "Server is already running"
+        sys.stdout.write( "Server is already running\n" )
         return
 
     # Build Lisp-starter command
     cmd = shlex.split( lisp_exp )
 
     # Start Lisp
-    if mswindows or darwin:
+    if mswindows or darwin or lisp_path.lower().find( 'sbcl' ) < 0:
         repl = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT )
         repl_stdin = repl.stdin
         repl_stdout = repl.stdout
         repl_pid = repl.pid
     else:
+        # Special handling for SBCL on Linux
         repl_pid, repl_fd = pty.fork()
         if repl_pid == 0:
             os.execvp( cmd[0], cmd )
     ol.start()
 
     # Allow Lisp to start, confuse it with some fancy Slimv messages
-    sys.stdout.write( ";;; Slimv server is started on port " + str(PORT) + newline )
-    sys.stdout.write( ";;; Slimv is spawning REPL..." + newline + newline )
+    sys.stdout.write( ";;; Slimv server is started on port " + str(PORT) )
+    sys.stdout.write( "\n;;; Slimv is spawning REPL...\n\n" )
     time.sleep(0.5)             # wait for Lisp to start
-    #sys.stdout.write( ";;; Slimv connection established" + newline )
 
     # Main server loop
     while not terminate:
         try:
             # Read input from the console and write it
             # to the stdin of REPL
-            text = raw_input()
-            os.write( repl_stdin.fileno(), text + newline )
-            buffer.write( text + newline, True )
+            if sys.version_info[0] < 3:
+                text = raw_input()
+            else:
+                text = input()
+            os.write( repl_stdin.fileno(), str2stream( text + "\n" ) )
+            buffer.write( text + "\n", True )
         except EOFError:
             # EOF (Ctrl+Z on Windows, Ctrl+D on Linux) pressed?
             terminate = 1
     cs = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
     try:
         cs.connect( ( 'localhost', PORT ) )
-        cs.send( " " )
+        cs.send( str2stream( ' ' ) )
     finally:
         # We don't care if this above fails, we'll exit anyway
         cs.close()
         pass
 
     # Be nice
-    print 'Thank you for using Slimv.'
+    sys.stdout.write( 'Thank you for using Slimv.\n' )
 
     # Wait for the child process to exit
     time.sleep(1)
     """Displays program usage information.
     """
     progname = os.path.basename( sys.argv[0] )
-    print 'Usage: ', progname + ' [-d LEVEL] [-s] [-f INFILE]'
-    print
-    print 'Options:'
-    print '  -?, -h, --help                show this help message and exit'
-    print '  -l PATH, --lisp=PATH          path of Lisp interpreter'
-    print '  -r PATH, --run=PATH           full command to run the server'
-    print '  -p PORT, --port=PORT          port number to use by the server/client'
-    print '  -d LEVEL, --debug=LEVEL       set debug LEVEL (0..3)'
-    print '  -s                            start server'
-    print '  -f FILENAME, --file=FILENAME  start client and send contents of file'
-    print '                                named FILENAME to server'
+    sys.stdout.write( 'Usage: ' + progname + ' [-d LEVEL] [-s] [-f INFILE]\n\n' )
+    sys.stdout.write( 'Options:\n' )
+    sys.stdout.write( '  -?, -h, --help                show this help message and exit\n' )
+    sys.stdout.write( '  -l PATH, --lisp=PATH          path of Lisp interpreter\n' )
+    sys.stdout.write( '  -r PATH, --run=PATH           full command to run the server\n' )
+    sys.stdout.write( '  -p PORT, --port=PORT          port number to use by the server/client\n' )
+    sys.stdout.write( '  -d LEVEL, --debug=LEVEL       set debug LEVEL (0..3)\n' )
+    sys.stdout.write( '  -s                            start server\n' )
+    sys.stdout.write( '  -f FILENAME, --file=FILENAME  start client and send contents of file\n' )
+    sys.stdout.write( '                                named FILENAME to server\n' )
 
 
 ###############################################################################
 
 if __name__ == '__main__':
 
-    EXIT, SERVER, CLIENT = range( 3 )
+    EXIT, SERVER, CLIENT = list( range( 3 ) )
     mode = EXIT
     slimv_path = sys.argv[0]
     python_path = sys.executable

ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
-" Version:      0.7.2
-" Last Change:  14 Nov 2010
+" Version:      0.7.3
+" Last Change:  27 Nov 2010
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
     " Start with the Python path
     let cmd = g:slimv_python
 
-    " Add path of Slimv script, on Windows enclose in double quotes
-    if g:slimv_windows
+    " Add path of Slimv script, enclose it in double quotes if path contains spaces
+    if match( g:slimv_path, ' ' ) >= 0
         let cmd = cmd . ' "' . g:slimv_path . '"'
     else
         let cmd = cmd . ' ' . g:slimv_path
 
 " Select bottom level form the cursor is inside and copy it to register 's'
 function! SlimvSelectForm()
+    " Search the opening '(' if we are standing on a special form prefix character
+    let c = col( '.' ) - 1
+    while match( "'`#", getline( '.' )[c] ) >= 0
+        normal! l
+        let c = c + 1
+    endwhile
     normal! va(o
     " Handle '() or #'() etc. type special syntax forms
-    " TODO: what to do with ` operator?
     let c = col( '.' ) - 2
-    while c > 0 && match( ' \t()', getline( '.' )[c] ) < 0
+    while c >= 0 && match( ' \t()', getline( '.' )[c] ) < 0
         normal! h
         let c = c - 1
     endwhile
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.