eRuby indenting capabilities

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

eRuby indenting capabilities

Doug Kearns
Tim,

I was just giving the new indent script a quick test drive prior to the
next release and noticed that the following example doesn't work as I'd
expect.

<%
if true
%>
foobar
<%
end
%>

is indented as:

<%
  if true
%>
foobar
<%
    end
  %>

It also appears that the Ruby code will only be indented correctly when
the <%,%> delimiters are on lines by themselves?

eg. the following isn't transformed at all when running the
filter/indent motion over it.

<% if true
foobar
end %>


Am I misunderstanding its current capabilities?

Thanks,
Doug
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: eRuby indenting capabilities

Tim Pope-2
On Tue, Dec 05, 2006 at 02:00:17AM +1100, Doug Kearns wrote:

> Tim,
>
> I was just giving the new indent script a quick test drive prior to the
> next release and noticed that the following example doesn't work as I'd
> expect.
>
> <%
> if true
> %>
> foobar
> <%
> end
> %>
>
> is indented as:
>
> <%
>   if true
> %>
> foobar
> <%
>     end
>   %>

First, the end block should of course be

<%
  end
%>

This is what I get.  Do your results differ or was this a copy and
paste error?

> It also appears that the Ruby code will only be indented correctly when
> the <%,%> delimiters are on lines by themselves?
>
> eg. the following isn't transformed at all when running the
> filter/indent motion over it.
>
> <% if true
> foobar
> end %>
>
>
> Am I misunderstanding its current capabilities?

Pretty much :).  I've supported the most common conventions.  For
example, your first example would work fine if written as

<% if true %>
  foobar
<% end %>

It would of course be ideal to support your examples as well but
implementing them would require some heavy modifications to
indent/ruby.vim (and perhaps indent/html.vim as well).  Since they
are apparently quite rare in the code I've worked with, I'm cheerfully
refraining from the task.

Cheers,
Tim
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: eRuby indenting capabilities

Doug Kearns
On Mon, Dec 04, 2006 at 11:05:41AM -0600, Tim Pope wrote:

> On Tue, Dec 05, 2006 at 02:00:17AM +1100, Doug Kearns wrote:
> > Tim,
> >
> > I was just giving the new indent script a quick test drive prior to the
> > next release and noticed that the following example doesn't work as I'd
> > expect.
> >
> > <%
> > if true
> > %>
> > foobar
> > <%
> > end
> > %>
> >
> > is indented as:
> >
> > <%
> >   if true
> > %>
> > foobar
> > <%
> >     end
> >   %>
>
> First, the end block should of course be
>
> <%
>   end
> %>
>
> This is what I get.  Do your results differ or was this a copy and
> paste error?

No, I'm seeing 2 indent levels for the "end" and one for the "%>".  In
fact, if I repeatedly indent this the final "%>" alternates between 1
and 0 levels of indent.
 
<snip>
 
> It would of course be ideal to support your examples as well but
> implementing them would require some heavy modifications to
> indent/ruby.vim (and perhaps indent/html.vim as well).  Since they
> are apparently quite rare in the code I've worked with, I'm cheerfully
> refraining from the task.

Fair enough...just checking. ;-)

Thanks,
Doug
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: eRuby indenting capabilities

Tim Pope-2
On Tue, Dec 05, 2006 at 05:37:48AM +1100, Doug Kearns wrote:

> On Mon, Dec 04, 2006 at 11:05:41AM -0600, Tim Pope wrote:
> > On Tue, Dec 05, 2006 at 02:00:17AM +1100, Doug Kearns wrote:
> > > Tim,
> > >
> > > I was just giving the new indent script a quick test drive prior to the
> > > next release and noticed that the following example doesn't work as I'd
> > > expect.
> > >
> > > <%
> > > if true
> > > %>
> > > foobar
> > > <%
> > > end
> > > %>
> > >
> > > is indented as:
> > >
> > > <%
> > >   if true
> > > %>
> > > foobar
> > > <%
> > >     end
> > >   %>
> >
> > First, the end block should of course be
> >
> > <%
> >   end
> > %>
> >
> > This is what I get.  Do your results differ or was this a copy and
> > paste error?
>
> No, I'm seeing 2 indent levels for the "end" and one for the "%>".  In
> fact, if I repeatedly indent this the final "%>" alternates between 1
> and 0 levels of indent.

Okay, after a little investigating, I found the cause, and I've had to
add a special case for an eRuby block with "end" as its first line.
After a couple of other minor tweaks here is the new indenting style
for the above example:

<%
  if true
  %>
  foobar
  <%
  end
%>

I'm not exactly sure what the correct behavior is for this example but
the above was easy to implement and seems reasonable.

I've kept the changes minimal to hopefulyl avoid a broken release.  If
anyone finds any problems let me know.

Tim
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel