New MATLAB Bundle for TextMate
Written by thomas on March 28th, 2007
Unhappy with the MATLAB bundle that was included in TextMate, I set out to write a new one. The old one was a mashup of Bash, Octave, MATLAB, and some other stuff, which, needless to say, didn't quite measure up. So, without further ado, you can now download the new and improved MATLAB bundle!
As time goes by, I'll most likely submit the bundle for inclusion in the official TextMate distribution, but I want to add some more features, as well as bugfixes. Since I don't have Subversion access to the bundle repository, it will be much easier for me to develop in my own svn repository. So if you're using this bundle, please let me know if you find any bugs or if you have some requests.
Here's a tiny recap of the features which you'll find in this bundle. First of all, plenty of syntax highlighting goodies! (As long as you use a theme which has defined all the different colors.) Not only are a bunch of new scopes recognized, but it will also mark invalid code for you! Such as invalid variable names, improper use of quotes, etc. It will also highlight strings, transposes, operators, and numbers.
I have also added the complete functions list provided by Mathworks. If you find some functions that you find missing, please let me know and I'll add them. At some point, I may add the option of scanning and adding your private functions to the highlighting, but this won't be done any time soon.
In this bundle, you'll find quite a few snippets such as figure operations (set, get, xlabel, ylabel, zlabel, xtick, ytick, line, subplot, title). For instance, if you hit "sub" followed by tab, TextMate will insert subplot(rows,cols,current), giving you the option of tabbing through the variables. The next time you invoke subplot, it will pre-populate the function, as well as automatically increment the current plot variable. Nifty!
Other useful snippets include if, if else, for, while, unix, clear, exp, ^. Also, there are several snippets for writing functions. If you type "fun", you will see
function [Output variables] = functionName(Input variables)
% FUNCTIONNAME Short description
%
% Long description
%
% SYNTAX
% [OUTPUT VARIABLES] = FUNCTIONNAME(INPUT VARIABLES)
%
%
% Created by Thomas Kjosmoen on 2007-03-28.
% Copyright (C) University of Stavanger. All rights reserved.
%
but obviously pre-populated with your name and organization. The help information here will be automatically filled in as you enter the function and variable names. This has saved me a lot of time, as well as letting me use a standardized help information for all my MATLAB functions. There are also, of course, snippets for things such as warnings, errors, disp, sprintf, fprintf, and BSD and GPL license information. Help with function names has also been added. Hit ^H (control-h), and you'll get the online MATLAB function reference.
While I'm focusing on the output functions, I should also mention that we now have more advanced features when dealing with strings. For instance, if you're inside a string such as
a = 'hurray for matlab'
and you realize that you need to split this up in several lines, just hit enter! You will then automagically get
a = ['hurray for ' ...
'matlab']
and the string will be properly recognized by MATLAB. (This "..." will also be automatically inserted if you hit enter in a regular matrix or parentheses.) Let's say you want to add a number to that, using the variable "foo"
a = [ foo 'times hurray for ' ...
'matlab']
As you might know, you now have to convert the variable "foo" to a string; just hit the quotes character " and you'll get
a = [ num2str(foo) 'times hurray for ' ...
'matlab']
Couldn't be easier ;-)
The last feature I'd like to point out, is the drag and drop features. If you drag an image into TextMate, you'll get something like this
image = imread('../../../Desktop/imagename.jpg');
with tab-stops in all the right places. Also, if you drag a MATLAB .mat file, you'll get
variable = load('../../../Desktop/filename.mat');
I hope you find these features useful, and please let me know if you like or dislike something, if you have wishes, or if you find bugs.
Filed in:
Tags:
bundle matlab snippets syntax highlighting tab completion textmate
Says:
April 20th, 2007 at 04:01 PMThank you very much for this needed MATLAB bundle !
Says:
April 24th, 2007 at 08:33 AMHey Mate, the matlab boundle for textmate is just great ! well done. Just one thing… the control-H doesnt bring bring me to the help. Any clue thanks fabrizio
Says:
April 24th, 2007 at 11:22 AMThanks for the feedback!
fabrizio: When you hit control-h while the caret is in a function name, it should pop up a window with documentation from the Mathworks homepage. Else it should pop up a message saying “Nothing to lookup (hint: place the caret on a function name)”. Didn’t TextMate do anything at all when you hit control-h?
Says:
June 12th, 2007 at 11:04 AMThomas, you are a star. This is head and shoulders above the standard Matlab bundle. We need to get your submission higher up in Google.
Just testing it out the following gives a weird response. I would like to type out a cell array like this:
cell_array={‘first thing’,’second thing’};
but what I end up with is
cell_array = {[‘first thing’,’second thing’};’ … ’]
and of course the … keep going and going. As I’m writing the first speech mark is white, the text “first thing” is blue and the second speech mark is blue as though it were a variable. The third speech mark is purple and the “second thing” text is also purple like a string should be. When I write the fourth speech mark it becomes highlighted in bright purple and then when I press enter after the semi colon it adds another speech mark and some dots and the weird square brackets you can see in the example.
Any ideas?
Thanks again for this bundle - all we need now is a way of plotting from matlab without using X!
Says:
June 12th, 2007 at 11:11 AMThanks for the feedback, Mike. I just committed a fix, which I hope solves the problem. It doesn’t handle, however, hitting enter within the curly brackets. Does that solve the problem you had?
Says:
December 11th, 2007 at 04:53 PMWhere to get your matlab bundle? The link above does not seem to work.
Says:
December 19th, 2007 at 04:15 PMsame here, the link does not work. yet, would love to have the latest version of this running. any help on how to download the bundle would be greatly appreciated. thanks, tobias.
Says:
January 9th, 2008 at 11:04 PMAs of January 9, 2008, the download link is still broken… Help!