Posts Tagged ‘Cantor’

Season’s End

During this summer, I participated in the Season of KDE, working on a Octave backend for Cantor with my mentor and Cantor author Alexander Rieder. I’m proud to say I have achieved my goal. In addition to running Octave commands directly from Cantor’s worksheet, all convenience features supported by both Cantor and Octave support are available:

  • Syntax highlighting for functions, variables, operators and strings
  • Tab-completion
  • Easy access to function documentation / syntax help
  • Easy 2D and 3D plotting of functions, with plots integrated in the worksheet
  • Linear algebra extension for defining matrices and computing their inverse, eigenvectors and eigenvalues
  • Integrated script editor and runner
  • Possibility to interrupt or restart Octave at any time

I haven’t been really regular with blogging, so I would like to apologize and give you something better in return: a screencast. Please excuse my bad english and strange voice, I’m really not a good speaker in any language.

Also, it was only after I finished that I remembered it would be better to make a presentation with untranslated Cantor. I hope I explained everything I did well enough.

Hi-quality version

Low-quality version

I would really like to thank the KDE team (especially Lydia) for organizing this, and my mentor Alexander for help and guidance (and finding me more things to do 🙂 ). I will certainly continue working on (and with) KDE.

Highlighting in Cantor

Disclaimer: another post about 4.6 when 4.5 is barely out. Please don’t hate me. If you do anyway, scroll to the end of the post.

When I started working on Cantor, most of its highlighters worked like this:

There was a struct HiglightingRule with two members: a QRegExp and a QTextCharFormat. The highlighter would make a QList of these rules, iterate over them every time the cursor moved, and formatted all matches of each regex with the associated format. As there could be a lot of these rules (~1600 for Octave), things could get slow. The other backends didn’t have that many rules, that’s why I was most bothered with it. Thousands of iterations and especially regex-matchings for every key pressed is really too much for my poor laptop. It was enough to make scrolling non-smooth. Because QSyntaxHighlighter can’t easily be made asynchronous, holding down the right arrow key caused the cursor to hang and jump randomly.

Fortunately, Alexander (Cantor’s author) and Oleksiy (who works on the R backend) tried a different implementation: The text was broken down into words, and each word checked against a database. We then decided that a database is not needed and I replaced it with a QHash<QString, QTextCharFormat>. Iterating over 1600 regexes was replaced with iterating over less than ten words and searching for them in a hash.

I preserved the QRegExp-based API for things like strings (‘.*’ and/or ".*"), but most of the rules are now converted to the word-based highlighting. Even without a proper benchmark, it’s obvious that scrolling is much faster now. It’s also not something screenshot-worthy, so I have to disappoint you again. Please don’t hate me again.

Final note for spoiler-haters: Even though I’m talking like I’m already skipping it, and I don’t have it because it’s not in Arch yet, there is something special for me about the 4.5 release. It’s the very first release of KDE with a piece of my code. Quite literally a piece, because in total it’s two new lines, but it makes me prowd. I added auto-prefetching to the Comic plasmoid.

Octave-backend improvements

I’m having a bit of a pause between the exams, so I’m doing some hacking on the new Octave backend for Cantor. Thing are going very well, probably better (especially faster) that I expected.

The basic input-output sending between Cantor and the command-line process was working some time ago, and I recently added support for embedding graphics into the worksheet.

This week I was working on cosmetics: Autocompletion, syntax highlighting and pop-up help.

Completion for functions and variables

Completion for functions and variables

Completion was easy, octave provides a completion_matches() function which takes a string argument and return all functions and variables starting with that string.

Syntax highlighting and help

Highlighter - there can be only one.

Syntax help was also quite straightforward, through the use of Octave’s built-in help() command. Highlighting was where I spent most of the time, because as a command-line program Octave has no native support for it.

There’s a handy command called ‘who’ that lists all currently visible variables, so I retrieved the variable name list with it and used it in the highlighter. I then hardcoded a list of all recognised operators and keywords.

The toughest nut was getting a list of all functions from Octave. There’s no (at least known to me) equivalent to ‘who’ for functions, so I had to improvise. I didn’t want to hardcode all the functions, as is done for the Maxima backend, because, as we all know, hardcoding is bad, and there’s always the possibility of future changes to Octave language. The closest I could get is using completion_matches() with an empty string, but that returns all the internal constants, environment variables, and files in the current directory. I filtered them out the best I could, and the end result work well, despite there being more that 1600 functions.

Embedded plots in Cantor

Embedded plots in Cantor

Another think I worked on this week is getting as much plotting code as possible from C++ to an octave script. This not only unclutters the worksheet (there used to be a long line of commands instead of cantor_plot#d()), but makes simple changes to plotting faster by not requiring a recompile. Tweaking the size of the plot to prevent it from filling the whole page didn’t even need a new session, just an update to the script.

Hello Planet

Since my blog is now shown on PlanetKDE, I believe I should write a formal introduction:

My name is Miha Čančula, I’m a second year Physics student from Slovenia. My involvment in KDE this summer is mainly composed of two parts:

Octave backend for Cantor

I didn’t make it into GSoC with this, so now it’s a part of the Season of KDE, mentored by Alexander Rieder. I should be doing this after I finish my exams, which will be in July and August, but I made quite a progress even before the exam period. Pretty much all the functionality is already there, I’m even using it for my Numerical methods class. What’s missing is completion and syntax highlighting, those will have to wait for about a month, when I’ll have some free time, and when I discuss it with the mentor.

KDE4 port/rewrite of Knights

For my current pet project, I chose something less serious, and something I figured to be quite easy to go. It is smooth sailing so far, but interfacing with console programs (a recurring theme for me, that’s also how Cantor talks to Octave) and the chess server took some time, documentation searching and experimentation.

Currently supported is a hot-seat game on one computer, playing against an XBoard-compliant chess engine, and the Free Internet Chess Server. I’m still not sure how to interface with Crafty, although XBoard and the old Knights support it. I’ll take a deeper look into their sources soon. And as promised in my previos post, a screenshot of playing on FICS:

As you can see, the default theme is the one from Knights for KDE3 with consent from its author, Troy Corbin. He didin’t have a SVG version, so they’re all PNG’s inside a SVG file. I would very much like a new, completely scalable theme as the default one, as it would look much nicer. Also included is a vector Tux theme, which looks much better, but the penguins aren’t really suitable for being the default.