Saturday, February 27, 2010
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.
Wednesday, February 17, 2010
The Power of Developer Meetings
- Social aspect: You get to know the other developers involved in the project in real life, which is a great motivation factor. This also happens at KDE's annual conference Akademy, although there are a lot more people.
- Productivity: Since you are sitting next to each other discussions about how to do what are very focused. It's amazing how quickly a project can evolve this way. (I haven't seen such focused work in companies, yet. I guess the variance in the knowledge of people involved is higher. And the motivation is usually very different).
- Knowledge Transfer: Since participants are experts in different areas, discussions lead to knowledge transfer. This is essential, as sometimes developers have very few free time to contributes to a project. Spreading the knowledge helps a lot to keep the project alive.
- Steady Contributions: We are always open for new contributors. Just send a patch, get commit access and join development. Experience shows that participants of a developer meeting usually contribute for years to come.
- memory optimization: remove unused edit history items
- fix crash in doHighlight due to wrong initialization
- don't squeeze captions in the window title
- fix crash when using katepart in e.g. konqueror
- kate vi mode improvements
- fix: invalid js commands lead to a crash
- share code snippets between kate and kdevelop
- more syntax highlighting files for asm dialects
- replace: show number of replacements in a passive popup
- new command line command: unwrap
- fix crash when switching sessions with multiple main windows
- fix incorrect global replace %s///g
- fix crash in smart range group handling
- turn search option "highlight all" into the action "find all"
- replace old text snippet plugin with new one
- optimize away nops for text editing
- fixes in the template handler code
- remove pythong browser plugin, since the symbol viewer plugin can do the same and much more
- remove unmaintained html tools plugin, since it was never ported
- optimization for bracket matching
- new text snippet plugin: context aware snippet completion
- fix filtering in the file browser plugin
- always start search&replace from cursor
- developer doumentation for smart range usage
- cstyle indenter: fix indentation of multi-line comments
- update of syntax highlighting for MySQL
- performance optimization in the highlighting system: bug, bug
- fix crash in removeTrailingSpaces, if undo/redo is active
- new interface for getting the mode at a given cursor
- search & replace: lots of code cleanups
- basic regression tests for search, scripting, and more...
- scripting: add support for quoting in command line scripts
- Kate crashes because of spell checking
- fix regression: with auto brackets + selection
- find-in-files: set filter correctly when opening the search
- fix: make reload-scripts work with new functions
- share a KCompletion object between all KateCmdLineEdits
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:
To run the script simply switch to the command line (F7) and write "unwrap". If you have further ideas about useful scripts, don't hesitate to start hacking right away, see also
Fixes with regard to the scripting support in the last days are
Those fixes will be in KDE 4.4.1. More to come in other blog entries :-)
Sunday, January 17, 2010
Kate XML Completion Plugin: Help Wanted
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.
The location in svn is: trunk/KDE/kdesdk/kate/plugins/xmltools
Just enable this folder in the kate/plugins/CMakeLists.txt file and start porting it. The code completion interface changed quite a lot, but there are other plugins and good api documentation (KTextEditor interfaces, Kate Application interfaces) where you can have a look at how things work.
Having a working XML Completion plugin for KDE4.5 would be awesome.
Sunday, November 01, 2009
Scripting Kate
- 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 "<para>text</para>". This is a perfect example for a command line script as well. Any volunteers? :)
Scripting also brings us closer to fixing the following reports:
- macro system: Kate still does not have a macro system. A macro can be interpreted as a group of scripts, executed in a sequence (more or less). The vi input mode already supports pretty complex commands, and the code for scripting is all there. It's just a matter of putting this together so it's usable for users.
- word count: maybe the word count features can be implemented by a script (too slow?). Problem is, that a script cannot show dialogs etc.
To make scripting an even better experience, we still need to implement binding shortcuts to scripts. Again: any volunteers? :)
Thursday, October 29, 2009
Extending Kate with Scripts
- Indentation Scripting
- Command Line Scripting
- Some Remarks
Since Kate 3.4 in KDE 4.4 the Kate editor component is easily extensible by writing scripts. The scripting language is ECMAScript (widely known as JavaScript). Kate supports two kinds of scripts: indentation and command line scripts.
Indentation scripts - also referred as indenters - automatically indent the source code while typing text. As example, after hitting the return-key code the indentation level often increases.
The following sections describe step by step how to create the skeleton for a simple indenter. As first step, create a new *.js file called e.g. javascript.js in the local home folder $KDEHOME/share/apps/katepart/script.
The header of the file javascript.js is embedded in a comment and is of the following form
/* kate-script
* name: JavaScript
* author: Example Name
* license: BSD
* revision: 1
* kate-version: 3.4
* type: indentation
* required-syntax-style: javascript
* indent-languages: javascript
* priority: 0
*
* A line without colon ':' stops header parsing. That is, you can add optional
* text here such as a detailed license.
*/
Each entry is explained in detail now:
kate-script[required]: This text string has to appear in the first line of the*.jsfile, otherwise Kate skips the script.name[required]: This is the indenter name that appears in the menu Tools->Indentation and in the configuration dialog.author[optional]: The author's name and contact information.license[optional]: Short form of the license, such as BSD or LGPLv3.revision[required]: The revision of the script. This number should be increased whenever the script is modified.kate-version[required]: Minimal required Kate version.type[required]: The type must be “indentation”, otherwise Kate skips this script.required-syntax-style[optional]: Comma separated list of required syntax highlighting styles. This is important for indenters that rely on specific highlight information in the document. If a required syntax style is specified, the indenter is available only when the appropriate highlighter is active. This prevents “undefined behavior” caused by using the indenter without the expected highlighting schema. For instance, the Ruby indenter makes use of this in the filesruby.jsandruby.xml.indent-languages[optional]: Comma separated list of syntax styles the indenter can indent correctly, e.g.: c++, java.priority[optional]: If several indenters are suited for a certain highlighted file, the priority decides which indenter is chosen as default indenter.
Kate reads all pairs of the form “key:value” until it cannot fine a colon anymore. This implies that the header can contain arbitrary text such as a license as shown in the example.
Having specified the header this section explains how the indentation scripting itself works. The basic skeleton of the body looks like this:
triggerCharacters = "{}/:;";
function indent(line, indentWidth, ch)
{
// called for each newline (ch == '\n') and all characters specified in
// the global variable triggerCharacters. When calling Tools->Align
// the variable ch is empty, i.e. ch == ''.
//
// see also: Scripting API
return -2;
}
The function indent() has three parameters:
line: the line that has to be indentedindentWidth: the indentation width in amount of spacesch: either a newline character (ch == '\n'), the trigger character specified intriggerCharactersor empty if the user invoked the action Tools->Align.
The return value of the indent() function specifies how the line will be indented. If the return value is a simple integer number, it is interpreted as follows:
- return value
-2: do nothing - return value
-1: keep indentation (searches for previous non-blank line) - return value
0: numbers >= 0 specify the indentation depth in spaces
Alternatively, an array of two elements can be returned:
return [ indent, align ];
In this case, the first element is the indentation depth like above with the same meaning of the special values. However, the second element is an absolute value representing a column for “alignment”. If this value is higher than the indent value, the difference represents a number of spaces to be added after the indentation of the first parameter. Otherwise, the second number is ignored. Using tabs and spaces for indentation is often referred to as “mixed mode”.
Consider the following example: Assume using tabs to indent, and tab width is set to 4. Here, <tab> represents a tab and '.' a space:
1: <tab><tab>foobar("hello",
2: <tab><tab>......."world");
When indenting line 2, the indent() function returns [8, 15]. As result, two tabs are inserted to indent to column 8, and 7 spaces are added to align the second parameter under the first, so that it stays aligned if the file is viewed with a different tab width.
A default KDE installation ships Kate with several indenters. The corresponding JavaScript source code can be found in $KDRDIR/share/apps/katepart/script.
Developing an indenter requires to reload the scripts to see whether the changes behave appropriately. Instead of restarting the application, simply switch to the command line and invoke the command reload-scripts.
If you develop useful scripts please consider contributing to the Kate Project by contacting the mailing list.
As it is hard to satisfy everyone's needs, Kate supports little helper tools for quick text manipulation through the built-in command line. For instance, the command sort is implemented as script. This section explains how to create *.js files to extend Kate with arbitrary helper scripts.
Command line scripts are located in the save folder as indentation scripts. So as first step, create a new *.js file called myutils.js in the local home folder $KDEHOME/share/apps/katepart/script.
The header of each command line script is embedded in a comment and is of the following form
/* kate-script
* author: Example Name
* license: BSD
* revision: 1
* kate-version: 3.4
* type: commands
* functions: sort, format-paragraph
*
* A line without colon ':' stops header parsing. That is, you can add optional
* text here such as a detailed license.
*/
Each entry is explained in detail now:
kate-script[required]: This text string has to appear in the first line of the*.jsfile, otherwise Kate skips the script.author[optional]: The author's name and contact information.license[optional]: Short form of the license, such as BSD or LGPLv3.revision[required]: The revision of the script. This number should be increased whenever the script is modified.kate-version[required]: Minimal required Kate version.type[required]: The type must be 'commands', otherwise Kate skips this script.functions[required]: Comma separated list of commands in the script.
Kate reads all pairs of the form “key:value” until it cannot fine a colon anymore. This implies that the header can contain arbitrary text such as a license as shown in the example. The value of the key functions is a comma separated list of command line commands. This means a single script contains an arbitrary amount of command line commands. Each function is available through Kate's built-in command line.
All functions specified in the header have to be implemented in the script. For instance, the script file from the example above needs to implement the two functions sort and format-paragraph. All functions have the following syntax:
function(arg1, arg2, ...)
{
// ... implementation, see also: Scripting API
}
Arguments in the command line are passed to the function as arg1, arg2, etc. In order to provide documentation for each command, simply implement the 'help' function as follows:
function help(cmd)
{
if (cmd == "sort") {
return "Sort the selected text.";
} else if (cmd == "...") {
// ...
}
}
Executing help sort in the command line then calls this help function with the argument cmd set to the given command, i.e. cmd == "sort". Kate then presents the returned text as documentation to the user.
Developing a command line script requires to reload the scripts to see whether the changes behave appropriately. Instead of restarting the application, simply switch to the command line and invoke the command reload-scripts.
If you develop useful scripts please consider contributing to the Kate Project by contacting the mailing list.
Final Remarks
Right now, it's not possible to assign shortcuts to command line commands. Thus, there is no way of executing scripted commands with shortcuts. Volunteers wanted!The command line scripting can be accessed for all KTextEditor users through the KTextEditor::CommandInterface. That is, you can query a specific command and execute it with arbitrary parameters (The parameter cmd contains the command itself including all arguments. Example: cmd = "goto 65").
Kate's command line itself is actually a quite powerful tool. It's a little bit sad that it's rather unknown. If you want to know more, just invoke "View -> Swith to command line" (shortcut: F7) and start typing text. More details are in the Kate handbook as well.
The Kate scripting API can be found here.
Monday, October 05, 2009
Help on TechBase, KDE Community Forums
Friday, September 18, 2009
News from the Holy Kate Land
- 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.
Wednesday, July 08, 2009
Followup on Kate's on-the-fly spellchecking
> Where can I get this patch?
The relevant subversion revisions are r992778, r992779, r992780, r992784.
> Will it be available in 4.3, or only in 4.4?
As KDE 4.3 will be released end of the month, this feature will be available in KDE 4.4 and not earlier.
> Please, please tell me that it's powered by Sonnet, one of the most awaited KDE4 pillar by me...
Yes, it uses Sonnet :)
The old spellcheck dialog however still uses the old spellchecking code without Sonnet. Any volunteers to port this? Also, the on-the-fly spellchecking needs to be more configurable in Kate's config dialog, e.g. selecting the correct language.
> Thanks so much, this was the feature I was mostly longing for in kate.
Yes, it is one of the oldest reports with 1245 votes!
> What languages are supported support?
<itemDatas>
<itemData name="Normal Text" spellChecking="0" />
...
<itemData name="String" />
<itemData name="String Char" spellChecking="0" />
<itemData name="Comment" />
<itemData name="Symbol" spellChecking="0" />
...
</itemData>
So we have to go through all .xml files and change the relevant parts in the itemDatas section. And that's where we need your help, as we don't know all the languages :) ...and if you want to test this feature, you first have to enable it in Tools > On-the-fly spellchecking.
PS: Is there a better name? Maybe Inline spellchecking? Any linguistic experts around? :)
Tuesday, July 07, 2009
On-the-fly spellchecking in Kate
Sunday, June 07, 2009
Kate Test Regression Suite
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
Step II: Run the test suite
- go to your build directory of kate (e.g. kdelibs/build/kate/tests/
- run the complete suite:
./testkateregression.shell - run specific tests, e.g. for the c indenter:
./testkateregression.shell -t indent/csmart
Tuesday, March 17, 2009
Again System Load Viewer
Friday, February 27, 2009
Creating a Plugin System
Tuesday, January 27, 2009
Feature Plans for KDE 4.2 / 4.3
Friday, January 09, 2009
Compile Time
Building kdelibs (1/6)
Preparing build system for kdelibs.
Running cmake...
Compiling, attempt 1...
Build succeeded after 44 minutes, and 56 seconds.
Installing kdelibs.
Overall time for kdelibs was 48 minutes, and 49 seconds.
Building kdepimlibs (2/6)
Preparing build system for kdepimlibs.
Running cmake...
Compiling, attempt 1...
Build succeeded after 7 minutes, and 53 seconds.
Installing kdepimlibs.
Overall time for kdepimlibs was 8 minutes, and 14 seconds.
Building kdebase (3/6)
Preparing build system for kdebase.
Running cmake...
Compiling, attempt 1...
Build succeeded after 52 minutes, and 35 seconds.
Installing kdebase.
Overall time for kdebase was 57 minutes, and 44 seconds.
Building kdesdk (4/6) # note: several subdirs commented out
Preparing build system for kdesdk.
Running cmake...
Compiling, attempt 1...
Build succeeded after 8 minutes, and 26 seconds.
Installing kdesdk.
Overall time for kdesdk was 8 minutes, and 45 seconds.
Building kdeplasma-addons (5/6)
Preparing build system for kdeplasma-addons.
Running cmake...
Compiling, attempt 1...
Build succeeded after 6 minutes, and 15 seconds.
Installing kdeplasma-addons.
Overall time for kdeplasma-addons was 6 minutes, and 24 seconds.
Building plasma (6/6) # this is: playground/base/plasma
Preparing build system for plasma.
Running cmake...
Compiling, attempt 1...
Build succeeded after 3 minutes, and 25 seconds.
Installing plasma.
Overall time for plasma was 3 minutes, and 35 seconds.
Sunday, January 04, 2009
Quickie: Faster compilation with cmake
- make $target/fast
- make install/fast
Friday, January 02, 2009
System Load Viewer
So if you want to have the plasmoid for your KDE4.2 desktop, it should be straightforward to compile/install.
On the screenshot you can see the plasmoid in action. There are two instances, one on the panel and one on the desktop. The one on the left is the KDE3 one.

It's worth to mention that the plasmoid already supports more featues than the KDE3 version. Features include:
- show all cpus (for computers with multicores)
- tooltip updates continuously
- nicer visualization (maybe needs some more tweaks)
Friday, November 14, 2008
Kate Internals: The Undo/Redo System
Text Operations
First we have to take a look at what actions need to be saved. In KatePart this basically comes down to
- insert text or line
- remove text or line
- selection changes
- (and a few others like wrapping a line)
- the content is 'x'
- the type is 'insert text'
KateUndo Items
In KatePart, an undo item is represented by the class KateUndo:
class KateUndo {
public:
KateUndo (KateUndoGroup::UndoType type, uint line,
uint col, uint len, const QString &text);
~KateUndo ();
bool merge(KateUndo* u);
void undo (KateDocument *doc);
void redo (KateDocument *doc);
inline KateUndoGroup::UndoType type() const;
inline uint line () const;
inline uint col () const;
inline uint len() const;
inline const QString& text() const { return m_text; }
};
Item Merging
Note the function KateUndo::merge(KateUndo* u); This functions merges two undo items of the same type if possible. For instance, typing 'hello world' inserts one undo item for every character, i.e. 11 undo items of type 'insert text'. Kate merges those 11 items into only 1 item with the string 'hello world'. Merging leads to less KateUndo items (less memory) and faster undo/redo replaying.
Item Grouping
What's still missing is the possibility to group several undo items together. Imagine you have selected the text 'hello world' and paste the text 'cheers' from the clipboard. What happens is this
- remove selected text
- insert text from clipboard
Every KateUndo item belongs to one KateUndoGroup. A KateUndoGroup can have an arbitrary count of KateUndo items. In the example above we want to group 'remove selected text' and 'insert text' together. Grouping can be explicitely done in the code as follows (simplified version):class KateUndoGroup
{
public:
explicit KateUndoGroup (KateDocument *doc);
~KateUndoGroup ();
void undo ();
void redo ();
enum UndoType { ... };
void addItem (KateUndoGroup::UndoType type, uint line, uint col, uint len, const QString &text);
void setUndoSelection (const KTextEditor::Range &selection);
void setRedoSelection (const KTextEditor::Range &selection);
void setUndoCursor(const KTextEditor::Cursor &cursor);
void setRedoCursor(const KTextEditor::Cursor &cursor);
bool merge(KateUndoGroup* newGroup,bool complex);
void safePoint (bool safePoint=true);
};
void KateDocument::paste ( KateView* view, QClipboard::Mode mode )
{
QString s = QApplication::clipboard()->text(mode);
editStart();
view->removeSelectedText();
insertText(pos, s, view->blockSelectionMode());
editEnd();
}
Grouping: editStart()/editEnd()
The call of editStart() tells the document that an edit operation is running. All text operations are added to the current KateUndoGroup, until editEnd() is called. editStart() and editEnd() do reference counting, i.e. editStart() can be called nested as long as for each call of editStart() there is (finally) a call of editEnd().
Grouping: Cursors and Selections
Undoing the paste-action above should restore the selection if there was one previously. Redo (i.e. paste again) should remove the selection again. So there are two different types of selections: one before the undo group, and one after. That's why each undo group has the functions setUndoSelection() and setRedoSelection(). The same applies for the cursor position: We have to store two different cursor positions, one for undo and one for redo.
For instance, imagine we removed the text 'world'. Undo (i.e. insert 'hello') should set the cursor position to the end of 'hello'. Redo (i.e. remove 'hello') should set the cursor position to the start of it.
Luckily a programmer does not have to set the undo/redo cursor positions and text selections manually. undoStart() is called the first time editStart() is called. The closing editEnd() finally calls undoEnd(). So undoStart() sets the undo cursor position and undo text selection, while undoEnd() sets the redo cursor position and redo text selection.
Group Merging
The careful reader might have noticed KateUndoGroup::merge(). So merging of two groups is also supported. Whether text operations should be merged into an existing undo group can be controlled with KateDocument::setUndoDontMerge(). Pasting text for example set's this flag.
Undo and Redo
Every document in KatePart has two lists: An undo list, and a redo list. Suppose we have 10 KateUndoGroups in the undo list and the user invokes undo 4 times. Then the undo list only contains 6 items and the redo list 4. Now it is also possible to redo. However, typing text clears the redo list.
Document Modified Flag
KateDocument::updateModifed() is called to update the modified flag of a file. This update also relies on the current active undo group. Saving the file saves a pointer to the current undo group, and later we simply can check whether the current undo group is the active one. Pretty simple mechanism. However, there right now seems to be a bug you can reproduce as follows:
- save doc [not modified]
- type a character [modified]
- undo [not modified]
- type a character [modified]
- undo [still modified]
Thursday, August 14, 2008
Akademy 08: Kate Flashback
- fix: drag & drop of text
- code completion: only show group header if the group name is not empty
- reintroduction of buffer blocks in Kate's document buffer (one buffer contains up to 4096 lines). The blocks build a linked list. Editing a 500 MB file kind of works now again. It's still rather slow, though.
- more speedup in Kate's document buffer
- Kate is using KEncodingProber instead of KEncodingDetector now
- generate internal version of KatePart automatically, so developers don't have to adapt it manually each release
- python encoding detection plugin that warns if encoding is not correct while saving
- new plugin: Backtrace browser, mainly for developers
- find in files: several speed optimizations
- find in files: progress indicator while search is active
- find in files: redesign of workflow. Search happens with non-modal dialog and results are shown in toolviews.
- lots of vi mode changes
- lots of bugs closed, mainly old ones
- some real bug fixes...
- things I forgot
Tuesday, August 12, 2008
Kate: Fast backtrace navigation
Sometimes there are several files with the same name, e.g.
- trunk/kdegraphics/okular/generators/dvi/config.h
- trunk/kdepim/mimelib/mimelib/config.h
- dvi/config.h
- mimelib/config.h
How to configure
- Enable the plugin: go to Settings > Configure Kate > Application Plugins and enable 'Kate Backtrace Browser'

- A config page appeared, so click on it and add the directories containing the source code

- Clicking OK will start indexing. It will take some time (the index of kdesupport + kdelibs + kdepimlibs + kdebase + kdesdk + playground/plasma + plasma-addons + kdevplatform + kdegraphics is about 6MB)

Hope it's useful :)