Le 16 mars 09 à 10:44, Pierre Morel a écrit :
Hello,
I'm trying to enhance the Matlab bundle. Especially by trying to make
matlab and texmate to interact (shortcut to launch a script etc...).
And I must say I'm pretty bad with shell scripts and regular
expressions.
I've nevertheless managed to do that, and now I'm trying to recreate
matlab "cell mode" : matlab source files are scripts, and it is
possible to divide the script in "cells". When you are in the (awful)
matlab editor, you can run the current cell just with cmd+enter. This
is very useful. The problem is that the cell separator is just a line
like this :
%% Title of the new cell
...That's it, there is no ending marker for a cell : the current cell
ends where the new one starts ! What I've done now is creating a new
"cell" scope delimited by these lines, but as soon as one "%% ...."
line is used to mark the end of a scope, it can't be used to start the
following one.
Here's my descriptor.
contentName = 'meta.cell.matlab';
begin = '%%.*$\n';
end = '%%.*$\n';
captures = { 0 = { name = 'meta.celltitle.matlab'; }; };
patterns = (
# Here I include all the other scope descriptors, because they can
be contained in a cell !
)
For my solution to work, I then have to use two of these "%% ..."
lines, one to end the previous cell scope, and one to start the new
one. This means matlab files need to be modified to work, which is not
so good !
Do you have an idea on how to solve this problem ?
A linked problem (but less important) is that I can't get code folding
to work with cells : a start marker can't be the same as an end
marker.
Thank you !
What about look-behind? The expression (?=%%) check that the next two
characters indeed are %%, but don’t consume then. Look-ahead, which
check the previous characters, is written (?<=subexp) and both come
with negative versions — check that the character are *not* something.
More information in the manual:
http://manual.macromates.com/en/regular_expressions
Watch out for grammar bugs, however. It’s easy to make TM crash if
you write things like:
begin = '(?=a)'
end = '(?=b)'
because neither expression consume a character. Thus the expression
ab matches the rule, no character is consumed and the string is left
similar. And still matches the rule, so TM loop.
Édouard GILBERT
edouard.gilbert(a)gmail.com