Subject: bug#6869: Octave mode: incorrect "unbalanced block" warning

From: "Sprague, Webb (OFM)" <[email-masked]>
Date: Tue, 17 Aug 2010 08:44:00 -0700

There is another nuance -- Matlab uses "end" for closing blocks only,
while Octave allows "endxxx" where xxx signifies the opening ("endif",
"endfunction" etc).  Octave also allows the plain "end" for blocks.

> -----Original Message-----
> From: Sprague, Webb (OFM)
> Sent: Tuesday, August 17, 2010 8:35 AM
> To: 'Stefan Monnier'
> Cc: [email-masked]
> Subject: RE: bug#6869: Octave mode: incorrect "unbalanced block"
> warning
> 
> Hi Stefan.  See below...
> 
> > It's a bug in octave's indentation code, indeed.  It gets confused
by
> > the "end" in the following line:
> >
> > >   x = data(:,2:end);
> 
> Oh -- that makes sense.
> 
> >
> > I don't know Octave much, as it so happens but I've recently been
> > playing with a new indentation code for Octave (using SMIE), so I'm
> > interested in fixing it.  Could you explain to me what is this "end"
> > (and more generally what the "data(:,2:end)" means: all I can guess
> is
> > that it's an array indexing of some sort).
> 
> There are two uses for "end" that are pretty different:
> 
>   1. Closing blocks (e.g. "if x==1 y=3 end")
> 
>   2. Indexing arrays. Here "end" is evaluated to give the length of a
> dimension in the array. For example  if x=[2 3 4 5], then x(end) == 5,
> x(end-1) == 4, etc.
> 
> Note that ":" means all elements when evaluated as an index, and "x:y"
> gives the vector of elements between x and y, and "3:end" means [3 4 5
> ... end] where end is the max index.  So, "data(:,2:end)" means all
the
> rows of data (the first ":") and the columns from 2 to the end.
> 
> Does that make sense?
> 
> If you really want to learn octave and don't have much experience with
> matlab I would suggest Attaway's book on matlab.  Octave tracks it
> pretty closely.
> 
> Thanks so much for dealing with this!  I sort of have my hands full,
> and emacs indentation code just freaks me out ;)