Sublime Forum

How are sublime windows related, and what exactly happens when you invoke sublime from the command-line?

#1

I’m running sublime on Linux. I typically have several different windows open doing several different tasks. I also typically use more than one compute server (and all share my same home directory and therefore my ~/.config).

When I start sublime (typically with -nw), sometimes it just opens a window with the file I told it to edit (which is typically what I want). Sometimes, it opens that plus copies of different windows that I have open elsewhere. Sometimes, it even opens up copies if windows that I’m working with on different machines. It seems that I more often get copies of windows when I open projects (-p on the command line) as opposed to files, but it never seems to do the same thing twice, so I’m having trouble narrowing down what exactly is going on.

I assume that sharing of my current workspace in ~/.config is somehow to blame, but being that I don’t really know what sublime is doing, I’m not sure how to go about fixing it. I don’t know what usage is supposed to be okay and what isn’t.

Can anyone shed some light on this?

0 Likes

#2

Sublime windows are not separate from each other, there is one instance of ST and the plugins running underneath. Windows do have some properties attached to them of course, so think of them as adding a layer of data and settings that the views in it can use.

What actually happens when you run the command line util depends on what the exact state of Sublime is at that point. I’m no expert on that, but if Sublime is not running it will first recreate the previous session (e.g. open windows from that session). Which may be what you’re experiencing.

0 Likes

#3

Thanks for the insight. I can to some simple experiments that confirm that it’s working as you say. If I quit sublime everywhere on all machines, then opening a file/directory on the command line will add it to the most recently used window. Opening with -nw will open in a new window.

Interestingly, though, when I invoke sublime_text without -nw, the command returns immediately (the window runs in the background). If I invoke sublime_text with -nw, however, the command does not return immediately - it stays running in the current shell. Even more interestingly, if I interrupt or suspend the shell process after the window has spawned, the window continues to work. The window is not owned by that process, but I’m not sure what that process is doing.

I cannot recreate the “windows opening automagically” behavior on demand. I’ve done a bunch of experiments and it doesn’t seem to be happening. If it comes back, I may have further questions. :slight_smile: I turned hot_exit and remember_open_files to false a while ago in an attempt to squelch this behavior. Perhaps I still had an instance of sublime running somewhere that prevented it from taking effect until now - I carefully shut down everything before doing these experiments.

Is it supported to run instances of sublime on two different machines (where the accounts share a home directory) at the same time? It seems to basically work, but perhaps the weird behavior I’ve been seeing is related to that.

0 Likes

#4

Probably not. Sublime stores caches and session data that really can’t be shared across different machines. I don’t know enough to tell you for sure though.

0 Likes

#5

The -w is telling Sublime to wait.

0 Likes

#6

If you run sublime_text --help, you’d see something similar to the below. Experimenting with the different options & their behaviors with file vs directories can lend clarity to how everything works.

Usage: subl [arguments] [files]         edit the given files
   or: subl [arguments] [directories]   open the given directories
   or: subl [arguments] -               edit stdin

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -s or --stay:        Keep the application activated after closing the file
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).

Filenames may be given a :line or :line:column suffix to open at a specific
location.

That is correct, ST runs only a single instance at a time per user (admittedly, I’ve never tried to run two instances with two users to verify the user claim). The specific tab that is opened when using -w, as @OdatNurd mentioned above, suspends the calling process and waits until the tab is closed.

The hot_exit setting does session saving. When enabled, the windows and tabs opened when you ‘hot’ exited were all saved (including unsaved changes) and would then be reopened upon launch regardless of how the application was launched (be it app launcher, cmd line, Sublime Merge, etc). As far as I know: remember_open_files is no longer an option in ST 3.

1 Like