Commits

Tamas Kovacs committed 7aa8338

Wrap SlimvArglist*() function calls in 'set ve=all'.
Explanation: col('.') returns one less inside an insert mode mapping when
the cursor is at the end of line and virtualedit is not 'all'.
This causes the cursor being placed left of the <space> just entered.

Comments (0)

Files changed (1)

ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
 " Version:      0.9.10
-" Last Change:  15 Dec 2012
+" Last Change:  09 Jan 2013
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
         inoremap <buffer> <silent>        <Up>     <C-R>=pumvisible() ? "\<lt>Up>" : "\<lt>C-O>:call SlimvHandleUp()\<lt>CR>"<CR>
         inoremap <buffer> <silent>        <Down>   <C-R>=pumvisible() ? "\<lt>Down>" : "\<lt>C-O>:call SlimvHandleDown()\<lt>CR>"<CR>
     else
-        inoremap <buffer> <silent>        <CR>     <C-R>=pumvisible() ? "\<lt>CR>" : SlimvHandleEnterRepl()<CR><C-R>=SlimvArglistOnEnter()<CR>
+        inoremap <buffer> <silent>        <CR>     <C-O>:let save_ve=&ve<CR><C-O>:set ve=all<CR><C-R>=pumvisible() ? "\<lt>CR>" : SlimvHandleEnterRepl()<CR><C-R>=SlimvArglistOnEnter(save_ve)<CR>
         inoremap <buffer> <silent>        <C-Up>   <C-R>=pumvisible() ? "\<lt>Up>" : "\<lt>C-O>:call SlimvHandleUp()\<lt>CR>"<CR>
         inoremap <buffer> <silent>        <C-Down> <C-R>=pumvisible() ? "\<lt>Down>" : "\<lt>C-O>:call SlimvHandleDown()\<lt>CR>"<CR>
     endif
             else
                 " Expression is not finished yet, indent properly and wait for completion
                 " Indentation works only if lisp indentation is switched on
-                call SlimvArglist()
+                let save_ve = &virtualedit
+                set virtualedit=all
+                call SlimvArglist( save_ve )
                 let l = line('.') + 1
                 call append( '.', '' )
                 call setline( l, repeat( ' ', SlimvIndent(l) ) )
 endfunction
 
 " Display arglist after pressing Enter
-function! SlimvArglistOnEnter()
+function! SlimvArglistOnEnter( set_ve )
     if s:arglist_line > 0
         let l = line('.')
         if getline(l) == ''
             call setline( l, repeat( ' ', SlimvIndent(l) ) )
             normal! $
         endif
-        call SlimvArglist( s:arglist_line, s:arglist_col )
+        call SlimvArglist( a:set_ve, s:arglist_line, s:arglist_col )
     endif
     let s:arglist_line = 0
     let s:arglist_col = 0
 
     " This function is called from <C-R>= mappings, must return empty string
+    let &virtualedit = a:set_ve
     return ''
 endfunction
 
 endfunction
 
 " Display function argument list
-" Optional argument is the number of characters typed after the keyword
-function! SlimvArglist( ... )
+" First argument is the original 'virtualedit' value to restore at the end.
+" When the function is called from a mapping, 'virtualedit' shall be set
+" in the mapping, before any function is called.
+" Optional arguments are the line and column where the function name ends.
+function! SlimvArglist( set_ve, ... )
     if a:0
         " Symbol position supplied
         let l = a:1
     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
+    let &virtualedit = a:set_ve
     return ''
 endfunction
 
 " 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> <CR>       <C-R>=pumvisible() ?  "\<lt>CR>" : SlimvHandleEnter()<CR><C-R>=SlimvArglistOnEnter()<CR>
+    inoremap <silent> <buffer> <Space>    <Space><C-O>:let save_ve=&ve<CR><C-O>:set ve=all<CR><C-R>=SlimvArglist(save_ve, line('.'),col('.')-1)<CR>
+    inoremap <silent> <buffer> <CR>       <C-O>:let save_ve=&ve<CR><C-O>:set ve=all<CR><C-R>=pumvisible() ? "\<lt>CR>" : SlimvHandleEnter()<CR><C-R>=SlimvArglistOnEnter(save_ve)<CR>
     "noremap  <silent> <buffer> <C-C>      :call SlimvInterrupt()<CR>
     if !exists( 'b:au_insertleave_set' )
         let b:au_insertleave_set = 1
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.