[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Vim's Ruby indenting

Vincent Foley

5/22/2005 1:51:00 PM

Hi to all the vim users,

I have always used Vim to edit my Ruby code, and I've always been very
grateful that Ruby had both indenting and syntax files. However, the
indenting has started to irritate me lately. It doesn't always indent
the way it should.

In Emacs, when you want to write method(foo, bar, baz) with foo, bar
and baz on separate lines, bar and baz will align themselves with foo.


method(foo,
bar,
baz)

However, with vim, bar will align itself with method not with foo, and
baz will align itself with bar. So you end up with:

method(foo,
bar,
baz)

And you have to manually align the parameters. It's annyoing,
especially if you then decide to reindent the whole file with =G, then
you just ruin the alignment you made and you either need to do it again
or put up with bad style.

Similar bad indenting happens with multiple-lines arrays, hashes,
assignements to the result of an expression such as if or case[1], and
probably other case I'm not thinking of right now.

Does anyone have experience in vim indent files hacking who could maybe
fix those issues, or point me to a good reference on how to fix this?
This is starting to seriously annoy me.

Vincent.

[1]
foo = case bar
when 1: 2
when 2: 3
end

instead of
foo = case bar
when 1: 2
when 2: 3
end

16 Answers

Brian Schröder

5/22/2005 2:19:00 PM

0

>
> [snip]
>
> Does anyone have experience in vim indent files hacking who could maybe
> fix those issues, or point me to a good reference on how to fix this?
> This is starting to seriously annoy me.
>

I just came over from emacs to vim, and this is also the main thing
that annoys me.
With hashes you can get away with
a = {
b => c,
d => e
}

But I don't know about the rest

Best regards,

Brian


--
http://ruby.brian-sch...

Stringed instrument chords: http://chordlist.brian-sch...


Thomas

5/23/2005 7:46:00 AM

0

Vincent Foley

5/23/2005 4:14:00 PM

0

Yes, I do. And I have this version installed.

Vincent Foley

5/23/2005 4:20:00 PM

0

Ah no, I did not. Thought I did. I used the new version and it fixed
the method parameters problem. However, the myvar = case foo still
breaks on the next line.

Nikolai Weibull

5/23/2005 4:58:00 PM

0

Vincent Foley wrote:

> However, the myvar = case foo still breaks on the next line.

Iâ??ll add support for this at a later time. Until then, consider
rethinking writing code that uses the case statement in this manner,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Brian Schröder

5/23/2005 6:24:00 PM

0

On 23/05/05, Nikolai Weibull
<mailing-lists.ruby-talk@rawuncut.elitemail.org> wrote:
> Vincent Foley wrote:
>
> > However, the myvar = case foo still breaks on the next line.
>
> I'll add support for this at a later time. Until then, consider
> rethinking writing code that uses the case statement in this manner,
> nikolai

I like this kind of code.

a = case b
when 1: 10
when 2: 20
else 50
end

makes it clear that something is assigned to a. While

case b
when 1: a = 10
when 2: a = 20
else a = 50
end

does not make this important fact as clear on first sight.

best regards,

Brian

--
http://ruby.brian-sch...

Stringed instrument chords: http://chordlist.brian-sch...


Nikolai Weibull

5/23/2005 10:22:00 PM

0

Brian Schröder wrote:

> > > However, the myvar = case foo still breaks on the next line.

> > I'll add support for this at a later time. Until then, consider
> > rethinking writing code that uses the case statement in this manner,

> I like this kind of code.

> a = case b
> when 1: 10
> when 2: 20
> else 50
> end

> makes it clear that something is assigned to a.

Sure, but tell me a reasonable way to indent it and provide me with the
code to do it and Iâ??ll add it immediately. Adding something like this
will require changes that will ripple through the whole indentation
code. People seem to think that indentation is a simple matter.
Perhaps they should give it a try sometime. Coming up with a reasonable
Ruby indentation definition took me two weeks of hard work and heavy
thinking. Neither Ruby nor Vim is very friendly to do this kind of
stuff for. Another deterrent thing is that people complain when it
doesnâ??t work but keep very quiet when it does,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Gavin Sinclair

5/23/2005 11:29:00 PM

0

Brian Schröder wrote:
>
> I like this kind of code.
>
> a = case b
> when 1: 10
> when 2: 20
> else 50
> end
>
> makes it clear that something is assigned to a. While
>
> case b
> when 1: a = 10
> when 2: a = 20
> else a = 50
> end
>
> does not make this important fact as clear on first sight.

The following code indents properly and is what I use.

a =
case b
when 1: 10
when 2: 20
else 50
end

To follow up Vincent's comments: to try your hand at this, there's no
shortcut; just read the Vim help files on indenting and general Vim
programming (it's fugly), and hack around with the existing
highlighting code. I don't understand it myself. Indenting Ruby is
Hard with a capital H. Writing the logic in the 10th-rate programming
language that is VimScript (or whatever they call it) is insane, but
Nikolai has done a great job.

I doubt it will ever improve to the point that gg=G is advisable on a
large file, though. I always indent one unit-of-code (e.g.
block/method/class) at a time.

Cheers,
Gavin

Sam Roberts

5/23/2005 11:43:00 PM

0

Quoting gsinclair@gmail.com, on Tue, May 24, 2005 at 08:30:17AM +0900:
> To follow up Vincent's comments: to try your hand at this, there's no
> shortcut; just read the Vim help files on indenting and general Vim
> programming (it's fugly), and hack around with the existing
> highlighting code. I don't understand it myself. Indenting Ruby is
> Hard with a capital H. Writing the logic in the 10th-rate programming
> language that is VimScript (or whatever they call it) is insane, but
> Nikolai has done a great job.

I wonder whether using Syntax, based on the ruby parser, would allow an
external tool to be written (in ruby...) that would do better. Down side
is it wouldn't indent as you type, upside is you could set indentprg,
and run the whole file through it.

Nikolai has performed miracles, but it almost seems like an excercise in
coding in Brainfuck, or some similar language.

Sam



Vincent Foley

5/24/2005 2:40:00 AM

0

Oh, don't get me wrong, I definitly appreciate what you did. I once
tried to modify the file, but VimScript is absolutely the worst
language I've ever seen, so kudos to you for doing it.