Home Download Buy Blog Forum Support

BufferScroll

BufferScroll

Postby tito on Tue Oct 25, 2011 12:02 pm

A little plug-in which remembers and restores the scroll and cursor positions, also the selections, folding, bookmarks and mark states.
Sublime already restore these things for tabs that are opened but not for closed tabs.
This plug-in provides persistence when closing and opening.

https://github.com/SublimeText/BufferScroll
Last edited by tito on Wed Oct 26, 2011 7:12 am, edited 1 time in total.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BufferScroll

Postby gregor.hoch on Tue Oct 25, 2011 12:44 pm

sounds very useful but how is this supposed to work? code folding is not remembered in my case (both for project switching as well as for restarting ST2). I am running 2134 on Mac OS 10.7.

Thanks!
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: BufferScroll

Postby tito on Tue Oct 25, 2011 2:10 pm

Nice catch.
The plug-in saves the "state" when the tab is closed, an optimal and non obstructive way.

As I'm seeing.. unfortunately sublime is not sending "on_close" event when switching projects. In a similar way sublime is not sending "on_close" when the application is closed..
Then, the plug-in miss the data because is not informed.

A workaround is to save the data when the tab lose focus(on_deactivated). But that means 1 write every time you switch a tab or the tab lose focus, unnecessary, dirty and not optimal.
Also, another problem is that folded regions can be obtained by unfolding the actual folds, this means every time you switch a tab or the tab lose focus the buffer need to be unfolded and refolded...

I've added the workaround to the plug-in.... update and please be informed I'm not happy and complete dislike this solution.

[edit] - Another problem is that the application by default tries to do its own restoration but this is not working properly for most of the files. then I need to put a time-out to not get my restoration overwrited, which is something I dislike too.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BufferScroll

Postby gregor.hoch on Tue Oct 25, 2011 2:47 pm

I see the problem. tab switching within projects already preserve code folding and cursor position so I agree that the save is unnecessary in that case.
What's about saving the data when
(a) "on_close" (already implemented)
(b) something like "on_save". That takes care of the application close as long as the user saves the file before closing the project. It's also not optimal because the user might save the file, do some code folding and then close ST2.
(c) When some project switch event is fired. Does that exist?
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: BufferScroll

Postby tito on Tue Oct 25, 2011 3:23 pm

I'm afraid there is no event for project switching.
BTW, Sublime should send the on_close event when switching projects and when closing the application.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BufferScroll

Postby tito on Wed Oct 26, 2011 7:15 am

I made some little tweaks and added support for bookmarks and marks.

There is a little bug reproducible even without this plug-in that the first focused tab on switching projects sometimes don't want to scroll, it stay on line 2.
I can live with that. : P

Regards
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BufferScroll

Postby tito on Thu Jan 05, 2012 2:10 pm

This plugin has the following bug:

When the same file is opened on different columns/rows, looks like there is no way to detect on which column/row/group the file is. On restoration all the diffferent column/row/group of that file will get the same scroll, bookmarks, selections, etc.

Looks like there is a need to know an ID of the position in the editor for a view. such "group+column+row".. any API?
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BufferScroll

Postby sublimator on Sun Jan 08, 2012 6:53 am

>>> Looks like there is a need to know an ID of the position in the editor for a view. such "group+column+row"

Yes, good fellow, yes!
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: BufferScroll

Postby Darelp on Tue Jan 24, 2012 3:15 am

Very nice find tito, I've been looking for something similar. Thanks!
Darelp
 
Posts: 1
Joined: Tue Jan 24, 2012 3:14 am

Re: BufferScroll

Postby highend on Tue Jan 24, 2012 4:17 pm

I get a bit of "spam" in the console when I use your plugin (ST 2, v2165 portable):

Code: Select all
app ready
pre session restore time: 0.277987
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 211, in on_deactivated
    callback.__module__, "on_deactivated", EVENT_TIMEOUT)
  File ".\sublime_plugin.py", line 155, in run_timed_function
    ret = f()
  File ".\sublime_plugin.py", line 210, in <lambda>
    run_timed_function(lambda: callback.on_deactivated(v),
  File ".\BufferScroll.py", line 33, in on_deactivated
  File ".\BufferScroll.py", line 77, in save
AttributeError: 'View' object has no attribute 'folded_regions'
wrote startup cache, added files: 2 orphaned files: 3 total files: 127 cache hits: 125
startup time: 0.362697 (package setup was not run)
loaded 941 snippets
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 211, in on_deactivated
    callback.__module__, "on_deactivated", EVENT_TIMEOUT)
  File ".\sublime_plugin.py", line 155, in run_timed_function
    ret = f()
  File ".\sublime_plugin.py", line 210, in <lambda>
    run_timed_function(lambda: callback.on_deactivated(v),
  File ".\BufferScroll.py", line 33, in on_deactivated
  File ".\BufferScroll.py", line 77, in save
AttributeError: 'View' object has no attribute 'folded_regions'


I have several files open but none of them is a duplicate (e.g. via "clone file") of each other.

Regards,
Highend
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 11 guests

cron