unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6869: Octave mode: incorrect "unbalanced block" warning
@ 2010-08-16 23:35 Sprague, Webb (OFM)
  2010-08-17  9:11 ` Stefan Monnier
  2010-08-31 12:24 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Sprague, Webb (OFM) @ 2010-08-16 23:35 UTC (permalink / raw)
  To: 6869

Hi there,

I am getting "unbalanced block" warnings when I hit tab on the
"endfunction" at the end of an m-file (function is cut-and-pasted
below).  It is on windows, but I don't think that is the cause of *this*
bug. I have tested the function and it works fine, so I don't think it
is my octave code.

I also don't think it is because it is an endfunction -- I have gotten
other "unbalanced block" warnings with for loops and such, they are just
harder to duplicate for bug reports.  Usually indentation works fine,
but sometimes it goes wonky for some reason.

(version) gives:

"GNU Emacs 23.2.1 (i386-mingw-nt5.1.2600)
 of 2010-05-08 on G41R2F1"

Thanks to the coders and maintainers for working on this!



function res = tcomp (fn)
  %% res = tcomp (fn)
  %%     imports components and rearranges them.
  
  if nargin ~= 1
	print_usage()
  endif

  data = dlmread(fn, 3, 0);

  x = data(:,2:end);

  cnty = repmat(x(:,1)(:), 10, 1);

  pop = x(:,1:10)(:);
  bir = x(:,11:20)(:);
  dth = x(:,21:30)(:);
  imig = x(:,31:40)(:);
  dmig = x(:,41:50)(:);
  gq = x(:,51:60)(:);
  
  yrs = repmat(2000:2009, 39, 1)(:);

  res = [yrs, cnty, pop, bir, dth, imig, dmig, gq];

endfunction





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6869: Octave mode: incorrect "unbalanced block" warning
  2010-08-16 23:35 bug#6869: Octave mode: incorrect "unbalanced block" warning Sprague, Webb (OFM)
@ 2010-08-17  9:11 ` Stefan Monnier
  2010-08-17 15:34   ` Sprague, Webb (OFM)
  2010-08-31 12:24 ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-08-17  9:11 UTC (permalink / raw)
  To: Sprague, Webb (OFM); +Cc: 6869

> I am getting "unbalanced block" warnings when I hit tab on the
> "endfunction" at the end of an m-file (function is cut-and-pasted
> below).  It is on windows, but I don't think that is the cause of *this*
> bug. I have tested the function and it works fine, so I don't think it
> is my octave code.

It's a bug in octave's indentation code, indeed.  It gets confused by
the "end" in the following line:

>   x = data(:,2:end);

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).
The Octave manual doesn't seem to talk about it.


        Stefan





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6869: Octave mode: incorrect "unbalanced block" warning
  2010-08-17  9:11 ` Stefan Monnier
@ 2010-08-17 15:34   ` Sprague, Webb (OFM)
  2010-08-17 15:44     ` Sprague, Webb (OFM)
  2010-08-18 14:16     ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Sprague, Webb (OFM) @ 2010-08-17 15:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6869

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 ;)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6869: Octave mode: incorrect "unbalanced block" warning
  2010-08-17 15:34   ` Sprague, Webb (OFM)
@ 2010-08-17 15:44     ` Sprague, Webb (OFM)
  2010-08-18 14:16     ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Sprague, Webb (OFM) @ 2010-08-17 15:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 6869

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: 6869@debbugs.gnu.org
> 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 ;)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6869: Octave mode: incorrect "unbalanced block" warning
  2010-08-17 15:34   ` Sprague, Webb (OFM)
  2010-08-17 15:44     ` Sprague, Webb (OFM)
@ 2010-08-18 14:16     ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-08-18 14:16 UTC (permalink / raw)
  To: Sprague, Webb (OFM); +Cc: 6869

>   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.  

Thanks, I see it in the Matlab doc now.  It's missing from the Octave
doc, AFAICT.


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6869: Octave mode: incorrect "unbalanced block" warning
  2010-08-16 23:35 bug#6869: Octave mode: incorrect "unbalanced block" warning Sprague, Webb (OFM)
  2010-08-17  9:11 ` Stefan Monnier
@ 2010-08-31 12:24 ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-08-31 12:24 UTC (permalink / raw)
  To: Sprague, Webb (OFM); +Cc: 6869

> I am getting "unbalanced block" warnings when I hit tab on the
> "endfunction" at the end of an m-file (function is cut-and-pasted
> below).  It is on windows, but I don't think that is the cause of *this*

Can you try the latest code on the Emacs trunk?
It uses a completely different code to navigate and indent Octave code.
The behavior should be similar, except that things like
the removal of octave-forward-block (merged into forward-sexp).
Please confirm if it fixes this bug.
And please report any new bugs separately.


        Stefan





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-08-31 12:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-16 23:35 bug#6869: Octave mode: incorrect "unbalanced block" warning Sprague, Webb (OFM)
2010-08-17  9:11 ` Stefan Monnier
2010-08-17 15:34   ` Sprague, Webb (OFM)
2010-08-17 15:44     ` Sprague, Webb (OFM)
2010-08-18 14:16     ` Stefan Monnier
2010-08-31 12:24 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).