Using Named Sessions

This article was originally published as a blog entry at http://alweb.dk/blog/anders/kate_named_sessions and is now donated to this website.

The biggest change in Kate (http://kate.kde.org, http://www.kate-editor.org) in the KDE 3.5 series is definitely the introduction of named sessions. Instead of defaulting to one instance, Kate now as a standard allows you to run many instances. Session ChooserAnd not even that, it will allow you to keep those sessions, with the list of open files as well as the instance specific GUI configuration. This is a big change in behavior, but once you get used to it, you will hopefully appreciate the benefits.

If not, it is still possible to restore the old-style kate behavior by utilizing the various related commandline and configuration options. You will of course loose at least some of the advantages of named settings, but if you desire keeping things as they were, you probably do not care a lot.

Because this is new, there are of course problems and unforeseen issues. Due to busyness with real life, I have not had a chance to get much into named sessions prior to the KDE 3.5/Kate 2.5 release, but I have been working hard on enhancing the named sessions experience for KDE 3.5.1/Kate 2.5.1 and upwards.

Read on for more about how it works, what have been fixed so far and some ideas for future improvements.

Kate Session Basics

Basically, a Kate session is a instance of the application with its own set of open documents and its own window setup (toolbars, toolviews, editor frame[s]). The session can be named and saved with the file list and optional the window setup, so that it can easily be restored again.

If you edit a lot of text files for different purposes, such sessions can make your life much easier. I for example have sessions for various websites I maintain and for my various KDE related projects. When I want to work on a project, I open the session and have the setup as I left it last time I used it. For one thing, the named sessions feature will obsolete the filelist loader plug-in that some of you may have used.

You can create a new session in many ways:

  • Use the Sessions->Save As menu item to save the current session under a new name
  • Use the Sessions->Save menu item to save an anonymous session.
  • Start kate with --start <New session name>. If the session with the specified name does not exist, it is created.
  • Use the Kate Session Menu kicker applet made available by yours sincerely (http://alweb.dk/projects/kate_session_menu)

There are equally easy ways to open a session once you have some:

  • The default behavior for Kate is to ask which session you want to open if you don’t specify one on the command line. But you can change that to always start a new (anonymous) session, or to allways load the last used session.
  • You can specify a session on the command line. (if you want desktop icons, you can create a kate icon with kate --start YourSession in the exec property)
  • You can use the Sessions->Quick Open menu item to load it into your Kate instance (the current session will be closed, and you will optionally be asked if you want to save it if it is named and has changes).
  • You can use the Kate Session Menu kicker applet (see above)

If I want to open one or more files and forget about them again, I can just open then in an anonymous session which will not be saved.

If I want to add files to a running session from outside, I can use command line options to do so. In Kate 2.5 that means any running instance (—use) or an instance selected by its process ID (PID) (—use —pid PID).

Kate saves your sessions pr. default, but you can have it ask you or not save sessions if that suits your work flow better (I’m personally happy with this default, although i sometimes forgets to close some files that I’m done with).

Session related command line options

As indicated above, Kate has tree new command line options to support named sessions:

-s, --start <name>
Start Kate with a given session. From Kate 2.5.1 (KDE 3.5.1) this will also work with --use so that when both is specified only the specified session will be reused, if it is not running it will be started or created.
-u, --use
Use a already running kate instance (if possible). If no instance is specified using --pid <PID> (or, in the future, --start >name<) the first instance found by DCOP (the one with the lowest PID) will be used.
-p, --pid <pid>
Only try to reuse kate instance with this pid

Session Configuration Options

Sessions have gotten their own panel in Kate’s configuration dialog, with so far tree options allowing you to tweak the behavior.

Elements of Sessions
This is really a promise, since a group box with one option is an indication that more will follow ;). Include window configuration is enabled pr default. When enabled, the entire configuration of the application window is saved with your session, including toolbar setup, toolviews, and the editor area.
Behavior on Application Startup
contains tree options, namely
  • Start new session
  • Start last used session
  • Manually choose a session (default)
Choose the one that suits your work flow best. For me that is the first one (start a new session) since I tend to start the session I want by using my kicker applet, and when I want to dig into something and open one or more source file I prefer Kate — with a new session — for the syntax highlight and the ability to open more files. I can then save the session for later use if I find those files very interesting…
Behavior on Application Exit or Session Switch
This again contains tree options, namely save (default), not save or ask.

Restoring the Old Style Kate Behavior

Many users have grown accustomed to the old style behavior, where Kate would run only one instance and all files would be forwarded to that instance. We know from the bugs database (http://bugs.kde.org) and mailling list (http://lists.kde.org/?l=kwrite-devel) that many users got a bit confused when kate didn’t behave as usual, and given the lack of warning and documentation of the new behavior that is not suprising.

To restore the old style behavior, you can follow this strategy:

  • Configure Kate to load the last used session on startup and save sessions on exit, and enable the window configuration session element.
  • in the KDE menu editor, edit the exec line of kate to to kate --use %U
  • Use an alias in your shell to add --use automatically. If you use bash as your shell, add something like alias kate="kate --use" to your ~/.bashrc file.

Be warned though that until KDE 3.5.1 is released (soon!) you will experience some problems with this: when opening files from the KDE environment with --use, you get a KIO error about not being able to launch kate. As indicated, this has been fixed in the 3.5 branch of KDE and if you compile KDE yourself, get this version of the kdebase module to fix those problems.

Improvements and Fixes in Kate 2.5.1

I have tried to do a few improvements in Kate 2.5.1 because there is quite some time until we get to KDE 4. Most are really bug fixes, although mostly for unreported issues. Many but not all are related to named sessions.

Improvements include

  • Kate will show the name of a named session in the window title.
  • --start <name> will work with --use.
  • when a session is specified using the application startup behavior option, it will allways be loaded, no matter if there are files on the command line.
  • The error about kdeinit not being able to launch kate is history.
  • Kate can now handle temporary files correctly, so the warning about the file being deleted when using kate to view Konqueror sources has gone.

Future Development with Named Sessions

A very obvious step is to include more configurations in the session data. This could include

  • Plug-in configuration
  • Filesystem browser configuration and history
  • Recent files

In Kate 2.5.1 the pid is exported to the environment variable KATE_PID so that you can alias kate with kate -up $KATE_PID if that is set, in Kate 2.5.2 this will not be nessecary anymore, Kate will automatically select the current instance if the KATE_PID variable is set.

One thing that has lead to quite a few complaints is the removal of the project support in Kate. This came as a suprise to us developers, as we all found the project support very poor, but it appears that it has been used and appreciated by quite a few users. Adding project support on the top of named sessions would be good, and I am considering how it can be done in a nice and flexible way. My own demands are that any file can be a member of a project, and I would like to see some sort of project type that would support various commands such as building software, synchronizing directories etc.

Comments

Still not clear how sessions work

Sorry, maybe I am too stupid, but I still haven’t understood how sessions work. I have heard that they are very useful and I thought, I can save my text files related to project A, B, C… separately. In fact, all files are mixed up and most are empty after a certain period of time. Sometimes I create a new session and later I found out that I have overwritten an existing text (the window was empty but once there have been text).

All the desciption is too technical and I still don’t know how it works and how to use it. Sorry, but as most features in KDE: Sounds nice, but not usable.

Kate is a goddess!

Thanks for this awesome feature, which is now indispensable; I can’t imagine using any other editor unless it had this facility. I’d been using Debian Sarge with an older version of Kate for much too long past its sell-by date and was looking forward to using the new Kate 2.5.5 once I upgraded. I am seriously impressed and it does everything I could wish for :-) I now have 5+ instances of Kate loading up automatically at boot time with my most important sessions, and others are easily loadable when needed.

Cheers, Malcolm Smith

How to remove saved session

Hello I didn’t find how to remove saved session from session list?

site

Your drupal site is nice but I can’t get to the 2nd page of articles. It just gives me a blank page. With Developers nd HOWTO’s Hardly worth signing up to the bugs list. Hal

Reusing Windows

The whole idea of sessions is just great, but I personally found it poorly implemented. Why the sessions aren’t update automatically, just when I save them ? We could at least have a way to NOT open a new window everytime I call kate from the command line and ask it to use an existing session. It’d be the best of both worlds, the old one, where I could simply call kate lots of times and it’d just keep adding documents to the open kate window, and the new one, where I could have this behaviour done on a session basis.

Kate Project was very different from session !!!

Doesn’t matter if only few people use kate’s projects… It was very very stupid to remove that feature !! Because now, there is no alternative for people like me that use kate’s projects… becuase Session are completly different !! There’s no common points !! I’m starting using Kate only because kate’s project feature !!! Because it was so simple and efficient !! If somethings is poor doesn’t imply that is useless !!

good article

thanks, it was very useful for me!

Are all my kateproject files useless???

I have been using kate to edit my R scripts for statistical analysis of many research projects. For each separate experiment I could add the data files and several separate scripts together as a .kateproject. I had just become quite efficient getting things done in this manner. Was all of this for nothing? Do I have to now create a named session for each one of these projects? and open them up by name at the command line???

I really hope this functionality can be restored. Until then I will have to once again search for a good R script editor…

This is all very well...

…but I liked restricting kate to a single session. For one thing, it meant that I could bring up the instance of Kate I was using with its appropriate KDE keyboard shortcut (such as CTRL+ALT+K), rather than Alt-tabbing my way through a program list. For another, it meant I could type

$ find . -type f | grep [pattern] | xargs kate

into a console to open every file matching that pattern in an existing Kate session. Wonderful little tool, but since I upgraded Kubuntu to Dapper yesterday, apparently it’s no longer useful.

Post new comment

  • You can use Markdown syntax to format and style the text.
  • You may link to images on this site using a special syntax
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.