04.20.06

More Spreadsheets in TextMate!

Posted in TextMate at 11:29 pm by Haris

In the previous post I talked a bit about the Spreadsheet bundle. Now it is ready for some beta testing! Here’s a small screencast demonstrating some basic functionality. The syntax for the expression is similar to the standard Spreasheet syntax. You can use dollar signs also, to indicate cells that do not change.

Update 3 Here’s a new screencast, for the updated bundle. Please update to the new version, it’s very much improved.

Here are the files. Sorry, not much documentation yet, but feel free to post your questions here. Here’s a screenshot:

Spreadsheet bundle

Update 1: I should mention that I am using vertical bars “|” for the cell delimiters, instead of tabs, because tabs did not allow for the textmate variables accurately describing the cell that the cursor is located at. Also, if you want to color the cells and the delimiters then you’ll want to set colors for the scopes “meta.cell” and “meta.cellend.tab” respectively. Finally, you can have comment lines that start with the hash symbol “#”.

Update 2: I just updated the bundle, and it now has a lot more ruby support. First off, you can have it execute one liners of the form “%r aRubyCommandHere”. There are executed by the Spreadsheet instance. You can access the data by calling data. So “data[4][5]” will return the entry in E5. To set values, use set_data. so both “set_data([4,5],28)” and “set_data(”E5″,28)” will set the value of E5 to 28. Atm the whole program must be in one line I’m afraid.

The other way is to add to the built in functions. The file commands.rb contains the module ParserDelegateMethods. This module is being loaded into ParserDelegate. If you add to this module a command like:

def foo(array)
  dosomethingwitharrayandreturnvalue
end

then in your files you could use FOO(2,3,4) to call this command.

IMPORTANT: This new version of the bundle requires vertical lines at both ends of the table. Running the reflow command should add those automatically.

Later

19 Comments »

  1. oliver said,

    April 20, 2006 at 11:51 pm

    That’s fantastic. I’ll be sure to dive into that when I have time next week.

  2. JEG2 said,

    April 21, 2006 at 3:06 pm

    This is truly unique. Nice work!

    Random idea #653: I wonder what it would be like to offer an option to filter the formulas through Ruby… ;)

    James Edward Gray II

  3. ryan king said,

    April 21, 2006 at 4:04 pm

    I see that you have a theme that goes with the bundle, but it doesn’t seem to be showing up for me.

    Also, do you have a file-extension that goes along with these files?

  4. Haris said,

    April 21, 2006 at 5:27 pm

    @ryan

    I basically just added two elements to my current theme, one with scope “meta.cell” and and the other with scope “meta.cellend.tab”. I am just hoping for someone much better in producing themes to come up with something appropriately radiant. :)

    I haven’t set it to have any file-extension, because originally I was planning for them to be just tab-delimited files, but then I added the comments and commands, so perhaps I should just come up with an extension. Hm, maybe “spd”?

  5. ryan king said,

    April 22, 2006 at 1:08 pm

    For the theme, I guess I just need to add the stuff to whatever theme I’m using and for the file extension, I’m sure we’ll figure it out as we go. :D

    This is awesome, btw!

  6. Alakazam said,

    April 30, 2006 at 6:17 am

    I’m not sur this is the best place to put this :

    This is really very nice, but it seems to have difficulty reflowing when there are accented characters (which would take 2 ‘columns’ in utf-8). Is there a way to remedy to this problem?

    Thank you, and congratulations!

  7. Haris said,

    April 30, 2006 at 8:02 am

    @Alakazam

    right now the script uses the “length” method of String to find out how long the string is supposed to be. Unfortunately, this does not seem to count utf-8 characters properly. It is possible to fix this, and it will happen then next time I update the bundle probably, but it is nontrivial enough that I don’t have the time to fix it right now. If you have experience with ruby, you can try it yourself. I think you can find some ideas here:
    http://www.bigbold.com/snippets/posts/show/1659
    http://www.fngtps.com/2006/01/encoding-in-rails
    http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/

    There is only one place that would need a slight change. Basically, you want to change the width command of the Array class, which is defined in helpers.rb, to not call to_s.length, but instead your custom string length method. Actually, all you have to do is change the call to_s.length to to_s.scan(/./u).size. That should do it.

  8. chris schwan: interactive designer said,

    July 16, 2006 at 10:34 pm

    […] You can make spreadsheets in TextMate. […]

  9. Ruben said,

    July 20, 2006 at 5:46 am

    While working with spreadsheets I missed a feature to highlight specific lines (the header, the last line with the final result or the like).

    To have that feature I copied the pattern for lines and changed the first character to a special character (I used > right now). I then mapped that line to meta.line.firstline.spreadsheet. It behaves like other lines but can be coloured different through themes.

    Maybe that’s useful for anyone out there.

  10. Ruben said,

    July 20, 2006 at 6:27 am

    I had some problems with my solution to work with the commands. Had to make some small changes to spreadsheetTools.rb. If you’re interested, send me an e-mail.

  11. Ungenious said,

    April 9, 2007 at 9:46 am

    I assume that this project is dead?

    I’ve come here from a link in previous commenter James Edward Gray II’s book “TextMate: Power Editing for the Mac”.

    I was hoping that there would still be a pulse in basic editing of CSV documents for TextMate. I’m just a beginner using TextMate, but I’m looking to edit/delete columns in a CSV and as my files are not separated by tabs, rectangular editing won’t work due to different #s of characters in each column.

    Cheers.

  12. Haris said,

    April 10, 2007 at 5:45 am

    @Ungenious,

    assuming you are referring to the Spreadsheet bundle in particular:

    It’s not exactly dead, but definitely very low in my priorities at the moment. Of course the bundle is there and is relatively working, though far from perfect. But I don’t really have the time and interest to work on it more at this point. There are a number of other bundles that need my attention, that are more crucial than this.

    When I have to edit such files, I first add spaces to make them align column-wise. Not ideal of course.

    Depending on what kind of work you want to do in those files, you might want to consider something like R. These days I do a lot of work in R, so I would probably write an R program to do what I would want to. R can read and write CSV files quickly, and of course could write them out in another format as well.

  13. Ungenious said,

    April 18, 2007 at 5:59 pm

    Thanks for the reply. I understand that this would be a low priority bundle, but was hoping it would be someone’s hobby.

    Yeah I was thinking about replacing the commas with a bunch of spaces to do rectangular editing, but yeah.. gross.

    Yes, I suppose I should just use R, but then at the same time it sort of begs to be done by someone eventually.

    Regards,
    U

  14. Haris said,

    April 20, 2007 at 12:54 pm

    Hehe, yeah it did start as my hobby, but also it was more of a question of: Let’s see to what extend we can do this in TM.

    Unfortunately there were a lot of technical issues that make it hard to work with, but perhaps when TM 2.0 comes out some of its features might suggest ways to improve the bundle.

    One of the key features I think would be to have the file saved as a regular csv file on the disk, but show up like a spreadsheet for editing. This would require writing custom load/save methods etc, and even then I’m not sure it can really be done to a satisfactory extend.

    There’s a lot of things I would want to improve in this bundle, but no time to do it.

  15. Skyros said,

    December 20, 2007 at 10:00 am

    Nice!

  16. Martinos said,

    January 31, 2008 at 10:50 pm

    interesting

  17. Matthaios said,

    February 2, 2008 at 1:07 am

    Nice!

  18. JiHO said,

    March 13, 2008 at 8:24 am

    This is very nice . I deeply hate spreadsheets too and would much prefer to spend my whole time in TextMate. One thing I would really appreciate would be a syntax flexible enough to recognize classic text-based spreadsheets formats (comma/space/tab separated values) and show them nicely in TextMate (so that columns are recognized and all). I saw you changed from tab to | as a delimiter for better highlighting. If there is any way in which you can support these formats it would be great (tried to modify the grammar myself but would not get it to work).
    Great initiative already!

  19. Haywood Casey said,

    November 12, 2008 at 2:11 pm

    ik0quss8gfw764l0

Leave a Comment