David Vallner
2/10/2006 6:50:00 PM
Dna Piatok 10 Február 2006 19:27 Diego Cano Lagneaux napísal:
> En Fri, 10 Feb 2006 19:15:10 +0100, Edward Faulkner <ef@alum.mit.edu>
>
> escribió:
> > On Sat, Feb 11, 2006 at 03:05:26AM +0900, Diego Cano Lagneaux wrote:
> >> The other day, I stumbed across the need to reindent some ruby code.
> >
> > Any worthwhile editor should have a Ruby mode that handles indenting
> > for you.
> >
> > (In emacs, use M-x indent-region)
> >
> > regards,
> > Ed
>
> I am aware that it should (I use Vim, by the way), but it doesn't. I have
> all imaginable variables in my .vimrc (indent on, smartindent, etc.), but
> all I have is syntax colours, no autoindentation.
>
Weird, last time I used Vim, it worked fine in this respect. But that was GVim
back in Windows times, and both the Windows Vim and XEmacs seem to come with
slightly more sensible defaults in some respects.
> It's not a big problem for the code I write now, since I am quite careful
> with correct indentation and all; but for old messy code, it could help me
> a lot to have a auto-reindenter, and even better, a code beautifier
> limiting code to 80 columns, uniformising spaces after commas and all this.
>
Bite into the bitter pill and have an emacs in batch mode chomp over your old
code? Although it might not quite work, the emacs ruby-mode doesn't quite
support auto-fill-mode (the code to limit code to a set page width) properly,
or handle multi-line comments and such.
And a pure ruby source code beautifier for Ruby does sound interesting, but
there are some pitfalls - especially in the page width limitation when
determining where to put a line break.
Wasn't there a project to make a self-hosting Ruby? You might want to have a
look at how far they got and possibly rip... err... -borrow- their Ruby
parser, and then just write a pretty printer for their code model to save
yourself a lot of work?
David Vallner