Category Archives: KDE

GSoC 2011 – Kate Code Folding – week 4 (Integrating the folding algorithm)

Hi!

I bring good news about Kate’s folding today. The algorithm was implemented and tested successfully. ;)
As I mentioned in the previous article, I implemented it in a new (simpler) project. It is a Qt project (developed using Qt Creator) and you can find it in my Kate clone, “tree_alg” folder.

Actually, I have implemented two folding algorithms: one that uses a tree that changes itself dynamically whenever you insert or delete a node, and one based on stack that rebuilds the entire folding tree whenever you insert or delete a node. I needed two algorithms because I wanted to implement an automatic testing mechanism and for that I needed a way to test the output. The second algorithm was easier to be implemented and it was very stable (bug-less) from the beginning, so it was great to use it for my testing.

The automatic testing proved to be a success. I hope I found all the bugs, but I would like to invite you to download the project and to play a little with this application. If you do find any bugs, please send the history files on the mailing list and I will fix them. About these history files, when you save the history two files will be created. E.g.: if you save your history in a file called “history_1”, then you will have (in the same directory) a file called “history_1” and a file called “history_1_moves”. Please send them both if you notice any bug. It will make my debugging much easier.

My next move is to integrate this tree folding algorithm into Kate’s folding. For this part, I will have to finish an undone job from a previous week (rewrite the interface and the update methods) and add the algorithm I have just implemented.
I think that in ten days at most we will have a new code folding for c style languages. :)

All the best,
Adrian

GSoC 2011 – Kate Code Folding – week 3 (Folding algorithm started)

Hello guys!

I’m writing my weekly article today because I have already started working on something else. I didn’t have time to finish the previous stage because I started the next phase of the project.

I had a talk with my GSoC mentor and a couple of Kate developers and we all concluded that I should start working on the folding algorithm as soon as possible because this is the main (and most important) part. For this part, I built a small new project that will help me implement the algorithm and test it independently from Kate project. You can find this project (and my Kate clone) at this address. There are not so many methods implemented, but you can figure out how things will be developed.

Fortunately, I don’t have to build this algorithm from scratch. I made some research and had some results by the time I was working on my proposal. Here is the paper I wrote based on that research and here is my GSoC proposal, too (it is public now, so anyone can see it).

If you have any questions or ideas, feel free to leave a comment here or to send an e-mail on Kate’s mailing list.

I’ll keep you in touch with my progress,

Adrian

GSoC 2011 – Kate Code Folding – week 2 (Architectural design)

Hello!

Last week I focused on analyzing the interface of the actual implementation. Now, it’s time to develop the new interface.

As I mentioned in my proposal, one of my project’s goals is compatibility: I want to make as few changes as possible in the other sources. This is the reason why I studied the previous implementation for a whole week.

Another goal of my project is classes diagramsimplicity. The interface will be implemented in an abstract class. This class will be inherited by two other classes: one for C style languages (those who use elements like “{}”) and one for Python style languages (those who use indentation level to define the code blocks), as you can see from the diagram. I believe the code will be simpler and clearer if it is more specialized.

Because this part of the projects it’s about design, I would also like to define my data structures. Of course, there will be a Tree, the code folding tree, and some Nodes. It is very important to know where those Nodes are placed in document (row and column). This info needs to be updated when something changes in your document (e.g.: you add a new line, so all the Nodes change their rows). Because it is very time consuming to search through the folding tree, I suggest adding a second data structure.

For this part, I have a dilemma: whether to use a Vector of Vector<Nodes>, or a Set<row,Vector<Nodes>>.

Let’s make it clear: I want to use a Vector of Nodes (actually pointers of Nodes) for each line (because we might have more than one Node per line). But how will be those Vectors stored?

The first option is to use another Vector. The size of this Vector will be the same with the number of rows of the document and Vector[i] = all the nodes placed on the line “i”. This method is easy to be implemented and very fast. The complexity of the updates will be constant and that’s great. So, where is the problem? Memory usage: If we have a 10.000 document lines, then we have about 40 KB of data reserved for this data structure (even though there are no folding nodes at all).

The second option is to use a Set<row,Vector>. For each row, that has at least one folding node, there will be a single entry into this set. This method uses the memory very optimally, but update functions will have a logarithmic (if the set is kept sorted) or linear complexity (much slower than the previous method).

If you have any ideas, feel free to leave some feedback to this article. ;)

Adrian