Tamas Kovacs avatar Tamas Kovacs committed cd983bd

Save and restore cursor position for previously visited pages in Inspector

Comments (0)

Files changed (2)

ftplugin/slimv.vim

 " slimv.vim:    The Superior Lisp Interaction Mode for VIM
 " Version:      0.9.9
-" Last Change:  03 Nov 2012
+" Last Change:  07 Nov 2012
 " Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 " License:      This file is placed in the public domain.
 "               No warranty, express or implied.
     noremap  <buffer> <silent>        <F1>   :call SlimvToggleHelp()<CR>
     noremap  <buffer> <silent>        <CR>   :call SlimvHandleEnterInspect()<CR>
     noremap  <buffer> <silent> <Backspace>   :call SlimvSendSilent(['[-1]'])<CR>
-    execute 'noremap <buffer> <silent> ' . g:slimv_leader.'q      :call SlimvQuitInspect()<CR>'
+    execute 'noremap <buffer> <silent> ' . g:slimv_leader.'q      :call SlimvQuitInspect(1)<CR>'
 
     if version < 703
         " conceal mechanism is defined since Vim 7.3
 endfunction
 
 " Quit Inspector
-function SlimvQuitInspect()
+function SlimvQuitInspect( force )
     " Clear the contents of the Inspect buffer
+    if exists( 'b:inspect_pos' )
+        unlet b:inspect_pos
+    endif
     setlocal noreadonly
     silent! %d
     call SlimvEndUpdate()
-    call SlimvCommand( 'python swank_quit_inspector()' )
+    if a:force
+        call SlimvCommand( 'python swank_quit_inspector()' )
+    endif
     b #
 endfunction
 
     execute "normal! \<CR>"
 endfunction
 
+" Restore Inspector cursor position if the referenced title has already been visited
+function SlimvSetInspectPos( title )
+    if exists( 'b:inspect_pos' ) && has_key( b:inspect_pos, a:title )
+        call winrestview( b:inspect_pos[a:title] )
+    else
+        normal! gg0
+    endif
+endfunction
+
 " Handle normal mode 'Enter' keypress in the Inspector buffer
 function! SlimvHandleEnterInspect()
     let line = getline('.')
         let line = strpart( line, c )
     endif
 
+    if exists( 'b:inspect_title' ) && b:inspect_title != ''
+        " Save cursor position in case we'll return to this page later on
+        if !exists( 'b:inspect_pos' )
+            let b:inspect_pos = {}
+        endif
+	let b:inspect_pos[b:inspect_title] = winsaveview()
+    endif
+
     if line[0] == '['
         if line =~ '^\[--more--\]$'
             " More data follows, fetch next part

ftplugin/swank.py

 # SWANK client for Slimv
 # swank.py:     SWANK client code for slimv.vim plugin
 # Version:      0.9.9
-# Last Change:  06 Nov 2012
+# Last Change:  07 Nov 2012
 # Maintainer:   Tamas Kovacs <kovisoft at gmail dot com>
 # License:      This file is placed in the public domain.
 #               No warranty, express or implied.
 
     vim.command('call SlimvOpenInspectBuffer()')
     buf = vim.current.buffer
-    buf[:] = ['Inspecting ' + parse_plist(struct, ':title'), '--------------------', '']
-    vim.command('let oldpos=winsaveview()')
+    title = parse_plist(struct, ':title')
+    vim.command('let b:inspect_title="' + title + '"')
+    buf[:] = ['Inspecting ' + title, '--------------------', '']
     vim.command('normal! 3G0')
     vim.command('call SlimvHelp(2)')
-    vim.command('call winrestview(oldpos)')
     pcont = parse_plist(struct, ':content')
     inspect_lines = 3
     inspect_newline = True
     swank_parse_inspect_content(pcont)
+    vim.command('call SlimvSetInspectPos("' + title + '")')
 
 def swank_parse_debug(struct):
     """
                                 pass
                             elif element == 'nil' and action and action.name == ':inspector-pop':
                                 # Quit inspector
-                                vim.command('b #')
+                                vim.command('call SlimvQuitInspect(0)')
                             elif element != 'nil' and action and action.name in to_nodisp:
                                 # Do not display output, just store it in actions
                                 action.result = unquote(params)
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.