ERuby indenting

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

ERuby indenting

Tim Pope-2
Hi all,

I have written and attached an ERuby indent plugin.  It outsources
most of the heavy lifting to the HTML and Ruby indent plugins, and
works quite well.  I would think it would be appropriate for inclusion
in vim-ruby.

I emailed this to Doug Kearns a bit earlier (and have not received a
response), but have since decided this list would be a more
appropriate place to share it.

Enjoy,
Tim Pope

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

eruby.vim (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ERuby indenting

Doug Kearns
Thanks for this Tim!

Folks, I've just added Tim as a developer to the project and he's taking
ownership of the eRuby indent file.  Now we'll have an indent script
that actually does something useful with the Ruby code. ;-)

Regards,
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

Nikolai Weibull-11
In reply to this post by Tim Pope-2
On 11/7/06, Tim Pope <[hidden email]> wrote:
> Hi all,
>
> I have written and attached an ERuby indent plugin.  It outsources
> most of the heavy lifting to the HTML and Ruby indent plugins, and
> works quite well.  I would think it would be appropriate for inclusion
> in vim-ruby.

Perhaps the regular expressions used in indent/ruby.vim should be made
available to the indent/eruby.vim script as well, to avoid
duplication.

  nikolai
_______________________________________________
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

Tim Pope-2
Hi, thanks for the response, and your work on indent/ruby.vim!

On Wed, Nov 08, 2006 at 02:54:38PM +0100, Nikolai Weibull wrote:
> Perhaps the regular expressions used in indent/ruby.vim should be made
> available to the indent/eruby.vim script as well, to avoid
> duplication.

This sounds like a good idea.  At the same time, it seems like more
trouble than it's worth.  There are only a couple of patterns
eruby.vim uses, and they don't directly match up with the patterns in
ruby.vim.  You'd need to factor out the differences and complicating
matters this way doesn't seem prudent for a couple of short patterns
that are rather unlikely to change.  If eruby.vim becomes more
sophisticated this is definitely worth considering.

I have a couple of questions regarding your indent/ruby.vim myself.
Are you particularly attached to the method of lining up parentheses?
I have altered my local copy to make it possible to disable
(g:rubyindent_match_parentheses) and instead use the brace/bracket
behavior.  Given that the indent doesn't restore properly on the line
after the closing parenthesis, I'd be quite satisfied to just see the
behavior eliminated altogether.  I could furnish a patch for this as
well (or just alter and commit directly) if you are open to it.

On a related note, ) and ] probably belong in indentkeys.

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

Thomas Adam-5
On Wed, Nov 08, 2006 at 02:24:28PM -0600, Tim Pope wrote:
> Hi, thanks for the response, and your work on indent/ruby.vim!
>
> I have altered my local copy to make it possible to disable
> (g:rubyindent_match_parentheses) and instead use the brace/bracket
> behavior.  Given that the indent doesn't restore properly on the line
> after the closing parenthesis, I'd be quite satisfied to just see the
> behavior eliminated altogether.  I could furnish a patch for this as
> well (or just alter and commit directly) if you are open to it.

I'd prefer this, as it does cause a lot of problem in fringe cases where
there's different sets of parenthesis split over different lines.  I too
have a patch for that, but I'll let you do it against your own file.
 
-- Thomas Adam

--
"Wanting to feel; to know what is real.  Living is a lie." -- Purpoise
Song, by The Monkees.
_______________________________________________
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

Nikolai Weibull-11
In reply to this post by Tim Pope-2
On 11/8/06, Tim Pope <[hidden email]> wrote:
> Hi, thanks for the response, and your work on indent/ruby.vim!

No problem :-).

> On Wed, Nov 08, 2006 at 02:54:38PM +0100, Nikolai Weibull wrote:
> > Perhaps the regular expressions used in indent/ruby.vim should be made
> > available to the indent/eruby.vim script as well, to avoid
> > duplication.
>
> This sounds like a good idea.  At the same time, it seems like more
> trouble than it's worth.  There are only a couple of patterns
> eruby.vim uses, and they don't directly match up with the patterns in
> ruby.vim.  You'd need to factor out the differences and complicating
> matters this way doesn't seem prudent for a couple of short patterns
> that are rather unlikely to change.  If eruby.vim becomes more
> sophisticated this is definitely worth considering.

Sounds like your right.

> I have a couple of questions regarding your indent/ruby.vim myself.
> Are you particularly attached to the method of lining up parentheses?

?  Do you mean as in

def some_method(param1,
                param2)
  <

or what?  Writing

def some_method(param1,
                param2
               )
               <

is bugged though, because it's assumed that the ) closes something.
This is stupid, though, and the ) shouldn't be considered special.
I'll check what's causing this some day or other.

> I have altered my local copy to make it possible to disable
> (g:rubyindent_match_parentheses) and instead use the brace/bracket
> behavior.  Given that the indent doesn't restore properly on the line
> after the closing parenthesis, I'd be quite satisfied to just see the
> behavior eliminated altogether.  I could furnish a patch for this as
> well (or just alter and commit directly) if you are open to it.

Please show the problem and the solution.

> On a related note, ) and ] probably belong in indentkeys.

They already are.

  nikolai
_______________________________________________
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

Tim Pope-2
On Wed, Nov 08, 2006 at 10:31:10PM +0100, Nikolai Weibull wrote:

> On 11/8/06, Tim Pope <[hidden email]> wrote:
> > I have a couple of questions regarding your indent/ruby.vim myself.
> > Are you particularly attached to the method of lining up parentheses?
>
> ?  Do you mean as in
>
> def some_method(param1,
>                 param2)
>   <
>
> or what?  Writing
>
> def some_method(param1,
>                 param2
>                )
>                <
>
> is bugged though, because it's assumed that the ) closes something.
> This is stupid, though, and the ) shouldn't be considered special.
> I'll check what's causing this some day or other.
The second example is one of the problem cases.  Here is another:

ActiveRecord::Base.establish_connection(
                                        :adapter => 'sqlite3',
                                        :database => 'foo.sqlite3')
                                       <

Notice that it also breaks if the opening parentheses ends the first
line.

My ideal outcome would actually be something like:

ActiveRecord::Base.establish_connection(
  :adapter => 'sqlite3',
  :database => 'foo.sqlite3'
)
<

This is a common case I run into.  With a very long method call, I
want to start the arguments on a separate line so I can have more
room.  Instead, I am treated to being in the exact same column that I
was already in.  I have to manually correct for this, and then
manually correct again when closing the parentheses.  Very tedious
with such a large indent.

After seeing your example it's apparent there are two different use
cases here.

very_long_method_name(
  bar,
  baz
)

short(foo,
      bar)

Perhaps the ideal solution is to optimize for my case when the line
ends with an opening parenthesis, and your case when it is followed
with further characters.  I have no idea how difficult this is to
implement but I think it would leave all parties happy.  (Further
input from others on this is welcome.)

> > I have altered my local copy to make it possible to disable
> > (g:rubyindent_match_parentheses) and instead use the brace/bracket
> > behavior.  Given that the indent doesn't restore properly on the line
> > after the closing parenthesis, I'd be quite satisfied to just see the
> > behavior eliminated altogether.  I could furnish a patch for this as
> > well (or just alter and commit directly) if you are open to it.
>
> Please show the problem and the solution.

I have attached a patch.  While it would pacify me, I think it would
probably be better to instead pursue the goal I outlined above.

> > On a related note, ) and ] probably belong in indentkeys.
>
> They already are.

Err, apparently I should be sending that to myself, as they are
missing from eruby.vim, not yours.

Cheers,
Tim

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

rubyindent_parens.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ERuby indenting

Tim Pope-2
> Perhaps the ideal solution is to optimize for my case when the line
> ends with an opening parenthesis, and your case when it is followed
> with further characters.  I have no idea how difficult this is to
> implement but I think it would leave all parties happy.  (Further
> input from others on this is welcome.)

I have gone ahead and implemented this.  Attached is a patch.

Cheers,
Tim

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

rubyindent_parens2.patch (995 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ERuby indenting

Nikolai Weibull-11
In reply to this post by Tim Pope-2
On 11/9/06, Tim Pope <[hidden email]> wrote:

> On Wed, Nov 08, 2006 at 10:31:10PM +0100, Nikolai Weibull wrote:
> > On 11/8/06, Tim Pope <[hidden email]> wrote:
> > > I have a couple of questions regarding your indent/ruby.vim myself.
> > > Are you particularly attached to the method of lining up parentheses?
> >
> > ?  Do you mean as in
> >
> > def some_method(param1,
> >                 param2)
> >   <
> >
> > or what?  Writing
> >
> > def some_method(param1,
> >                 param2
> >                )
> >                <
> >
> > is bugged though, because it's assumed that the ) closes something.
> > This is stupid, though, and the ) shouldn't be considered special.
> > I'll check what's causing this some day or other.
>
> The second example is one of the problem cases.  Here is another:
>
> ActiveRecord::Base.establish_connection(
>                                         :adapter => 'sqlite3',
>                                         :database => 'foo.sqlite3')
>                                        <
>
> Notice that it also breaks if the opening parentheses ends the first
> line.
>
> My ideal outcome would actually be something like:
>
> ActiveRecord::Base.establish_connection(
>   :adapter => 'sqlite3',
>   :database => 'foo.sqlite3'
> )
> <
>
> This is a common case I run into.  With a very long method call, I
> want to start the arguments on a separate line so I can have more
> room.  Instead, I am treated to being in the exact same column that I
> was already in.  I have to manually correct for this, and then
> manually correct again when closing the parentheses.  Very tedious
> with such a large indent.
>
> After seeing your example it's apparent there are two different use
> cases here.
>
> very_long_method_name(
>   bar,
>   baz
> )
>
> short(foo,
>       bar)
>
> Perhaps the ideal solution is to optimize for my case when the line
> ends with an opening parenthesis, and your case when it is followed
> with further characters.  I have no idea how difficult this is to
> implement but I think it would leave all parties happy.  (Further
> input from others on this is welcome.)

Yes, that sounds reasonable.  I'll add a case for when a method call ends with (

  nikolai
_______________________________________________
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

Nikolai Weibull-11
In reply to this post by Tim Pope-2
On 11/9/06, Tim Pope <[hidden email]> wrote:
> > Perhaps the ideal solution is to optimize for my case when the line
> > ends with an opening parenthesis, and your case when it is followed
> > with further characters.  I have no idea how difficult this is to
> > implement but I think it would leave all parties happy.  (Further
> > input from others on this is welcome.)
>
> I have gone ahead and implemented this.  Attached is a patch.

Ah, thanks.  :-)

  nikolai
_______________________________________________
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

Tim Pope-2
On Thu, Nov 09, 2006 at 09:30:35AM +0100, Nikolai Weibull wrote:
> > I have gone ahead and implemented this.  Attached is a patch.
>
> Ah, thanks.  :-)

Great, I take this you approve.  Doug and I were contemplating doing
another release in the next few days to show off the new
indent/eruby.vim.  I would be thrilled if this patch could make it in.
I can commit it and update the ChangeLog too if you'd like.

Here's a bit of code that illustrates two cases with incorrect
indenting if the current plugin has its way (try them out with gg=G).
The first is tricky and the second is downright pathological, but I
thought I'd share anyways.  I may investigate the first at a later
time.

class Hash

  class Foo; def bar; nil; end; end

  alias old_writer []= unless instance_methods.include?(:old_writer)

end

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

Nikolai Weibull-11
On 11/9/06, Tim Pope <[hidden email]> wrote:
> On Thu, Nov 09, 2006 at 09:30:35AM +0100, Nikolai Weibull wrote:
> > > I have gone ahead and implemented this.  Attached is a patch.
> >
> > Ah, thanks.  :-)
>
> Great, I take this you approve.  Doug and I were contemplating doing
> another release in the next few days to show off the new
> indent/eruby.vim.  I would be thrilled if this patch could make it in.
> I can commit it and update the ChangeLog too if you'd like.

Do so.  The less I have to do the better :-).  Also, someone seems to
have put tabs in the script.  (Or they've been there all along).
You're free to replace them with the appropriate number of spaces.
I've decided that tabs are a hack and I don't use them any more.  Let
the flame-war begin.

  nikolai
_______________________________________________
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

Tim Pope-2
On Thu, Nov 09, 2006 at 09:25:24PM +0100, Nikolai Weibull wrote:
> Do so.  The less I have to do the better :-).  Also, someone seems to

Done.

> have put tabs in the script.  (Or they've been there all along).
> You're free to replace them with the appropriate number of spaces.
> I've decided that tabs are a hack and I don't use them any more.  Let
> the flame-war begin.

I find tabs to be more trouble as their worth as well.  However, my
understanding is that Bram prefers them to help keep the size of
runtime files down.  While I dislike tabs, Vim makes it just easy
enough that I'm willing to oblige (my biggest issues arise when having
to deal with non-Vim users/environments).

I have gone so far as to add a modeline specifying 'noet' to
indent/ruby.vim when I committed the patch.  Feel free to remove it; I
have no stake in the matter.

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

Nikolai Weibull-11
On 11/9/06, Tim Pope <[hidden email]> wrote:

> On Thu, Nov 09, 2006 at 09:25:24PM +0100, Nikolai Weibull wrote:
> > Do so.  The less I have to do the better :-).  Also, someone seems to
>
> Done.
>
> > have put tabs in the script.  (Or they've been there all along).
> > You're free to replace them with the appropriate number of spaces.
> > I've decided that tabs are a hack and I don't use them any more.  Let
> > the flame-war begin.
>
> I find tabs to be more trouble as their worth as well.  However, my
> understanding is that Bram prefers them to help keep the size of
> runtime files down.  While I dislike tabs, Vim makes it just easy
> enough that I'm willing to oblige (my biggest issues arise when having
> to deal with non-Vim users/environments).

Bram can be a bit overzealous at times (no offense meant - he's right
most of the time).  I have a hard time believing that tab
space-compression-scheme saves us anything over what gzip/bzip2 do.
Especially considering that we're messing up the huffman coding.

> I have gone so far as to add a modeline specifying 'noet' to
> indent/ruby.vim when I committed the patch.  Feel free to remove it; I
> have no stake in the matter.

Ooh, no modelines please.  Modelines are bad, mkay.  Hm, seems like
most files in vim-ruby do have them, though...

As the file seems to be tabs throughout, let's leave it at that then.

  nikolai
_______________________________________________
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

Tim Pope-2
On Thu, Nov 09, 2006 at 11:01:40PM +0100, Nikolai Weibull wrote:
> Bram can be a bit overzealous at times (no offense meant - he's right
> most of the time).  I have a hard time believing that tab
> space-compression-scheme saves us anything over what gzip/bzip2 do.
> Especially considering that we're messing up the huffman coding.

I think the concern is uncompressed, not compressed size.

> Ooh, no modelines please.  Modelines are bad, mkay.  Hm, seems like
> most files in vim-ruby do have them, though...

While I've seen some horrible abuses of modelines (in one plugin I
even saw t_vb=), This seems like an appropriate use.  We both likely
have expandtab set by default for the vim filetype; this modeline
allows for one exception without worrying about having to remember it.

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