Sublime Forum

Defective OS X anonymous projects - broken layout, search history behaviour

#1

Hi,

I’ve recently upgraded back up to ST3 from (a working) ST2 - and I’ve quickly realised just how annoying the lack of hot exit is on OS X.

There are countless topics on this forum (and the Github issue tracker) that cover issues with broken hot exit (via closing all windows) functionality on OS X - is it possible to ask @wbond and the rest of the Sublime PTY crew as to why this is how it is?

It’s broken, to be fair.

If you’d like, I can go through this forum and find all the hot_exit related issues on this forum?

0 Likes

#2

This is in somewhat related to Unable to save Column Layout in ST3 (my previous topic) but after further investigation, it affects search and other niceties too.

0 Likes

#3


I’ll find more later

0 Likes

#4

I didn’t even look for this one!

0 Likes

#5
0 Likes

#6

Sorry, but is it only me that has this issue?

0 Likes

#7

If it is not already there, can you open a issue for your problem on the Community Issue tracker https://github.com/SublimeTextIssues/Core/issues? It is easier to track bugs and features over there than using the forum.

0 Likes

#8

I use macOS in a daily basis, and I can’t say it is obvious to me that hot_exit is broken. Creating an issue on the issue tracker with a clear description of how you understand it should work and the issues you are seeing will be the best way to move towards a possible solution.

1 Like

#9

I created a ticket on the community GitHub back way back in September 2017 (#1907) - it didn’t refer to “hot_exit” as the first issue I had encountered was mainly the tab issue - I basically refused to look into ST3 any further at that time as that was to me, a show-stopper.

It’s only when I am beginning to look into using ST3 again (due to me wanting to develop on Windows) that I am seeing more of these issues on macOS

With regards to the two column layout issue, I have found a plugin that will automatically create two columns for me whenever you start your editor.

I tried to find/create a plugin that will load the last loaded project/workspace, but I wasn’t able to do either options.

I have created a video that will replicate this, and I will upload it once I fix my nginx installation :frowning:

0 Likes

#10

Now I have my WebDav proxy working, below is a video of how to replicate this.

This has been cross-posted to GItHub as well, for further reference.

1 Like

#11

Thanks for the video. It is very clean what the problem is.

Alternatively, can you check whether it works correctly if you go to the menu File -> Exit, instead of clicking on the Red X button?

1 Like

#12

I can confirm that cmd+Q, exit via the dock, and exit via Sublime Text > Quit Sublime Text work as expected.

I can confirm also that cmd+W will close the anonymous project (and lead to this issue), similar to pressing the red X button.

1 Like

#13

It looks like you’re conflating hot_exit (which remembers the state of open windows on quit and restart) with closing the window – they’re not the same thing.

MacOS has the peculiarity that apps remain running even when you close the last window. In that state clicking on the dock icon creates a new window, making it look like you restarted the app, when in fact it was already running. This is denoted in your video by the white dot under the icon; note that when you quit the app fully, the dot vanishes, but closing the window, it remains.

When you actually quit Sublime (via the dock or by using File > Exit or the key binding, etc), you’re actually quitting Sublime, which terminates the app and gets it to persist it’s state in the session file.

On the other hand, when you click the red X, you’re closing a window.

If you quit Sublime, it persists it’s state in the session via hot_exit, which in the case of no windows persists the fact that there are no windows. Then the next time you start the app, it restores the state back to no windows.

If you use a project in your window, the state of the project is saved in it’s workspace file and can be recovered. Anonymous windows don’t do that, presumably because if Sublime persisted every anonymous window you closed, it would quickly become unweildy which one you meant to re-open (i.e. the list would be unbounded).

3 Likes

#14

Then how come ST2 had the same behaviour that you had referred to as “unwieldy”?

1 Like

#15

Indeed Sublime 2 remembers the last window layout in a way that Sublime 3 doesn’t. I believe it also stores the state of find operations as well. I don’t know why the layout save change was made, but storing find state differently was an explicit change in build 3143 (Sublime 3.0):

https://www.sublimetext.com/3:

  • New windows start with an empty find history

If I recall correctly, that was not a popular decision at the time or through the dev series that led up to the release.

In any case, neither of those is the same as what hot_exit purports to do:

    // Exiting the application with hot_exit enabled will cause it to close
    // immediately without prompting. Unsaved modifications and open files will
    // be preserved and restored when next starting.
    //
    // Closing a window with an associated project will also close the window
    // without prompting, preserving unsaved changes in the workspace file
    // alongside the project.
    "hot_exit": true,

Regardless of the platform you’re on, closing a window with unsaved files in it that does not have a project attached causes you to be prompted to save unsaved changes (as in both of your videos) and then closes the window without saving any state, regardless of the setting of hot_exit.

In reference to hot_exit and your problem, the implication would be (to me) that the hot_exit setting should save the state of every window when you close it (i.e. not just project windows) so that when you create a new window, it gets restored (because that’s what hot_exit does).

In such a case, unless it only ever saved the last window you closed, the list of saved windows would grow ever larger over time and require you select the one you want to re-open from a growing list.

However you probably don’t want to have only X last windows saved, because as soon as you commit to X, someone will come along that uses X + 1 windows every day and will be unhappy that one of their windows is not persisted.

Walls of rambling text aside, based on the description of what the hot_exit is supposed to do, it seems to be doing what it says it does; it saves projects when you close their window and the overall state when you quit the application. It doesn’t say that it remembers and restores the state of anonymous windows.

it sounds like what you actually want is a way to do that, or perhaps some sort of template that is used to set up a new window when one is created (layout, find settings, etc)?

To some degree that’s possible via a plugin, though on MacOS clicking on the dock icon when there’s no window doesn’t trigger an event that a plugin can respond to, so some trickery would be involved.

3 Likes

#16

Yes, a reversion to the behaviour that is in ST2.

I attempted to create a plugin to automatically load a project but I’m somewhat lost - firstly, I can’t seem to get open_recent_project to work, and additionally I see an issue where if a project has no tabs assigned to it, it’s automatically closed - but I suspect this could be resolved in a plugin somewhere, if done properly

1 Like

#17

At some point in the past I wrote a quick plugin for someone on Stack Overflow that would set the window layout to two columns in new windows, but I can’t seem to find it at the moment. That’s where I realized that clicking the dock icon creates a window without triggering anything a plugin can use to detect that it’s happening.

At the time I had the thought that you could poll to see if the list of windows changed, but that seemed potentially resource intensive.

sublime-project files are just JSON files, so you could keep a record yourself of what you want your default project to be, and then have your plugin create a new window and use window.set_project_data() on the new window to apply things in.

That said, that would only do things like set up default settings and folders. To set the window layout as well would be a separate step. That’s included in the sublime-workspace file instead. It contains the layout information, so you’d have to set that separately.

0 Likes

#18

@OdatNurd - https://github.com/pykong/TwoColumns is the plugin I’m currently using for this. It’s similar in concept to what you have written in the past, by the sounds of it.

The set_project_data would work if there was say… a way to retrieve project data?

1 Like

#19

I think you were looking for this: :slight_smile:

2 Likes

#20

There is, but it’s named project_data() instead. I often fall victim to thinking that get should be paired with set, but for whatever reason that’s not always the case. For example view.get_regions() gets named sets of regions from a file, but view.add_regions() is what puts them in place.

>>> window.project_data()
{'folders': [{'path': '.', 'file_exclude_patterns': ['OverrideAudit.sublime-project']}], 'settings': {}}

That said, the data that this gets mimics what you see in the sublime-project file (changing the project data via the API will update the sublime-project file on disk, for example), and that information doesn’t contain things like the window layout.

The layout is in the associated sublime-workspace file of the project. That’s also JSON and has a top level key of layout that specifies the splits of things in the windows. For an existing project you can capture the data that way. My SO answer that @kingkeith linked above shows one way to apply that to a window.

For windows that don’t have projects attached to them (or if they do but you don’t want to fiddle with loading JSON data) you can use window.get_layout() to obtain the layout information of a given window and window.set_layout() to apply it to a window. (Note that there is in fact a window.get_layout(), but it’s deprecated in favor of window.layout()).

2 Likes