Kate Code Folding

Adrian Lungu

Short description: Kate is a KDE text editor. The goal of this project is to redesign the code folding feature. The actual implementation contains many bugs and is hard to be maintained. I would like to redesign this feature using the knowledge gained from the current implementation and add a new feature as well – code folding preview.

 

Personal Details

Name: Adrian Lungu

Email Address: adrian.lungu89@gmail.com

Freenode IRC Nick: adrian_lungu89

IM Service and Username: Google Talk – adrian.lungu89@gmail.com

Location: Bucharest, Romania, UTC +02.00

 

Project Details

Proposal Title: Kate Code Folding

Motivation

I use Kate editor to write most of my projects and I am very familiar with this editor, as well as its code folding bugs. I’ve personally encountered this problem while programming in Kate : ). I am a very ambitious person and I would like to solve all these bugs forever with a new implementation based on two simpler solutions. I do believe in my motivation and my programming skills to make this project a success.

Implementation Detail

My project idea is based on two elements. The first one is a new approach of the problem: transform one more complex problem into two simpler problems. To be more specific, as far as I know there are two types of programming languages: there are languages that use syntactical elements like {} or any other begin/end constructions (e.g.: C/C++) and there are languages that use indentation level to define their code blocks.

The second idea is to have the new implementations compatible with the current one. What I mean is that most of the actual public functions will still be used in the new implementation (some of them will suffer a few modifications), to solve the dependencies problem in a smart and simple way. So there won’t be too many changes in the other source files. In the next paragraphs I will detail these ideas.

1. Keep It Simple Stupid

I do think that the major problem (and the main cause for all these bugs) of the current solution is the somewhat complicated implementation. The code is pretty difficult to be read, maintain and debug. My idea is to use an abstract class where the frontend functions and Q-SLOTS will be defined. Those are the functions used by other classes to communicate with the code folding algorithms. This abstract class would be extended by two classes as mentioned before.

I believe that this approach will have better results than the current one because the backend implementation will be more specific for every class. A more specific code translates into maintainability and better performance and this is the goal of this project.

2. Design solutions

For the first class of programming languages I have thought to a tree-algorithm based on two types of nodes: begin nodes (e.g.: “{“) and end nodes (e.g.: “}“). Because the position of these nodes is very important in order to decide where to add the new nodes in the tree, we have to update their positions (row and column) each time we type/delete a character (the current implementation use this update approach as well). This part is very time consuming if we have to search through that tree. Another problem is that when you insert a new line, you have to update all the nodes from that specific line to the end of the document.

My solution for this problem is to have a 2D structure: a QVector object will contain the nodes for each line of the document sorted by their columns. So, when we’ll insert/delete a character on line ‘l’ we’ll have to modify only those nodes placed on line ‘l’. Furthermore, we don’t have to update the whole line; we can update only the nodes affected by this change. Then, another QVector object groups all these lines. This is very helpful when we enter a new line or delete a whole line because all we have to do is to change some addresses in this QVector. The vectors used for lines will suffer no changes.

For the second class of programming languages the implementation will be a little lither because we cannot have problems like parentheses unmatched or more code blocks starting on a single line. Therefore, I propose a tree-algorithm based only on a single type of nodes. Also, we can have a second (linear) data structure used for the update. There is no need for a 2D data structure because there is only one node per line.

Another solution that can be applied in both cases is to use a root-node. The root node cannot be folded and all the other nodes will have this node as their ancestor.

3. Backwards compatibility

Compatibility with the current implementation will be ensured by the common abstract class. This class will define the public functions, the objects and the Q-SLOTS needed to be implemented in order to ensure backwards compatibility.

4. Testing

Testing is a very important part in this project development. Firstly, I will test the tree-algorithms separately, to make sure they work fine. Then, I am planning to surf the internet for several source files, written in different programming languages, and try code folding on them. For the last part, I will use a profiler for some fine-tuning.

5. New Features

Why not? I do think that I will have about two weeks to implement some new features for Kate code folding. One of my ideas it is to implement the “code folding preview” (a feature that is implemented in many editors, e.g.: QT-Creator [1]). I believe it would be a nice feature for Kate and useful for the Kate programmers as well. 

 

Tentative Timeline

25 April – Do more research – See how other open-source editors implements code-folding; discuss all my ideas with my mentor and community members;

May 23 – June 12 – I won’t be able to work during this period because I will have some school exams during this time.

Weeks 1-2 (13 June – 26 June) – Plan on how to fit all the “puzzle pieces” (algorithms, data structure and other objects used); implementing the abstract class that will ensure backwards compatibility; take an overall picture of Kate code folding.

 Weeks 3-4 (27 June – 10 July) – I will implement and test my tree-algorithms, which is the base of the code folding. The algorithms will be implemented in C++ using QT objects but as a separate project in order to test them as much (and easy) as possible.

Weeks 5-6 (11 July – 24 July) – Implementing the two classes that extends the abstract class using all the information gained in previous weeks.

Weeks 7-8 (25 June – 7 August) – Implementing a new feature for Kate code folding – “Code folding preview” (presented above)

Weeks 9-10 (8 August – 22 August) – Lots of testing and some documentation (I saw that Kate source file have a little lack of code documentation, but I think some explanations about the implementation would be great).

 

About me

I am a 3rd year student at “Politehnica” University of Bucharest, Romania, majoring in Computer Science and Engineering. I have developed a passion for algorithm since High school when I participate in many programming competitions and took things to a new level during college. In the last years I have developed a lot of small and intermediate-size projects using languages like C, C++, Java and Python.

I consider myself an experienced programmer in C and C++, since I’m programming in these two languages for more than 5 years. I am not so confident with my current QT knowledge, but I have already started (as part of a three students team) working on a photo editor developed in QT, so by the end of the spring I will have finished my first QT project. : )

I am very prompt when I do have some tasks to finish. I learned from previous projects to manage my time in order to finish my job in time. I am also eager to learn as many things as possible so I will respond positively to any feedback from my mentor or the user’s community.


[1] -