Sublime Forum

Subl --Project, Closing ST3 and Shutdown

#1

At first I thought subl --Project wasn’t working. Here’s an example from my linux start up file:

wmctrl -s 0
sleep 2s
subl --project /home/username/.config/sublime-text-3/Packages/User/BuildsNSnippets.sublime-project &
sleep 4s

All that would happen is that it would open a new BuildsNSnippets.sublime-project in workspace 0.
I’ve found out this this is because when ST3 loads up; it opens BuildsNSnippets automatically because that’s what was open at the time of shutdown. Subl is creating a new project because it’s already open. The cure is to shut that particular project before shutting down.
So before getting into this:


which looks a bit mareish…
Is there any kind of setting I can change in ST3, so when it closes down it automatically shuts a particular project, so on startup subl will then open the project I want in the right workspace.
At the moment I have five workspaces (on the same machine) and across those, five ST3 projects open which I can chop and change with a key press.

( Current project, source files and headers, next to that gitsavvy and git stuff, then a couple of open terminals, firefox, and then BuildsNSnippets which has got all kind of stuff in it )

It’d be good to have everything in the right place on start up and not have to close down ST3 specifically at the end of each session. I turn my computer off at the end of the day.

In summary, is there an automatic close and save project/file setting on shutdown for ST3 please ?

Ta, that was very long winded for what is probably a simple problem, so thanks for getting to the end of this !

ATB Lozminda

0 Likes

Ctrl+q Has Erased all my Projects
#2

You can turn off hot exit to achieve this.

0 Likes

#3

Thanks for your responce.

Will I then loose anything that isn’t saved ? Does that mean I have to tick a save all on exit button or something similar ?

Cheers

0 Likes

#4

You will not loose unsafed changes. sublime text asks to save changes on exit.

0 Likes

#5

Thank you, will give it a go now!

0 Likes

#6

Sorry, turned hot exit off, hasn’t worked in a way I was expecting. It has kept unsaved stuff, so that’s good. But it hasn’t stopped the conflict between instances of BuildsNSnippets projects. My guess is: information concerning ST3’s shutdown isn’t reaching ST3 before it’s shutdown. When I shut ST down, it works as expected, when my system shuts ST down it doesn’t. What I’m trying to avoid is having to close all my project windows every time I shutdown, if possible.

And what I didn’t realise (when I’ve done ctrl+q before St3 closes, and then when you re-open everything was back as before) now I did crtl+q, perhaps not concentrating as I should and I’ve lost everything

My advice to the unitiated, if changing the hot exit setting be very careful what you do. All my projects are now empty…UGGG

AND TREBLE JEFFING UGGG

I have to reset the lot again, hours and hours of work lost

0 Likes

#7

how do you shutdown ST? It is working when i use Super+q in gnome. I don’t know how it works, but it is probably using pkill

0 Likes

#8

Is only paritially true, with hot_exit set to false, you’ll loose all your project structure (the directories will be there) but any open files will be closed. Some times I have twenty files open in one project, so loosing that info was/and still is being sorted…

0 Likes

#9

It sounds misleading when you say you'll lose all your project structure. The project is either the contents of the sublime-project file that describes your project, or the actual physical contents of your folders on disk, and neither of those gets lost when you turn off hot_exit (unless it asks you to save unsaved changes and you say no and later regret the decision).

What’s actually lost is the session information on what files you had open, where you were in them, and other information to allow Sublime to restore the window back to the state it was in when you closed it.

Just adding that in here for clarification for future readers.

0 Likes

#10

This is what I’ve got so far (for any that this may be useful for) if you have multiple linux workspaces open with different subime projects in them

My start up script:


sleep 2s
wmctrl -n 6
sleep 5s

wmctrl -s 1
mate-terminal --working-directory="/SOME_DIRECTORY_STRUCTURE" --maximize &
sleep 3s

#wmctrl -s 0
## mate-terminal --working-directory="" --maximize
#subl &
## /home/elitebook/sublime_text_3/sublime_text &
#sleep 3s

wmctrl -s 4
mate-terminal --working-directory="/SOME_DIRECTORY_STRUCTURE/fileHelp Test Zone" --maximize &
sleep 3s

wmctrl -s 5
firefox &
sleep 9s

# ********************* Loading Specific ST3 Projects ************************************
wmctrl -s 0
sleep 2s
# mate-terminal --working-directory="/home/elitebook/Desktop/Big Mandlebrot/Final Project/fileHelp Test Zone"
subl --project /home/SOME_DIRECTORY_STRUCTURE/Project_1.sublime-project --command toggle_full_screen &
sleep 5s

wmctrl -s 2
sleep 2s
subl --project /SOME_DIRECTORY_STRUCTURE/Project_2.sublime-project"\
 --command toggle_full_screen &
sleep 5s

wmctrl -s 3
sleep 2s
subl --project /SOME_DIRECTORY_STRUCTURE/Project_3.sublime-project"\
 --command toggle_full_screen &
sleep 5s

This opens Projects_1 to 3 in workspaces 0 2&3 (there are six in total). The sleep statements are important and will no doubt vary on the performance of one’s machine.
Also beware “” placements ! It also opens an extra instance of ST3 at workspace 0 and this seems to be unavoidable due to how subl works. No matter what command you do (except for exit) subl creates an instance of itself (I managed to get this down to 1 extra one so far)

The finish script I’ve got to get into system.d (and the shutting down protocol) which I haven’t done yet, but just running the script (in a manual simulation of the shutting down process) seems to lead to success (mostly):


sleep 2s
wmctrl -s 0
subl --command close_workspace &
sleep 2s

wmctrl -s 2
subl --command close_workspace &
sleep 2s

wmctrl -s 3
subl --command close_workspace &
sleep 4s

subl --command exit &

I’ve posted this link before about sytem.d and rc[0…6]

Now there’s more to be said, but I’ve run out of time today…(for example: If I change my set up in my session, open new projects and what not, automating the start_file generation rather than having to do it manually !)

:unicorn: :skull_and_crossbones:

0 Likes

#11

I don’t think that Sublime Text is the best place to do this. Instead of looking for a solution that only works for one particular software I’d rather have my windows manager do it for me. So pick up a decent tiling windows manager you like or look for one of the many window session manager available on the net.

You could also look into hibernation, which stores the work session on a dedicated area.

Whichever way you decide to go, storing hours of work in a session is typically not a good idea. They do corrupt once in a while, at least by my standards.

0 Likes

#12

Thanks for the info. Had a quick look at i3. The reason I use workspaces (which is a built in Linux feature) is basically because I don’t have a large monitor, so with having 6 workspaces that means I can cram a lot of infomation on just one machine (and despite it being at least 10 years old) it’s quite happy with 5 or 6 ST3 projects open, firefox, gdb, etc. etc. (And I can switch with a keypress.)

The reason I’m having to do it this way is the result of the vagueries of ST3, when it loads up it loads everything in the same workspace (which I think I’ve detailed before) (I haven’t tried firefox, but then I use it for different things).
Until I dropped the ball with the hot_exit debarcle, ST3 had kept all my open files, just as I wanted them for a year. If there’s an easier way, I’d love to know, but all I need to do now is incorp my shut down script into the shutdown process and voila problem solved, no new software required.

When I get a bigger monitor (ie when someone throws something away I can repair) I’ll check out the tiling system (It’ll still have to deal with how ST3 closes it’self no ?)

I freely accept I’m probably missing something about your suggestion, I only had a nose for about 30 min, so If you have a more detailed solution I’m all ears. Thanks very much.

Cheers :beers:

Ps I don’t know if it’s still true but Hibernation doesn’t come shipped with Linux Mint and for a while it was a hot topic (weirdly) although this seems to be changing…

PPs I’m one those weirdo’s that turns electrical equipment off (via the shutdown software) (at the socket eventually). I know weird.

A final PPPs The information that I lost was not what I was working on (exactly). An analgy would be imagine sitting at a table, and you’ve got loads of books open (books !!) which you’re using to do some research. Maybe some notes, and each set of notes is next to the open book it pertains to. Then someone comes along and thinks this is a mess, closes all the books and stacks all the papers together neatly in one pile (and hey stacks the books too). All the information is still there (but you have lost something, in fact things have become more ordered, therefore you’ve lost information). It’s not the end of the world, but it is a pain !

Just to be clear, because someone will no doubt dive in at this point to defend the honour of ST3 (:stuck_out_tongue_winking_eye:) it wasn’t ST3’s fault at all, I was a muppet. One shouldn’t believe everything you read ! (at least check first) (which to really hammer the point home) which I should have done.

Phew, and thanks!

0 Likes

#13

Sublime Text 4 can optionally restore windows to their previous workspace.

1 Like

#14

ST4 also remembers undo / redo buffers after closing a project. (although i’m not up to date what ST4 can do). This is probably also coming in handy for you.

0 Likes

#15

After using 2 monitors for many years i switched back to a single monitor setup. It feels more productive now, less mouse travel. Still have that monitor ready to be switched on if needed.

at the end of the day ST3 is a GUI application just like any other. So launching / quitting, safing / restoring windows positioning is a job for your window manager. It really doesn’t matter what ST is doing: as long as it has an application window it can be placed on a desktop.

Hibernation may or may not be shipped with your Linux distribution but you should still be able to activate it. There are many reasons why this is not an option for you due to some limitations.
Hibernation allows you to completely shut down your machine and pull the plug, while restoring your session when you restart.

0 Likes

#16

Thanks for all your comments.
Had I only read your comment a few hours ago, hibernation seems “just the ticket”, however I’ve solved “my problem” in a totally different way (for anyone who’s interested):

Rather than go the way of system.d or systemctl or any or that madness (which I couldn’t get to work) I just created a custom launcher in my top panel that runs my shutdown script plus

mate-session-save --shutdown-dialog

(which is the command the shut down laucher runs) hence getting rid of all my timing issues (shutdown was happening before i could execute any of the subl commands). Gosh took me 10mins (and a few hours of reasearch in the wrong area first). Face Palm.

I still get a random instance of ST3 opening and Hibernation it turns out is probably the way to go, but it’s kept me out of mischief for a day.

In order for this to be useful, I’ll now have to use Sublime for about 300 - 400 days before it actually saves me anytime. Only myself to blame :stuck_out_tongue_closed_eyes: :crazy_face: :upside_down_face:

For the non drinkers :doughnut: :mushroom: :pizza: :coffee: (as I often end my posts with beers)

Lozminda :unicorn: :skull_and_crossbones:

0 Likes

#17

I’ve had a quick look at Hibernation, and it indeed does look good. However it doesn’t work on my machine.
At first I though it was conflciting with my start up script, but having disabled that all that happens when I turn on my machine it boots up to a completely different state (I have the desktop open and nothing else)
I sorted out the swap a few months back, Swap is the same size as RAM at the mo.

Reasons for failure (as I see it) could be:

  • The current hibernation software doesn’t work. It’s was a recommendation on installing Linux MATE that you disable hibernation (though that may have changed).

  • The CMOS battery (i think) is jeffed, so the booting process is a little weird and maybe that’s interfering. (My lap top boots fine but after some extra processes. It’s currently not worth the day it’ll take me to sort it out (at least, coz a lot of my tools are reclaimed too !)

  • Other reasons I can’t currently think of.

I guess this is what happens when you take other folks junk and raise it from the dead ! (“It lives, it lives. It’s alive I tell you, ALIVE !”)

One for the kids there. :microbe: :sauropod:

I suppose the easiest option i try some better hibernation software, but any thoughts gratefully received

ATB :unicorn: :skull_and_crossbones:

0 Likes

#18

you can rule out the battery.

My suggestions were merely meant to point you in the right direction. These are not proven solutions, non of which guarantees for a painless user experience.

This discussion is no longer related to ST, you’ll get better support somewhere else.

Please mention: distro and version, other distros (dual boot), file system(s) and

swap:

swapon --show
0 Likes

#19

My reply was only to show I was “paying attention” and that your comments “weren’t in vain” (I can’t think of a better way to put it, haven’t had breakfast yet). Otherwise I agree, thank you !

1 Like