Commits

Tamas Kovacs committed 57f8f18

Bugfix: when pressing <Space> sometimes the cursor was placed before the <Space>.
Explanation: if virtualedit is empty and a normal mode command is executed
inside an insert mode mapping at the end of line, then the cursor may be moved
left one character. This is compensated by adding <End> to the mapping.

  • Participants
  • Parent commits 59ea217

Comments (0)

Files changed (1)

File ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
 " Version:      0.9.10
-" Last Change:  15 Dec 2012
+" Last Change:  11 Jan 2013
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
 
 " Display arglist after pressing Enter
 function! SlimvArglistOnEnter()
+    let retval = ""
     if s:arglist_line > 0
+        if col('.') > len(getline('.'))
+            " Stay at the end of line
+            let retval = "\<End>"
+        endif
         let l = line('.')
         if getline(l) == ''
             " Add spaces to make the correct indentation
     let s:arglist_line = 0
     let s:arglist_col = 0
 
-    " This function is called from <C-R>= mappings, must return empty string
-    return ''
+    " This function is called from <C-R>= mappings, return additional keypress
+    return retval
 endfunction
 
 " Handle insert mode 'Tab' keypress by doing completion or indentation
 " Display function argument list
 " Optional argument is the number of characters typed after the keyword
 function! SlimvArglist( ... )
+    let retval = ''
+    let save_ve = &virtualedit
+    set virtualedit=all
     if a:0
         " Symbol position supplied
         let l = a:1
         let c = a:2 - 1
+        let line = getline(l)
     else
         " Check symbol at cursor position
         let l = line('.')
+        let line = getline(l)
         let c = col('.') - 1
+        if c >= len(line)
+            " Stay at the end of line
+            let c = len(line) - 1
+            let retval = "\<End>"
+        endif
+        if line[c-1] == ' '
+            " Is this the space we have just inserted in a mapping?
+            let c = c - 1
+        endif
     endif
-    let line = getline(l)
     call s:SetKeyword()
     if s:swank_connected && c > 0 && line[c-1] =~ '\k\|)\|\]\|}\|"'
-        let save_ve = &virtualedit
-        set virtualedit=all
         " Display only if entering the first space after a keyword
         let matchb = max( [l-200, 1] )
         let [l0, c0] = searchpairpos( '(', '', ')', 'nbW', s:skip_sc, matchb )
                 endif
             endif
         endif
-        let &virtualedit=save_ve
     endif
 
-    " This function is also called from <C-R>= mappings, must return empty string
-    return ''
+    " This function is also called from <C-R>= mappings, return additional keypress
+    let &virtualedit=save_ve
+    return retval
 endfunction
 
 " Start and connect swank server
 " Initialize buffer by adding buffer specific mappings
 function! SlimvInitBuffer()
     " Map space to display function argument list in status line
-    inoremap <silent> <buffer> <Space>    <Space><C-R>=SlimvArglist(line('.'),col('.')-1)<CR>
+    inoremap <silent> <buffer> <Space>    <Space><C-R>=SlimvArglist()<CR>
     inoremap <silent> <buffer> <CR>       <C-R>=pumvisible() ?  "\<lt>CR>" : SlimvHandleEnter()<CR><C-R>=SlimvArglistOnEnter()<CR>
     "noremap  <silent> <buffer> <C-C>      :call SlimvInterrupt()<CR>
     if !exists( 'b:au_insertleave_set' )