Commits

Tamas Kovacs committed 3f46006

Version 0.8.1

Added action handling to Inspector, fixed Inspector output, bugfixes: read-string mode was stuck, buffer corruption with two source windows (thanks to Philipp Marek), eliminate multiple CursorHold autocommands (thanks to Philipp Marek), completion with special characters in symbol name (thanks to Philipp Marek), sometimes cursor went to the start of line in insert mode, syntax error in Untrace All (thanks to Philipp Marek), removed ' prefix from symbol selection (except for Inspect), keep cursor position in Describe and Compile-Region.

Comments (0)

Files changed (4)

-*slimv.txt*                    Slimv                 Last Change: 14 Apr 2011
+*slimv.txt*                    Slimv                 Last Change: 20 Apr 2011
 
 Slimv                                                                  *slimv*
-                               Version 0.8.0
+                               Version 0.8.1
 
 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.8.1  - Added action handling to Inspector, fixed Inspector output.
+       - Bugfix: read-string mode was stuck.
+       - Bugfix: buffer corruption with two source windows
+         (thanks to Philipp Marek).
+       - Bugfix: eliminate multiple CursorHold autocommands
+         (thanks to Philipp Marek).
+       - Bugfix: completion with special characters in symbol name
+         (thanks to Philipp Marek).
+       - Bugfix: sometimes cursor went to the start of line in insert mode.
+       - Bugfix: syntax error in Untrace All (thanks to Philipp Marek).
+       - Bugfix: removed ' prefix from symbol selection (except for Inspect).
+       - Bugfix: keep cursor position in Describe and Compile-Region.
+
 0.8.0  - Major update: added SWANK client (many thanks to Philipp Marek).
        - Split documentation into three parts.
        - Added keymapping hints to GUI menu items.
-*swank.txt*                    Slimv                 Last Change: 14 Apr 2011
+*swank.txt*                    Slimv                 Last Change: 18 Apr 2011
 
 SWANK client for Slimv                                    *swank* *slimv-swank*
-                               Version 0.8.0
+                               Version 0.8.1
 
 The Superior Lisp Interaction Mode for Vim.
 Slimv contains a SWANK client that can communicate with a running SWANK server
   When pressing Enter on the top line starting with 'Inspecting' then the
   currently inspected value is reloaded.
 
+  When pressing Enter on a line starting with <nn> (where nn is the action
+  identifier) then nn-th action is called.
+
   When pressing Enter on a line starting with [nn] (where nn is the part
   identifier) then nn-th part is inspected.
 
   swank:frame-locals-and-catch-tags
   swank:init-inspector
   swank:inspect-nth-part
+  swank:inspector-call-nth-action
   swank:inspector-pop
   swank:invoke-nth-restart-for-emacs
   swank:listener-eval

ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
-" Version:      0.8.0
-" Last Change:  15 Apr 2011
+" Version:      0.8.1
+" Last Change:  20 Apr 2011
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
 let s:debug_activated = 0                                 " Are we in the SWANK debugger?
 let s:debug_move_cursor = 0                               " Move cursor to Restarts when debug activated
 let s:compiled_file = ''                                  " Name of the compiled file
+let s:au_curhold_set = 0                                  " Whether the autocommand has been set
 let s:skip_sc = 'synIDattr(synID(line("."), col("."), 0), "name") =~ "[Ss]tring\\|[Cc]omment"'
                                                           " Skip matches inside string or comment 
 
     redir END
 
     if s:swank_action != '' && msg != ''
-        "echo s:swank_action
         if s:swank_action == ':describe-symbol'
             echo msg
             echo input('Press ENTER to continue.')
         " REPL buffer not loaded
         return
     endif
+    let repl_win = bufwinnr( repl_buf )
+    let this_win = winnr()
 
     if msg == ''
         " No new REPL output since the last refresh
     if repl_buf != this_buf
         " Switch to the REPL buffer/window
         try
-            if g:slimv_repl_split
-                wincmd w
+            if g:slimv_repl_split && repl_win != -1
+                if this_win != repl_win
+                    execute repl_win . "wincmd w"
+                endif
             else
                 execute "buf " . repl_buf
             endif
         stopinsert
     endif
 
-    if repl_buf != this_buf && !s:debug_activated
+    if repl_buf != this_buf && repl_win != -1 && !s:debug_activated
         " Switch back to the caller buffer/window
         if g:slimv_repl_split
-            wincmd w
+            if this_win != repl_win
+                execute this_win . "wincmd w"
+            endif
         else
             execute "buf " . this_buf
         endif
         " REPL buffer not loaded
         return
     endif
+    let repl_win = bufwinnr( repl_buf )
+    let this_win = winnr()
 
     if g:slimv_swank && s:swank_connected
         "execute 'python swank_output(' . repl_buf . ')'
     if repl_buf != this_buf
         " Switch to the REPL buffer/window
         try
-            if g:slimv_repl_split
-                wincmd w
+            if g:slimv_repl_split && repl_win != -1
+                if this_win != repl_win
+                    execute repl_win . "wincmd w"
+                endif
             else
                 execute "buf " . repl_buf
             endif
     call SlimvMarkBufferEnd()
     set nomodified
 
-    if repl_buf != this_buf
+    if repl_buf != this_buf && repl_win != -1 && !s:debug_activated
         " Switch back to the caller buffer/window
         if g:slimv_repl_split
-            wincmd w
+            if this_win != repl_win
+                execute this_win . "wincmd w"
+            endif
         else
             execute "buf " . this_buf
         endif
     call SlimvRefreshReplBuffer()
     if g:slimv_repl_open
         if mode() == 'i' || mode() == 'I'
-            " Put an empty '<C-O>:<CR>' command into the typeahead buffer
-            call feedkeys("\<c-o>:\<cr>")
+            " Put '<Insert>' twice into the typeahead buffer, which should not do anything
+            " just switch to overwrite mode then back to insert mode
+            call feedkeys("\<insert>\<insert>")
         else
             " Put an incomplete 'f' command and an Esc into the typeahead buffer
             call feedkeys("f\e")
         execute "au CursorMoved  * :call SlimvRefreshReplBuffer()"
         execute "au CursorMovedI * :call SlimvRefreshReplBuffer()"
     endif
-    execute "au CursorHold   * :call SlimvTimer()"
-    execute "au CursorHoldI  * :call SlimvTimer()"
+    if ! s:au_curhold_set
+        let s:au_curhold_set = 1
+        execute "au CursorHold   * :call SlimvTimer()"
+        execute "au CursorHoldI  * :call SlimvTimer()"
+    endif
     call SlimvRefreshReplBuffer()
 endfunction
 
     endif
     execute "au! CursorHold"
     execute "au! CursorHoldI"
+    let s:au_curhold_set = 0
     set noreadonly
 endfunction
 
     call SlimvAddReplMenu()
     execute "au FileChangedRO " . g:slimv_repl_file . " :call SlimvRefreshModeOff()"
     call SlimvRefreshModeOn()
-    call SlimvRefreshReplBuffer()
 endfunction
 
 " Called when leaving REPL buffer
     endtry
     if g:slimv_repl_split
         call SlimvRefreshModeOn()
-        call SlimvRefreshReplBuffer()
     else
         call SlimvRefreshModeOff()
     endif
 
 " Select symbol under cursor and return it
 function! SlimvSelectSymbol()
+    if SlimvGetFiletype() == 'clojure'
+        setlocal iskeyword+=~,#,&,\|,{,},!,?
+    else
+        setlocal iskeyword+=~,#,&,\|,{,},[,],!,?
+    endif
+    let symbol = expand('<cword>')
+    return symbol
+endfunction
+
+" Select symbol with possible prefixes under cursor and return it
+function! SlimvSelectSymbolExt()
     let save_iskeyword = &iskeyword
     if SlimvGetFiletype() == 'clojure'
         setlocal iskeyword+=~,#,&,\|,{,},!,?,'
 
 " Execute the given SWANK command with current package defined
 function! SlimvCommandUsePackage( cmd )
+    let oldpos = getpos( '.' ) 
     call SlimvFindPackage()
     let s:refresh_disabled = 1
     call SlimvCommand( a:cmd )
     let s:swank_package = ''
+    call setpos( '.', oldpos ) 
     let s:refresh_disabled = 0
     call SlimvRefreshReplBuffer()
 endfunction
         call SlimvEval( ['[0]'] )
         return
     endif
+
     if line[0] == '['
         if line[0:3] == '[<<]'
             " Pop back up in the inspector
         endif
     endif
 
+    if line[0] == '<'
+        " Inspector n-th action
+        let item = matchstr( line, '\d\+' )
+        if item != ''
+            call SlimvEval( ['<' . item . '>'] )
+            return
+        endif
+    endif
+
     " No special treatment, perform the original function
     execute "normal! \<CR>"
 endfunction
 " Switch trace off for the selected function (or all functions for swank)
 function! SlimvUntrace()
     if g:slimv_swank
-        if g:swank_connected
+        if s:swank_connected
             let s:refresh_disabled = 1
             call SlimvCommand( 'python swank_untrace_all()' )
             let s:refresh_disabled = 0
     endif
 endfunction
 
-" Inspect symbol
+" Inspect symbol under cursor
 function! SlimvInspect()
-    let s = input( 'Inspect: ', SlimvSelectSymbol() )
+    let s = input( 'Inspect: ', SlimvSelectSymbolExt() )
     if s != ''
         if g:slimv_swank
             if s:swank_connected
 endfunction
 
 function! SlimvCompileRegion() range
+    let oldpos = getpos( '.' ) 
     let lines = SlimvGetRegion()
     let region = join( lines, "\n" )
     call SlimvFindPackage()
         let region = substitute( region, '"', '\\\\"', 'g' )
         call SlimvEvalForm1( g:slimv_template_compile_string, region )
     endif
+    call setpos( '.', oldpos ) 
 endfunction
 
 " ---------------------------------------------------------------------
 function! SlimvComplete( findstart, base )
     if a:findstart
         " Locate the start of the symbol name
-        let line = getline( '.' )
-        let start = col( '.' ) - 1
-        while start > 0 && ( line[start - 1] =~ '\k' || match( '\*&', line[start - 1] ) >= 0 )
-            let start -= 1
-        endwhile
-        return start
+        if SlimvGetFiletype() == 'clojure'
+            setlocal iskeyword+=~,#,&,\|,{,},!,?
+        else
+            setlocal iskeyword+=~,#,&,\|,{,},[,],!,?
+        endif
+        let upto = strpart( getline( '.' ), 0, col( '.' ) - 1)
+        let p = match(upto, '\k\+$')
+        return p 
     else
         " Find all symbols starting with "a:base"
         if g:slimv_swank && s:swank_connected

ftplugin/swank.py

 #
 # SWANK client for Slimv
 # swank.py:     SWANK client code for slimv.vim plugin
-# Version:      0.8.0
-# Last Change:  14 Apr 2011
+# Version:      0.8.1
+# Last Change:  18 Apr 2011
 # Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 # License:      This file is placed in the public domain.
 #               No warranty, express or implied.
     """
     Parse the swank inspector output
     """
-    buf = '\n \nInspecting ' + parse_plist(struct, ':title') + '\n--------------------'
+    buf = '\n \nInspecting ' + parse_plist(struct, ':title') + '\n--------------------\n'
     pcont = parse_plist(struct, ':content')
     cont = pcont[0]
     lst = []
-    desc = ''
-    sep = ''
+    linestart = 0
     for el in cont:
+        logprint(str(el))
         if type(el) == list:
-            lst.append([desc, sep, unquote(el[1]), unquote(el[2])])
-            desc = ''
-            sep = ''
-        else:
-            stg = unquote(el)
-            if stg == "\n":
-                if desc:
-                    lst.append([desc, sep, '', ''])
-                desc = ''
-                sep = ''
-            elif stg == ': ' or stg == ' ':
-                sep = unquote(stg)
+            if el[0] == ':action':
+                item = '<' + unquote(el[2]) + '> '
+            else:
+                item = '[' + unquote(el[2]) + '] '
+            if linestart < 0:
+                lst.append("\n")
+                linestart = len(lst)
+            lst.insert(linestart, item)
+            linestart = -1
+            text = unquote(el[1])
+            if text[-len(item):] == ' ' * len(item):
+                # If possible, remove spaces from the end in the length of item info
+                lst.append(text[:-len(item)])
             else:
-                desc = unquote(stg)
-    for (desc, sep, data, item) in lst:
-        buf = buf + "\n"
-        if item:
-            buf = buf + "[" + item + "]  "
-        buf = buf + "%s%s%s" % (desc, sep, data)
+                lst.append(text)
+        else:
+            text = unquote(el)
+            lst.append(text)
+            if text == "\n":
+                linestart = len(lst)
+    for s in lst:
+        buf = buf + s
     buf = buf + '\n \n[<<]'
     return buf
 
                                 keys = make_keys(params)
                                 retval = retval + '  ' + keys[':name'] + ' = ' + keys[':value'] + '\n'
                             elif element == ':title':
+                                logprint(str(params))
                                 retval = retval + swank_parse_inspect(params)
                             elif element == ':compilation-result':
                                 logprint(str(params))
     swank_rex(':undefine-function', cmd, get_package(), 't')
 
 def swank_return_string(s):
+    global read_string
     swank_send('(:emacs-return-string ' + read_string[0] + ' ' + read_string[1] + ' ' + s + ')')
+    read_string = None
 
 def swank_inspect(symbol):
     cmd = '(swank:init-inspector "' + symbol + '")'
     cmd = '(swank:inspect-nth-part ' + str(n) + ')'
     swank_rex(':inspect-nth-part', cmd, 'nil', 't')
 
+def swank_inspector_nth_action(n):
+    cmd = '(swank:inspector-call-nth-action ' + str(n) + ')'
+    swank_rex(':inspector-call-nth-action', cmd, 'nil', 't')
+
 def swank_inspector_pop():
     swank_rex(':inspector-pop', '(swank:inspector-pop)', 'nil', 't')
 
             swank_inspector_pop()
         else:
             swank_inspect_nth_part(form[1:-2])
+    elif form[0] == '<':
+        swank_inspector_nth_action(form[1:-2])
     else:
         # Normal s-expression evaluation
         pkg = vim.eval("s:swank_package")