Tamas Kovacs avatar Tamas Kovacs committed 9505a33

Version 0.1.1: Corrected memory fill up problem after a long REPL session.

Comments (0)

Files changed (3)

-*slimv.txt*                    Slimv                 Last Change: 30 Jan 2009
+*slimv.txt*                    Slimv                 Last Change: 04 Feb 2009
 
 Slimv                                                                  *slimv*
-                               Version 0.1
+                               Version 0.1.1
 
 The Superior Lisp Interaction Mode for Vim.
 This plugin is aimed to help Lisp development by interfacing between Vim and
     let g:slimv_template_apropos = '(apropos "%1")'
 
                                                  *g:slimv_template_macroexpand*
-Lisp form built when issuing the 'macroexpand-1' command.
+Lisp form built when issuing the 'macroexpand-1' command, after "defmacro"
+string is replaced with "macroexpand-1".
 Example:
     let g:slimv_template_macroexpand = '(pprint %1)'
 
                                              *g:slimv_template_macroexpand_all*
-Lisp form built when issuing the 'macroexpand-all' command.
+Lisp form built when issuing the 'macroexpand-all' command, after "defmacro"
+string is replaced with "macroexpand".
 Example:
     let g:slimv_template_macroexpand_all = '(pprint %1)'
 
 ===============================================================================
 CHANGE LOG                                                    *slimv-changelog*
 
-0.1    - Initial release. And hope not the last one :-)
+0.1.1  - Corrected memory fillup problem after a long REPL session.
+
+0.1    - Initial release.
 
 ===============================================================================
 KNOWN ISSUES                                                     *slimv-issues*
 #!/usr/bin/env python
 
+###############################################################################
+#
+# Client/Server code for Slimv
+# slimv.py:     Client/Server code for slimv.vim plugin
+# Version:      0.1.1
+# Last Change:  04 Feb 2009
+# Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
+# License:      This file is placed in the public domain.
+#               No warranty, express or implied.
+#               *** ***   Use At-Your-Own-Risk!   *** ***
+# 
+###############################################################################
+
 import os
 import sys
 import getopt
 import shlex
 import socket
 from subprocess import Popen, PIPE, STDOUT
-from threading import Thread
+from threading import Thread, BoundedSemaphore
 
 autoconnect = 1             # Start and connect server automatically
 
 
 buffer      = ''            # Text buffer (display queue) to collect socket input and REPL output
 buflen      = 0             # Amount of text currently in the buffer
+buffer_sema = BoundedSemaphore();
+                            # Semaphore to synchronize access to the global display queue
 
 python_path = 'python'      # Path of the Python interpreter (overridden via command line args)
 lisp_path   = 'clisp.exe'   # Path of the Lisp interpreter (overridden via command line args)
     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
-    time.sleep(0.01)
+
+    time.sleep(0.01)        # give a little chance to receive some output from the REPL before the next query
+                            #TODO: synchronize it correctly
+
 
 
 def translate_send_line( server, line ):
 
     def run( self ):
         global buffer
+        global buffer_sema
         global terminate
 
         # Open server socket
                 try:
                     lstr = conn.recv(4)
                     if len( lstr ) <= 0:
-                        break;
+                        break
                 except:
                     break
                 if terminate:
                     # Fork here: write message to the stdin of REPL
                     # and also write it to the display (display queue buffer)
                     self.inp.write( received + '\n' )
+                    buffer_sema.acquire()
                     buffer = buffer + received + '\n'
+                    buffer_sema.release()
+
             log( "sl.close", 1 )
             conn.close()
 
 
     def run( self ):
         global buffer
+        global buffer_sema
         global terminate
 
         log( "ol.start", 1 )
                 # Read input from the stdout of REPL
                 # and write it to the display (display queue buffer)
                 c = self.out.read(1)
+                buffer_sema.acquire()
                 buffer = buffer + c
+                buffer_sema.release()
             except:
                 #TODO: should we set terminate=1 here as well?
                 break
     """
     global buffer
     global buflen
+    global buffer_sema
 
+    buffer_sema.acquire()
     l = len( buffer )
     while buflen < l:
         try:
             buflen = buflen + 1
         except:
             break
+    buffer = ''
+    buflen = 0
+    buffer_sema.release()
 
 
 def server( args ):
     while not terminate:
         try:
             # Constantly display messages in the display queue buffer
-            #TODO: it would be better some wakeup mechanism here
+            #TODO: it would be better having some wakeup mechanism here
             log( "in.step", 1 )
             time.sleep(0.01)
             buffer_read_and_display()
 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
-" Last Change:  2008 May 02
+" Version:      0.1.1
+" Last Change:  04 Feb 2009
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
     let g:slimv_menu = 1
 endif
 
+" Name of the REPL buffer inside Vim
+if !exists( 'g:slimv_bufname' )
+    let g:slimv_bufname = 'Slimv.REPL'
+endif
+
 
 " =====================================================================
 "  Template definitions
 "  General utility functions
 " =====================================================================
 
+" Open a new REPL buffer or switch to the existing one
+function! SlimvOpenReplBuffer()
+    "TODO: check if this works without 'set hidden'
+    "TODO: add option for split window
+    let repl_buf = bufnr( g:slimv_bufname )
+    if repl_buf == -1
+        " Create a new REPL buffer
+        exe "edit " . g:slimv_bufname
+    else
+        " REPL buffer is already created. Check if it is open in a window
+        let repl_win = bufwinnr( repl_buf )
+        if repl_win != -1
+            " Switch to the REPL window
+            if winnr() != repl_win
+                exe repl_win . "wincmd w"
+            endif
+        else
+            " Switch to the REPL buffer
+            exe "buffer " . repl_buf
+        endif
+    endif
+    
+    " This buffer will not have an associated file
+    set buftype=nofile
+endfunction
+
 " Select symbol under cursor and copy it to register 's'
 function! SlimvSelectSymbol()
     "TODO: can we use expand('<cWORD>') here?
     if g:slimv_debug_client == 0
         let result = system( g:slimv_client . ' -c ' . SlimvMakeArgs(a:args) )
     else
-        execute '!' . g:slimv_client . SlimvMakeArgs(a:args)
+        execute '!' . g:slimv_client . ' -c ' . SlimvMakeArgs(a:args)
     endif
 endfunction
 
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.