I need a code beautifier or formatter

Hi,

···

— Michael Neumann mneumann@ntecs.de wrote:

On Sat, Jun 14, 2003 at 10:01:36PM +0900, Joao > Pedrosa wrote:

Hello,

I have some source code that is terribly
formatted. It needs some good
indentation at least. But I am too lazy to do it
all by hand.

Does anyone know a tool to do the job ?

Vim can format Ruby code (visual select then press
’=’).

Regards,

Michael

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?

Thanks Michael,
Joao

You can try to update your indent file:
http://www.soyabean.com.au/gavin/vim/index.html

Works for me most of the time, but sometimes there’s problems w/

def foo
class << anObject; self end

thinks def foo is closed now and colors are wrong from now on

and

bla do |x|
#sometimes indentation fails here???
#and ‘end’ is mistakenly aligned with the outer scope, e.g. def foo

···

On Sat, Jun 14, 2003 at 11:33:43PM +0900, Joao Pedrosa wrote:

Hi,

— Michael Neumann mneumann@ntecs.de wrote:

On Sat, Jun 14, 2003 at 10:01:36PM +0900, Joao > > Pedrosa wrote:

Hello,

I have some source code that is terribly
formatted. It needs some good
indentation at least. But I am too lazy to do it
all by hand.

Does anyone know a tool to do the job ?

Vim can format Ruby code (visual select then press
’=’).

Regards,

Michael

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
’_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Are Linux users lemmings collectively jumping off of the cliff of
reliable, well-engineered commercial software?
– Matt Welsh

I tried the ‘=’ in VIM and the indent then got screwed up…

Michael, How does your .vimrc look ?

···

On Sun, 15 Jun 2003 00:33:43 +0900, Joao Pedrosa wrote:

— Michael Neumann mneumann@ntecs.de wrote:

Vim can format Ruby code (visual select then press
’=’).

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?


Simon Strandgaard

“Joao Pedrosa” joaopedrosa@myrealbox.com wrote in message
news:1055601220.9254.8.camel@localhost.localdomain…

Hi,

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?

Thanks Michael,
Joao

I use vim for my ruby coding. I set smartindent on as well–not sure how
much difference that makes for ruby. It mostly does the right thing, but…

The problem is that it will end up completely in the weeds after it gets one
line wrong (since vim indents seem to be very much based on what the
previous line was). I’ve found I can’t indent too many lines at once
without this happening. So I don’t find I can use gg=G without being
unhappy.

Some things that aren’t necessarily ‘wrong’, but aren’t how I like them:

foo = "someverylongstring and some other "+
“something else”

The “something else” just lines up with the previous line. I’d like to see
it indented. Same goes for any non-complete line.

bar = some_method(afjdksajk, gjfrjeje, fjdkjska,
dfjkdsjk, ss)

I’d like for this to have the second line line up with the open paren.
Basically, I want things to work how ruby-mode for emacs works but I want to
use vim :slight_smile:

There are just two things I miss from emacs now that I’ve made the switch:
psgml-mode, and the near certainty that emacs indent will tell me when I’ve
goofed something up and make it look just how I like it.

xemacs -batch myprog.rb -eval ‘(indent-region (point-min) (point-max)
nil)’ -f save-buffer -kill

This thread is useful to me though, as I can just define a vim map that will
run the buffer through emacs batch mode and get it how I like it :slight_smile: Thanks,
Tim, for the tip!

I thought about this not long ago, while working on a piece of software along
with several others, all with their own special little way of formatting (a
multi-language project, java, C/C++, C# and ruby mostly) trying to identify
important changes from cvs logs was a pain in the *** after the different
editors and different code styles messed things up. It ended up so bad
eventually that something had to be done, forcing everyone to write in the
same fashion would waste time and probably dampen productivity.

Everything that was to be commited to the cvs had to be passed through
indentation programs, astyle and gnu indent covered C/C++/java but we didn’t
find any such utilities for Ruby and C# (which had a visual impact on the
project scheduled after analyzing progress reports).

afaik, there is no such application for Ruby (as a sidenote, any handwritten
ruby lexer in ruby? :wink: perhaps it is time for the development of such an
application? Personally I’d love to be able to atleast format around the
differences in block structures ( {} compared to do … etc.), the obvious
depth-indentation and probably a few other things I can’t seem to remember
right now :slight_smile:

/ Björn Ståhl

···

On Saturday 14 June 2003 16.33, Joao Pedrosa wrote:

Hi,

— Michael Neumann mneumann@ntecs.de wrote:

On Sat, Jun 14, 2003 at 10:01:36PM +0900, Joao > > > > Pedrosa wrote:

Hello,

I have some source code that is terribly

formatted. It needs some good

indentation at least. But I am too lazy to do it

all by hand.

Does anyone know a tool to do the job ?

Vim can format Ruby code (visual select then press
’=’).

Regards,

Michael

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?

Thanks Michael,
Joao

On Mon, 16 Jun 2003 03:29:21 +0900, Brett Williams wrote something resembling:

“Joao Pedrosa” joaopedrosa@myrealbox.com wrote in message
news:1055601220.9254.8.camel@localhost.localdomain…

Hi,

Vim did format it, but not as expected. It doesn’t even indent
correctly for me. Anyone can confirm that it doesn’t work properly ?

Thanks Michael,
Joao

I use vim for my ruby coding. I set smartindent on as well–not sure how
much difference that makes for ruby. It mostly does the right thing, but…

The problem is that it will end up completely in the weeds after it gets one
line wrong (since vim indents seem to be very much based on what the
previous line was). I’ve found I can’t indent too many lines at once
without this happening. So I don’t find I can use gg=G without being
unhappy.

Some things that aren’t necessarily ‘wrong’, but aren’t how I like them:

foo = "someverylongstring and some other "+
“something else”

The “something else” just lines up with the previous line. I’d like to see
it indented. Same goes for any non-complete line.

bar = some_method(afjdksajk, gjfrjeje, fjdkjska,
dfjkdsjk, ss)

if i get my mind of coding my web pages any time soon i’m going to add
support for this to the ruby indenter. i’m not the maintainer of it
though. the code for this already exists in the Makefile indenter,
which i currently maintain. so stay tuned ;-).

enjoy,
nikolai

···


::: name: Nikolai Weibull :: aliases: pcp / lone-star :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,php,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)[“have”]+“fun”-97);}

Some things that aren’t necessarily ‘wrong’, but aren’t how I like them:

foo = "someverylongstring and some other "+
“something else”

The “something else” just lines up with the previous line. I’d like to see
it indented. Same goes for any non-complete line.

bar = some_method(afjdksajk, gjfrjeje, fjdkjska,
dfjkdsjk, ss)

FWIW, here’s how the emacs ruby-mode indents that:

foo = “something long” +
“something else”

bar = some_method(afjdksajk, gjfrjeje, fjdkjska,
dfjkdsjk, ss)