PreviousNextTracker indexSee it online !

(32/33) 596 - #501 Auto-save untitled buffers - patch

I created a patch for the feature request: "#501 Auto-save untitled buffers".
Altough the settings "Autosave untitled buffers" exists, but not working like described in the feature request.
My patch extends this feature, when "Autosave untitled buffers" checked (default):
- the untitled buffers will be autosaved when closing jedit, without a question prompt
- the autosave for an untitled buffer saved to <jedit_settings_dir>/autosave, and reloaded after a restart (the state persisted to the perspective.xml)
- closing an untitled buffer by hand removes the autosave file

Tested on windows7 and linux also.
The patch is against revision 24609.
Please review.
Thanks!

Submitted roti - 2017-02-17 17:34:49.113000 Assigned ezust
Priority 5 Labels untitled autosave
Status pending Group
Resolution remind

Comments

2017-03-19 20:53:15.322000
ezust

- **assigned_to**: Alan Ezust
- **Group**: -->

2017-03-27 23:23:31.193000
ezust

- **status**: open --> pending-rejected

2017-03-27 23:23:31.552000
ezust

I tried applying the patch to the svn trunk but it did not apply cleanly for MiscUtilities.java.
Can you please try to freshen the patch to the latest SVN? I like your ideas.

2017-03-31 15:28:16.015000
roti

Please find the updated patch against rev. 24670 attached.

saveUntitled_170331.patch (21.2Kio)

2017-05-05 19:44:21.790000
roti

Hi Alan,

can you review my patch? I could promote jedit with more success by this feature.
By the way, I use the version with this path for months without any issue.

Thanx!

2017-05-05 20:40:07.896000
ezust

I am so sorry for not getting around to this!! I do plan to put it into
jEdit but I've been away from my home development box for a couple of
weeks. I will be home next week and then I am away for 2 more weeks.
I will try extra hard to get it into the svn trunk next week.

thanks again for your contribution!!

On Fri, May 5, 2017 at 3:44 PM, "Hrotkó Gábor" <roti@users.sf.net> wrote:

> Hi Alan,
>
> can you review my patch? I could promote jedit with more success by this
> feature.
> By the way, I use the version with this path for months without any issue.
>
> Thanx!
>
>
> ---
>
> ** [patches:#596] #501 Auto-save untitled buffers - patch**
>
> **Status:** pending-rejected
> **Group:**
> **Labels:** untitled autosave
> **Created:** Fri Feb 17, 2017 05:34 PM UTC by Hrotkó Gábor
> **Last Updated:** Fri Mar 31, 2017 03:28 PM UTC
> **Owner:** Alan Ezust
> **Attachments:**
>
> - [saveUntitled.patch](https://sourceforge.net/p/jedit/
> patches/596/attachment/saveUntitled.patch) (22.0 kB; text/x-patch)
>
>
> I created a patch for the feature request: "#501 Auto-save untitled
> buffers".
> Altough the settings "Autosave untitled buffers" exists, but not working
> like described in the feature request.
> My patch extends this feature, when "Autosave untitled buffers" checked
> (default):
> - the untitled buffers will be autosaved when closing jedit, without a
> question prompt
> - the autosave for an untitled buffer saved to
> <jedit_settings_dir>/autosave, and reloaded after a restart (the state
> persisted to the perspective.xml)
> - closing an untitled buffer by hand removes the autosave file
>
> Tested on windows7 and linux also.
> The patch is against revision 24609.
> Please review.
> Thanks!
>
>
> ---
>
> Sent from sourceforge.net because you indicated interest in <
> https://sourceforge.net/p/jedit/patches/596/>
>
>
>
> To unsubscribe from further messages, please visit <
> https://sourceforge.net/auth/subscriptions/>
>

2017-05-08 13:18:39.791000
ezust

- **status**: pending-rejected --> open

2017-05-08 14:45:19.231000
ezust

Just tried this verison of the patch. it does not apply cleanly either :-(

svn-patch.log (2.0Kio)

2017-05-09 09:57:17.997000
roti

This is against 24674, and I tested it also.

saveUntitled_24674.patch (20.5Kio)

2017-05-09 16:40:53.130000
ezust

That applies cleanly and I am testing it now.

2017-05-09 17:49:12.796000
ezust

Testing it with Editpane Scope Buffersets, there is an inconsistency. It bugs me, so I am hesitant to commit the patch as-is.

If I close the dirty untitled-1 buffer from view#1, the only view that has it open, I am asked if i want to save the untitled buffer.
But if I close view#2 with an untitled-2 buffer that is not open in view#1, it does not ask me to save, and the contents are lost. If later, I create a new untitled-2 buffer, it is empty.

I think the behavior of closing a dirty untitled buffer or closing a view with a dirty untitled buffer should be the same - either it should save it and restore it when you bring the buffer back, or it should ask you to confirm if you want to close without saving.

2017-05-13 21:04:50.995000
roti

I added a simple solution for this:
When you have more than one view opened, and close a view with untitled buffers:
all of it's untitled buffers will be moved to the first or last opened view's active editpane's bufferset.
Works fine, no untitled buffer will be lost. Also for EditPane and View scopes.
I think the help also should be updated with these infos.

saveUntitled_24674_01.patch (21.0Kio)

2017-05-13 21:33:06.493000
ezust

Oh I like your solution very much. Elegant.

2017-05-13 21:39:00.446000
ezust

- **status**: open --> closed-accepted

2017-05-13 21:39:00.766000
ezust

Committed revision 24675.
Thanks for your contribution!

2017-05-31 14:43:06.716000
ezust

Hrotkó,

I just made some changes to where autosave files are saved, and I broke and then fixed the restoring of dirty untitled buffers. However, the restoring process is not 100% correct yet - the path of the untitled buffer after restoring it, points to a location in the backup directory when we want it to point to the original path of the untitled buffer. Please update to the latest svn or daily build and test it. I will keep testing and working on it too, but if you notice something you can fix, please let me know.

--Alan

2017-06-01 21:03:55.319000
roti

Are you testing it with a clean new settings dir? I tested with new settings dir, and it works. I think it should work like this, because this feature is not released yet.

2017-06-01 21:13:55.563000
ezust

The problem is the location of new untitled buffers is not being set correctly anymore.
When I create a new untitled buffer, it should create it at the location of the current buffer's directory.

This is caused by your patch, and is a regression of previous behavior.

What I want is for the autosaves of untitled buffers to go in the same place as the backup directory, which is the current directory *OR* the backup directory *if* specified in properties.

When the untitled buffer is restored, it must restore the correct path also.

I will see if I can fix this, but I am also not 100% happy with some of the other changes I see now that I am looking at this patch more closely.

2017-06-03 23:27:24.451000
ezust

- **status**: closed-accepted --> pending-remind

2017-06-06 22:19:29.463000
roti

I think, the untitled buffers should all go into one directory by default, even if we do not set the autosave/backup dir explicitly. For example in this way one can easily find them after a long time, even without using jEdit.
Imagine by the default behaviour, that if one would have many untitled buffers lying around the filesystem.
Attached a small patch to make it work again, it fixes the following problem: when I edited a real file without saving, and have untitled buffers, the close question also listed the untitled buffers.

saveUntitled_24699.patch (562B)

2017-06-06 22:43:00.512000
ezust

The problem is that I want to be able to create a new file in the same directory as the currenly editing file, and my workflow looks like this:
File - New
type stuff
"save as" and I want the FSB to already have the correct location I want.

Since i have the Console plugin also chdir-ing to the location of the currently open buffer, it changes into the wrong directory also.

2017-06-07 14:12:39.336000
ezust

ok I committed that and the change will be in the next daily build.
But we still need to fix the initial path issue.

as for leaving behind autosaves of untitled buffers, the user has 2 options.
1. uncheck autosave untitled buffers
2. set the autosave/backup directory to somewhere else.


2017-06-12 20:20:21.823000
roti

I created a patch, that works exactly as you described:

* if the backup, autosave dir set:
- new untitled buffers will be saved to that location
- newly opened files will be autosaved to that dir, prefixed with their path

* if the backup, autosave dir is NOT set:
- new untitled buffers will be saved to the currently opened buffer's dir
or for the very first start: to jedit's dir
- newly opened files will be autosaved next to the original

Note: The autosave path will be set when a buffer is created/opened.
When we change the backup, autosave path from/to empty value, already opened buffers will preserve the path until jedit closed.

Fixed other problems like:
- press save for an untitled buffer saved without question
- after changing the autosave path, at next start the untitled buffer was not laoded.

Please test.

saveUntitled_24704.patch (9.0Kio)

2017-06-12 20:35:46.833000
ezust

This is *almost* what I meant, so thank you for addressing my issues.

I made a small change to your patch, so that
If backup, autosave dir *is* set:
new untitled buffers should go into the same place as if it is not set - same place as the currently opened buffer.
I don't want that setting to change jEdit's behavior when creating new untitled buffers.

And the final touch is that when an autosave untitled is restored from backup, its path should be restored too. Perhaps you can look into that?

Committing transaction...
Committed revision 24705.

2017-06-13 01:13:57.960000
ezust

Be sure to update to r24713 because I made more changes to the code that you modified previously.

2017-06-13 21:19:45.118000
ezust

It seems something else that has changed since jEdit 5.4 is the creation of a new untitled buffer when projectviewer changes projects (in the case where only project files were opened, and we have close open project files on project change, and also remember open files enabled).
There is a thread on jedit-users now subject: "Project Viewer opens an empty buffer"
I am not yet sure if it is your code or mine.

2017-06-16 07:19:48.471000
roti

I created a patch for "Project Viewer opens an empty buffer".
For some reason, I modified BufferSet.addBufferAt, but it can be reverted, and cured this problem.

For untitled backup: "when an autosave untitled is restored from backup", I need a little clarification. I do not see that any backup is saved for untitled buffers. Should we have backups also for untitled buffers?

And last:
me: if the backup, autosave dir set: new untitled buffers will be saved to that location
you: I don't want that setting to change jEdit's behavior when creating new untitled buffers.

Can we have an option like:
"Save untitled buffer to Autosave directory if Autosave directory is set" default off
with tooltip:
"When this option is checked, and the Autosave directory is set, save the untitled buffer to that directory.
Otherwise, it will be saved to the same place as the currently opened buffer (at the time when the untitled buffer was created)."

just for my sake? :-)

ProjectViewerOpensAnEmptyBuffer.patch (848B)

2017-06-16 11:50:27.540000
ezust

What i meant to say is "when an autosaved untitled is restored from the backup/autosave directory, its previous path should be restored, instead of the path to the autosave/backup location."

If you really want to add a checkbox, I'm still not sure of its title yet. Let's get previous behavior restored properly before we add new options.




2017-06-16 15:43:23.842000
ezust

Why would someone want untitled autosaves to be stored differently from regular autosaves?

Is having separate options for backup vs autosave directories more appropriate?

2017-06-20 21:11:57.932000
roti

I had some misunderstanding of your wording lastly, but now I understand all requirements, and created the patch for that.
The only "big" change is that if no autosave/backup directory specified, the backup dir will be: jedit settings dir + backup, to separate those files.
Please test this patch.

saveUntitled_24718.patch (7.9Kio)

2017-06-21 00:07:52.629000
ezust


I imagine some users will want autosaves/backups in the same directory, and others will not.

The current documentation and the feature requests I am trying to implement are trying to make both kinds of users happy.

If no autosave/backup is specified, it should use the same directory as the original file!

If an autosave/backup is specified, then the files are separate, and we can specify the location.

Why do you want to make things more complicated than that? And why do you want to hard-code the location of the default?

2017-06-21 00:09:05.096000
ezust

It sounds like the option you want is "location of new untitled buffers", regardless of autosave/backup dir.

2017-06-24 14:05:49.347000
ezust

I don't like this patch. You are adding a new field to the perspective when it is not necessary. Just save the correct location of the original UNTITLED buffer in the perspective, and then SEARCH for autosaves checking where getAutosaveDirectory() tells you to go for that buffer.
I don't like untitled buffers being autosaved in a different way from regular autosaves.

2017-06-28 20:51:03.792000
roti

Ok, from your perspective, what is left to be done for this feature to be accepted?

2017-06-28 20:56:43.306000
ezust

I just want to see the correct buffer path saved and restored from the perspective, untitled or not when autosave is used.
I recommend you make a feature request to describe what other thing you want.

2017-06-28 21:02:40.183000
roti

I think, now the code in trunk, restores the correct path. I tested it now.
We can forget my feature request.

2017-06-28 21:30:36.893000
ezust

Trunk does not save the correct location of the untitled buffer to the perspective.
Instead it saves the location of the backup/autosave directory (not necessary since it is already obtained from properties), so the original untitled buffer path is lost.

2017-06-29 21:42:36.762000
roti

I tested your requirement, and the full behavior is only possible with my patch: saveUntitled_24718.patch.
I tried to prepare another patch with less code modifications, but there is a problem: if you change the backup/autosave while creating untitled buffers, you cannot get the right paths back without storing it into the perspective.
Please try to create an untitled buffer, then restart, then change the backup/autosave path, then create another untitled buffer, then restart ...
That is why I created my patch that way.

2017-06-30 00:12:14.158000
ezust

I am testing your patch and so far, it seems to work as I asked as long as I don't look into the perspective file :-)

2017-06-30 13:32:24.257000
ezust

The problem you are trying to solve: allowing for the user to change autosave directories and using the old one for existing buffers, is not a solution that works for non-untitled buffers.
Personally, I don't think it is an important problem to solve - when the autosave happens, it could read the autosave directory again from the properties, and then use the latest location for subsequent autosaves. Then it would work the same way as it does for non-untitled buffers, and after 30 seconds you don't care what the old value was anymore.

2017-07-02 16:18:01.617000
ezust

There are a lot of public functions you've added to jEdit's API just to make it possible to treat untitled buffers differently from regular ones. I personally think many of them can be removed if we store untitled autosaves the same way as regular autosaves.
But for the ones that can not, you pasted the @since from the original function, and that is not correct. They need to have @since jEdit 5.5pre1 in the javadoc comments.

2017-07-02 16:31:46.205000
ezust

The default behavior could be set to have the backup location pre-set to something sensible, such as the jEditSettingsDirectory/backups, but that is just a simple value/1-liner we add to the jedit.props file. Then the default behavior won't leave behind autosaves or backups everywhere.