Developers
Kate Internals: Text Buffer
Right now, in Kate’s gitorious repository we, or rather mainly Christoph, is rewriting the heart of Kate: The text buffer. In this blog I’ll explain how the text buffer works in detail. After reading, you’ll be able to understand the code. And be warned: Probably you will be desperately amazed about its awesomeness! So this is a must read :^)
Storage. Kate Part internally stores the content of a text document as a QVector of text lines. Each text line holds the text in a QString object as well as additional data like color attributes for highlighting. Inserting and removing text lines implies inserting or removing items in the QVector of the text lines. This is can get slow when there are thousands of text lines in a document, because QVector has to move the memory every time. Thus, to keep text operations fast, Kate splits all text lines into several text blocks: Each text block contains a certain amount of lines (e.g. 256). The expense of memory movement is then always limited. When a text block grows too much, it is automatically split. When the amount of lines in a text block shrinks, it is merged with the previous text block. In other words, Kate’s text buffer automatically balances the text blocks. The basic idea of Kate’s text buffer, the text blocks and text lines looks like this:
Design Ideas of the Kate::TextBuffer
Storage
- Basic idea: text stored as lines
- Lines hold text and additional data (like for highlighting)
- Advanced Concept: Stores lines in blocks of xxx lines, to have better performance
Cursor Support
- They will move on editing
- Cursors can be combined to ranges
- KateTextCursor will be stored in the buffer blocks
Transactions
- Each edit action must be encapsuled in a transaction
- startEdit/endEdit will do this
- Signals for starting and ending this transactions
Revisions
- After loading, buffer has revision 0
- Each edit action which is no nop will lead to increment in revision number
- Successful saving will reset revision back to 0
Editing Operations (only 4 different editing primitives)
- Insert Text (inside one line)
- Remove Text (inside one line)
- Wrap Line (wrap a line at given position, create a new line with content behind wrap position)
- Unwrap Line (unites the line with its predecessor)
- Signals for all of these actions, containing the change (to allow to layer undo/swap file support/…) on top of the buffer
Load/Save & Encodings
- Loading will try to use given codec, if that doesn’t work, try to detect the codec by the BOM at start of file or use fallback codec, if that again doesn’t work, given codec will be used again, and errors reported
- Saving will just use the given codec
Unit Tests
- Each of the above implementation details will be covered by unit tests
- KateTextBuffer (+KateTextLine and Cursor) must therefor be usable without other components
Kate Partly Moving to Gitorious
We have discussed a bit about the migration to gitorious on the Kate Developer Meeting and Christoph came up with this mainly because building only KTextEditor, Kate Part, KWrite and Kate is much faster and easier compared to building the KDE modules kdesupport, kdelibs, kdepimlibs, kdebase, kdesdk.
I myself remember the time where I started KDE development, and it took more than two weeks to have a first successful build of KDE. You have to learn so many things at once, like revision control, lots of so far unknown software, and what not. Talking to other developers verifies this. In other words: Getting into KDE development is not easy and straight forward.
Moving to gitorious removes this barrier for Kate development: You just checkout the Kate repository and that’s all you need. It would be nice if you join Kate development and contribute patches :)
What does that mean for Kate in KDE? Nothing changes. We will merge the changes in Gitorious back to the main KDE development line and vice versa. Read More
Developer Meeting: More on scripting Kate
Yesterday I closed a bug requesting an “unwrap” feature in Kate that works like “Tools > Join Lines” but maintains paragraph separation, i.e., empty lines are not removed. This feature is implemented now in javascript. Further infos: Read More
Kate XML Completion Plugin: Help Wanted
In KDE3 Kate had a plugin called “XML Completion Plugin”. It was able to list XML elements, attributes and attribute values and entities in a completion popup menu depending on the currently active DTD. For instance, it was able to complete all your KDE/docbook tags and, thus, was one of the best tools for writing KDE documentation.
Unfortunately, this plugin has not been ported to KDE4, yet. So this is a request for developers: Please someone pick it up and make it available for Kate in KDE4.
Read MoreScripting Kate
In my last blog I explained Kate’s scripting features in KDE 4.4. To better understand how scripting can be used let’s look at some use cases.
- join lines: This feature request wants the action “join lines” to not join different paragraphs, i.e. not remove empty lines. We have not implemented this wish, as there are probably users who prefer the current behaviour. This request can be fixed by writing a small script that joins the lines according to the user’s wishes.
- reformat paragraph: An intelligent reformatter for paragraphs. Should be rather straight forward to implement.
- XML tools: In KDE3, Kate once had a xmltools plugin. Unfortunately noone ported it to KDE4. The plugin provided lots of very useful features for xml editing. For example, you could select text and then wrap it with xml elements, e.g. “text” would become “
textRead More
Extending Kate with Scripts
As mentioned in one of my last blogs, there has been quite some work for JavaScript scripting support in trunk recently. So what will Kate 3.4 (KDE 4.4) will bring? This is explained in detail in the sections:
- Indentation Scripting
- Command Line Scripting
- Some Remarks
The scripting allows to extend Kate with lots of little helper functions. All users can add scripts as they wish. The documentation here is copied from the official Kate handbook. So instead of using this blog as reference, please use the handbook later for an up-to-date version. To script something useful, you’ll need to know the scripting API. All the available functions are documented in the section Scripting API in the handbook as well. Enough said, here we go:
Read MoreNews from the Holy Kate Land
Since we now all know that Kate is holy (thanks to rms. By accident, he obviously confused Kate with emacs, though) let’s have a look at what’s going on. In the last months Kate development is quite active, so here is a quick update:
- new: on-the-fly spell checking thanks to Michel Ludwig. Highlights include e.g. spell checking in comments of source code or latex parts. Also, constructs like sch”on work in latex.
- extended scripting support in the command line, more on that later
- more and more mature vi input mode
- lots of bug fixing. quite impressive bug squashing by Pascal Létourneau for more than 4 months now
- lots of refactoring and code cleanups thanks to Bernhard!
- “Find in Files” appears by default again in the tool view,
- “File Browser” uses UrlNavigator, huge code cleanup
- convenience updates of syntax highlighting
- delayed highlighting of code folding ranges to prevent flickering on mouse move
- new command line commands: ‘toggle-header’ in the Open Header plugin. ‘grep’ and ‘find-in-files’
- haskell and lilypond indenter
- much, much more, see commits for details.
Thanks to all contributors involved in Kate development. Keep it up :)
Read MoreOn-the-fly spellchecking in Kate
Christoph just added an awesome and long awaited feature: on-the-fly spellchecking. ‘Kate’s xml highlighting files now have an additional attribute in the itemData section: spellChecking=”true/false”. C++ comments and strings can be spellchecked now :) Same for all other languages such as Latex. Really big thanks to Michel Ludwig for the patch, good work! Screenshot for latex highlighting:
Read MoreKate Test Regression Suite
This blog is mainly about documenting the process how to run Kate Part’s test regression suite and probably not much use for other developers.
Step I: Setup the environment
- create the file ~/.testkateregression. The content of this file is a single line pointing to the folder of the checkout of the test regression suite data. For me this is
/home/dh/kde/tests/katetests/regression/ - Create the folder where you checkout the suite
mkdir /home/dh/kde/tests - Change to this folder
- Checkout the data:
svn co svn://anonsvn.kde.org/home/kde/trunk/tests/katetests
Now all the data is there for testing.
Read More