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.

Advertisements

10 responses to this post.

  1. Posted by arieder on 19. June 2010 at 14:04

    cool stuff. you totally rock!

    Reply

  2. I *need* this.
    By the way, does/will cantor support Mathematica/Maple? That would be extra-rich dark delicious sinful chocolate icing on the cake 🙂

    Reply

    • Posted by arieder on 19. June 2010 at 18:40

      no it doesn’t support them, and probably won’t do anytime soon, unless someone else steps up to write it.(i won’t spend my free time working with non-free software)

      Reply

  3. Posted by mahousenshi on 19. June 2010 at 17:29

    Nice work! If this export graph to EPS it’s will be qtoctave killer

    Reply

    • Posted by noughmad on 19. June 2010 at 18:03

      Cantor can export the graphs as images (but not EPS) from the right-click menu, if that’s what you mean. However, the .cws file Cantor saves is an archive that contains the graphs as EPS files, same as octave itself produces.

      Reply

      • Posted by arieder on 19. June 2010 at 18:10

        if the plot is in EPS format (as it is for maxima and octave backend) the right-click menu offers possibility to store as eps file (not image).

        Reply

      • Posted by noughmad on 19. June 2010 at 18:20

        Alexander is right (I can’t reply to his comment, dunno why). I see now that it depends on the filename.

        Octave by default doesn’t append .eps to its output file name, and I tried exporting on an old file file created before I fixed that. Sorry for the confusion.

        Reply

  4. Posted by Kyran on 19. June 2010 at 18:22

    Can’t you reuse the code highlighting from kate? It has a very nice matlab/octave “stylesheet”.

    Reply

  5. I will right away seize your rss as I can’t to find your e-mail subscription hyperlink or e-newsletter service. Do you’ve any?
    Please permit me understand so that I may subscribe. Thanks.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: