Most of my day is spent editing code. I don't use just one editor, though. While Kate is my favorite, some editing tasks are faster in vim, some in Netbeans. It depends a little on what I'm doing. And in the course of the day changes to files come in through source-repository updates (hg pull in my case). For files that I work on for a while it means it's likely that they change while they are still open in some editor or another.


Netbeans auto-reloads changed files, silently. vim asks about it -- but I don't tend to leave vim open for long, it's for specialized editing needs. Kate pops up a confirmation dialog saying the file is changed on disk and asking what to do about it.

So far so good.

Two activities in my daily routine trigger a lot of reloading: updating my checkout after lunch to catch up with what others have done, and popping and pushing patches as I navigate source history to improve individual patches or search for a bug. Especially when looking for a bug, I'll have five or six source files open in Kate, run a test, switch to another revision, run a test, then want to see the files in that revision.

Kate has (or had) a useful menu item File -> Reload all. It comes with a DBus binding, so I have even  made a shell alias that does hg up ; qdbus `qdbus org.kde.kate-*` /kate/__KateMainWindow_1/actions/file_reload_all trigger. This makes it easy to sync the loaded files in Kate with what's on disk as I flip through revisions.

I had not realised how much I used this particular workflow (under OpenSUSE 11.4 with whatever KDE was default there) until I updated to OpenSUSE 12.1 and it broke.

There's lots to like in the newest Kate (line modification markers foremost!), but all of a suddent "Reload All" means "Reload all the files, asking about each one in turn" instead of "Reload all the files and damn the torpedoes." This had been annoying me for a while now, and I finally decided to scratch that itch.

The Kate site has good, straightforward Join Us information, and the quick HOWTO did what it said on the box for me: got me a newly built-from-source Kate to replace the one already installed. I hacked the run.sh script a little so I could hard-link it to an executable's name and it would run properly, so now I have a ~/kde/bin/kate that starts newer-Kate.

What I like about the quick HOWTO is that it focuses on just the one purpose: building Kate. Dot this, do that. Thanks to the instructions with specifics for different distro's, it took maybe ten minutes total to get a new Kate built. Figuring out how to make subsequent changes is left as an exercise for the reader. No excursions about git configuration, which I still think is one of the most pointlessly obtuse version control systems around. 

Now, about the "exercise for the reader", which was modifying the Kate code: it took me longer than I expected. My C++ has been idle for about six months as I've been living in Python-land (with wx widgets). So there were plenty of missing semicolons and "no, #include doesn't go in the middle of a function where you need an external symbol". Static typing, right. I ended up with a three-line addition  to the reloadAll() method to mark files as unmodified (thus bypassing the dialog prompt) before reloading them. Looking at the code I see that the same signals are emitted as when you would individually select "Reload" in each dialog, so that's what I wanted. The code ends up looking like this:

void KateDocManager::reloadAll()
{
 foreach ( KTextEditor::Document *doc, m_docList )
 {
   KTextEditor::ModificationInterface *d = qobject_cast(doc);
   if (d)
     d->setModifiedOnDisk(KTextEditor::ModificationInterface::OnDiskUnmodified);
   doc->documentReload();
 }
}
I'm not entirely happy with this code, since it just wipes out the modification state of the file before reloading. If anything more complicated needs to happen before reloading a modified file, then that's not going to happen. I would much rather suppress the dialog in documentReload() instead. There's even a method ModificationInterface::setModifiedOnDiskWarning() that can be used to suppress the dialog, but there's no accessor for the previous setting, so I can't switch the dialog off briefly and then restore the value.

Anyway, now Kate is better for me, and I'd like to say thanks to the Kate folk like Dominik for making a great editor and good instructions for getting started.