Needless to say that it also supports undo/redo and pasting text. Kudos go to Andrey Matveyakin for implementing it!
Needless to say that it also supports undo/redo and pasting text. Kudos go to Andrey Matveyakin for implementing it!
Another release cycle gone, and the KDE Software Compilation 4.11 is out in the open (well, for quite some time already), and with that it is time to talk about what changed in Kate the last half year since the 4.10 release. Besides the usual bug fixing (~50 bugs since 4.10), the following sections present some major improvements and features of Kate in 4.11.
Since KDE 4.10, Kate features the Python »Pâté« plugin. This plugin basically wraps the API of all Kate application interfaces. Therewith, together with the Python KDE (PyKDE) bindings you can develop full-featured Kate plugins in Python. Being relatively new, there are quite some Python plugins available already now (see this blog, this blog, or this blog).
@Python community: You can interpret this as an invitation for writing lots of cool addons for the Kate text editor in python. All contributions are usually very much welcome!
Enabling the vi input mode turns Kate into a full-fleged vim compatible editor: modal editing exactly like in vim. This mode is especially suited for vim users who want a fully KDE integrated text editor with all the beloved vim features. Started as GSoC project in 2010, the vi input mode evolved over the years to become a very mature alternative to vim itself. However, there is always room for improvements. The good news is, that Kate Part’s vi input mode gained a lot of attention thanks to Simon, mostly in the form of small “papercuts” that fixed small bugs and annoyances and made behaviour more compatible with Vim, including:
One fairly major change is the introduction of an experimental Emulated Vim Command Bar. This, as you will probably have guessed, is a replacement for the current Search dialog that behaves more like Vim’s, allowing one to e.g. insert the contents of registers via ctrl-r; dismiss via ctrl-c/ ctrl-[ as well as ESC; work properly with both forward (“/”) and backward (“?”) incremental searches; use smart case for case-sensitivity; allow the use of Vim-style regex’s etc. As an extension to Vim, I’ve also added the ability to auto-complete words from the document via ctrl-space: not that useful for searching, but very useful for when you want to do a search+replace command (command mode (“:”) did not make it into 4.11, alas).
In 4.11, it is disabled by default as it is not yet ready for primetime, but may be enabled by setting the hidden config option “Vi Input Mode Emulate Command Bar” to “true”. It is much more powerful and featureful in current master (see the blog here!) and will likely be the default in 4.12.
Back in KDE SC 4.8, Kate got a new code folding implementation as part of the yearly GSoC project. Compared to the previous implementation, the amount of bugs indeed reduced, but during the 4.9 and 4.10 release it became apparent, that the code folding was still not where it should be. Maybe writing a good code folding implementation was also a bit too much in terms of a newby developer in a GSoC project.
So Christoph sat down and wrote it completely new from scratch, this time very clean and simple. And as a new feature, the text folding is now per view, so the folded parts can be different in each view of a document. And as another feature for those who do not use text folding at all: Not using text folding means you have zero overhead, no matter how large the file. Besides that, code folding in Python works now better than ever before, in fact, it should be bug-free.
Passive notifications are meant to provide a non-intrusive way showing notifications (replacing KPassivePopup). Used e.g. by the data recovery, these notifications were also introduced for the search & replace feature (most of this is already available in KDE SC 4.10.3). In KDE SC 4.11, the interface for showing these passive notifications got officially included into the KTextEditor interfaces, meaning that applications like Kile or KDevelop can show notifications as well. (Issues in KDE 4.11.0 should be fixed for 4.11.1).
Next to the KTextEditor::MessageInterface, Kate has a so-called TextHintInterface since year 2003, but it seems its implementation never got finished. For 4.11, Sven Brauch stepped up and finally fixed the text hint interface. So showing tool tips for text under the mouse (section Text tooltips) is as easy as it was never before:
When saving files, Kate uses the class KSaveFile (in Qt5 available as QSaveFile thanks to David Faure). In short, to avoid data loss, KSaveFile saves the file to a temporary file in the same directory as the target file, and on successful write finally moves the temporary file to the target filename. If the folder of the file does not allow creating new files, KSaveFile automatically falls back to writing the file directly. In this case, data loss could happen if e.g. the system crashes in this moment, but saving the file would otherwise be not possible at all.
Announced just a few days ago, the KDE community prepares for KDE Frameworks 5 and much more: The KDE libraries and the KDE Plasma Workspace are now in long term support mode, meaning that bugs will get fixed for another two years. That means that the KTextEditor interfaces are frozen as well, there will not be any feature updates at all in the KTextEditor interfaces itself. Since Kate Part and the Kate Application are developed outside of kdelibs, Kate Part and Kate will most certainly see another feature release. Especially, since there are already a lot of improvements for the vi input mode in the pipe for Kate in KDE SC 4.12.
After that, we plan to port Kate to Qt5 and the new frameworks 5 libraries. We already added a lot of “KDE 5” todo-markers to the Kate source code, meaning that we will probably work on a 5 port rather sooner than later. We will address this schedule in a separate post later this year, so stay tuned!
Just an eye-glazingly brief blog post about some of the stuff I’ve been working on in the Kate Vim emulation mode since my last blog. Once more, I’ll mostly be dumping them all as bullet points, Gräßlin-Style™, with some longer sections on the more important changes, but this time around I’ve added some nifty animated gifs which you can skip to should the full text prove too harrowing!
In roughly chronological order, I:
… and a biggie:
There are quite a lot of issues with the interaction between Vim mode and Kate’s own Find dialog:
etc. On top of that, we miss out on some nice features of Vim’s search bars, such as ctrl-r for insertion of register contents; ctrl-w for deleting previous word; ctrl-h for delete; ctrl-b/e for jumping to the beginning or end (more conveniently located, IMO, than HOME or END); plus the Qt regex syntax is different from Vim’s. In light of this, I decided to add a new KateViewBarWidget called “KateViEmulatedCommandBar”:
The searches carried out can be repeated correctly via “n” and “N”. Search history can be navigated via ctrl-p and ctrl-n, and searches “external” to the emulated command bar (e.g. those carried out by “*” and “#”) are added to this history. “Smart Case” is used for specifying case-sensitivity – if the search term has any capitals, then the search is assumed to be case-sensitive; else it is case-insensitive. More on the emulated command bar later! Back to the micro-fixes:
Everything above made it for 4.11, I think. The Emulated Command Bar was disabled by default but can be enabled by setting the hidden config option “Vi Input Mode Emulate Command Bar” to “true”. Continuing:
… and then on to:
The emulated command bar has a lot of advantages over the default Find dialog and command-line for Kate Vim users, but there are drawbacks, too: firstly, it can only perform regex searches and not literal searches, which is awkward when searching for complex expressions pasted from your document that may contain characters that have a special meaning when interpreted as regex’s (e.g. “*”) or which have special meaning in a Vim search bar (e.g. “/” when searching forward, and “?” when searching backwards). The necessity of going through the search term and escaping all such characters is a big strike against its use.
Secondly, Vim’s Find/ Replace dialog has most of the same flaws, when used in Vim mode, as its Find dialog has: in fact, incremental Find & Replace doesn’t work at all with Vim mode(!), and the emulated command bar is of no use here.
Since I’d really like to make the emulated command bar the default (and possibly only) option for use in Vim mode, I really needed to sort out a solution for these two dealbreakers.
For the first, there are basically two options: one is to add some kind of flag that says “look for literal matches for this string; don’t treat it as a regex!”; the other is to make it easy to perform the escaping of special characters. I eventually opted for the second, as it allowed one to treat portions of an expression as a regex if one desired, plus it allowed one to always use the same delimiters in a sed-replace expression (i.e. :s/find/replace/gci) without having to worry about whether the “find” term contained “/”‘s or not. So I added a shortcut (ctrl-g) to the emulated command bar that behaved much like ctrl-r (“insert contents of the following register”) except that it escapes the inserted register contents in such a way that a regex search for the contents would behave the same as a literal search for the contents. The gif below highlights the problem and the solution; the “:) 🙂 :)” bit used ctrl-g to insert the (correctly escaped) yanked expression:
Still missing, though, were interactive search and replace; multi-line search; usage of \U and \L in the “replace” expression to make regex captures upper/ lower cased; etc. Multi-line search and \U and \L codes are available in a class called KateRegExpSearch, so I initially pulled out the guts of the SedReplace code and replaced it with that, and then made the whole thing interactive:
The emulated command bar now seemed to me to be a decent alternative to Kate’s own Find/ Find & Replace dialogs, so with that out of the way, I then moved on to …
The lack of macro support is what got me into Kate Vim hacking in the first place, so it seems weird that it ended up being almost the last thing I tackled. The reason, of course, is that macro support would be a bit crippled if we couldn’t run searches or execute commands in our macros, so I really needed to finish the emulated command bar first. It ended up being quite easy in the end; the main difficulty was in interacting with mappings, especially the situation where a mapping triggered a macro which in turn needed to execute another mapping! Anyway, here’s a small, real-life example of a Kate Vim macro in action:
That’s about it for macro support; now back to the small changes!
… and that’s about it! I’m going to take a break from Kate stuff for a while to work on some other projects I’ve been neglecting, but will return to finish off some odds and ends later 🙂
The Kate Vim mode is in pretty good shape nowadays, so if you were thinking of trying it out, now (with the current master) would be a good time 🙂
valgrind --soname-synonyms=somalloc=\*tbbmalloc\* <your-application-here>
I missed that hint in the Valgrind documentation for my first tries 😉
Btw., the scalable allocator from TBB is a really BIG improvement over the normal system allocator on current Linux & Windows machines if you allocate mostly fixed size small object, like what happens if you heavily use STL data structures like std::map/set that are implemented as trees and you have other stuff like DOM/AST like data structures (even in the single threaded case, for which it just saves a LOT of memory).