Updated: November 21, 2018
Here's a scenario for you. As a Linux person, you happen to be using the Plasma desktop environment, and your text editor of choice is Kate. You have multiple files open, i.e. multiple document tabs, and you want to preserve them for your next session. In the Kate settings, you did find the option that allows you to save the session, which you've promptly marked. However, on next app start, you only get a single, blank document.
This turned out to be a problem that I had to face after I configured Kubuntu on my new Slimbook Pro2 machine. The quest for answers soon turned into a neat and non-trivial tutorial that you're reading right now. So let's have it. I'll show you now how to make Kate remember and preserve your work sessions.
We need to go under the hood
This is most likely a bug, but the reason why Kate isn't doing its job is because it does not have a session associated with the save state, hence nothing gets saved. Until this is fixed the official way, the solution is to change how Kate runs. This is done via the org.kde.kate.desktop file under /usr/share/applications.
Now, you may think, what? Well, in the Plasma desktop, applications have their own shortcuts. In Windows, you'd expect to find them on the desktop. Here, they lurk under /usr/share/applications. I have already shown you how to use and manipulate these files when we set up WINE shortcuts in the icons-only task manager in Plasma as well as configured multiple versions of the same app in the same manner.
So, open the Kate desktop file in a text editor (ironic, isn't it). Look for the Exec= line. This is the line that governs under which parameters and flags the program will run. It will read something like:
...
MimeType=text/plain;
Exec=kate -b %U
StartupNotify=true
X-KDE-HasTempFileOption=true
...
We need to change this to include a save-session option (-s flag). Something like:
Exec=kate -b -s Dedoimedo %U
But do note that you actually have to have the Dedoimedo session file exist in the first place, created manually, or it may not actually get created, contrary to the documentation, hence no saved session, hence the bug. Instead, you can use the pre-existing Default session, which will work:
Exec=kate -b -s Default %U
Close Kate, start it again. Open a few documents. Close the program. On next start, you will actually see that your tabs with open documents will have been preserved. Which then brings us to the end of this little guide.
More reading
Some other cool Plasma stuff, if you're interested ...
Some cool Plasma tips and tricks
Plasma secrets: task manager tweaks
Plasma secrets: Custom app launchers - WINE, too
Plasma icons-only task manager: Multiple app versions
Plasma secrets: Remove shadows in screenshots
Plasma is sluggish? Disable desktop effects.
Make Plasma remember window position
Conclusion
Another Plasma secret unveiled. I am always amazed by how much new stuff one can learn and discover, even when they have been using the desktop environment for a long time. I guess it comes down to necessity, and inherent problems in the implementation. Technically, ideally, it would be best if there were no tips. That's a sign of a perfect design.
Plasma is wading deeply into the pro arena, but there are still things that need to be improved, polished, tweaked, including a whole bunch of small, seemingly invisible usability bugs like the Kate save session one. Anyway, I hope you appreciate the intense diligence with which I tackle Linux problems, so that you don't have to. Not asking for much, just a nice marble bust in a town square somewhere. Take care.
Cheers.