[ANN] FormatR 1.06

But after using Ruby for a year, seeing that in C/C++
doesn’t bother me as much. (In fact, the brace on the first
line is a coding standard for the bsd kernel, so I guess
it must not be all that bad. :slight_smile:

And Niklaus Wirth used to do it in Pascal (which
he invented). I just never cared for it. I like
to see things match vertically.

Also, this style has never bothered me in Ruby. I’m not sure why.

Likewise. I think it’s because Ruby forces you
to do it that way, which could be an annoyance if
you don’t like it; but Ruby has sooo many features
that compensate for that.

For an analogy: Suppose knuckle-cracking annoys
you. If Roseanne Barr sat in your living room
cracking her knuckles, you’d be highly annoyed.
But if Kate Moss did it, you wouldn’t mind so much.

Hal

···

----- Original Message -----
From: “Jim Freeze” jim@freeze.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, July 31, 2002 5:47 PM
Subject: Re: Style question

What’s really unfortunate, though, is that Vim has some killer features
dealing with {…} blocks (on account of its C heritage and the plain
ubiqity of such blocks.

For example, you can delete, change, indent, or do whatever you like to the
contents of {…} (or (…), […], etc.) in an instant, no matter where
the
cursor is in the block.

Obviously, this functionality does not apply to do…end blocks. Despite
this loss, I still use do…end because it seems more fitting for Ruby.

If you can’t indent a do-end block by starting at the “do” line and
typing “>/end^M” then I might be willing to go out on a limb and
say that your block is trying to do too much and needs to be
refactored.

:wink:

Seriously, no offense meant.

– Dossy

That’s a fair point, and I would never (admit to) having a do…end block of
more than 10 lines! :wink:

Anyway, by “indenting a block” I meant “correcting the indentation”, not
“increasing the indent”. The former is handy when you’ve moved some code into
the do…end block and require all the indentation to be fixed up.

–Gavin “imap endcc” Sinclair

···

----- Original Message -----
From: “Dossy” dossy@panoptic.com

On 2002.08.01, Gavin Sinclair gsinclair@soyabean.com.au wrote:

My experience is that 99% of people use mixed tabs and spaces.
So the result is that you get no-ones preferences. :slight_smile:

···

On Thu, Aug 01, 2002 at 06:21:40AM +0900, Albert Wagner wrote:

On Wednesday 31 July 2002 11:07 am, Jim Freeze wrote:

I have chosen the lowest common demoninator, ie, I use spaces
instead of tabs and I use {} instead of do end. This lets
me edit easily whether I use vi, vim, gvim, emacs,
emacs+ruby extensions, etc, and have my code still look uniform
in any editor,

This is fine if you do not expect to share your code with others who choose
not to use vim. There are actually two common denominators: one for your own
ease and one for others. Tabs allow others to view with their own
preferences. Some use two spaces, some four, etc. for a tab. Spaces force
others to use your preferences.


Jim Freeze
If only I had something clever to say for my comment…
~

But by forcing a way ruby avoids any flamewar about how to do it :wink:

-billy.

···

On Thu, Aug 01, 2002 at 07:58:34AM +0900, Hal E. Fulton wrote:

From: “Jim Freeze” jim@freeze.org
Sent: Wednesday, July 31, 2002 5:47 PM

Also, this style has never bothered me in Ruby. I’m not sure why.

Likewise. I think it’s because Ruby forces you
to do it that way, which could be an annoyance if
you don’t like it; but Ruby has sooo many features
that compensate for that.


Meisterbohne Söflinger Straße 100 Tel: +49-731-399 499-0
eLösungen 89077 Ulm Fax: +49-731-399 499-9

Anyway, by “indenting a block” I meant “correcting the indentation”,
not “increasing the indent”. The former is handy when you’ve moved
some code into the do…end block and require all the indentation to
be fixed up.

True. Vim’s = (reindent) doesn’t Do The Right Thing for me and
especially breaks when do/end is used instead of {}.

Before:

[1, 2, 3].each do |x|
    p x
        p x
end

After =4j:

[1, 2, 3].each do |x|
p x
p x
end

Before:

[1, 2, 3].each { |x|
    p x
        p x
}

After =4j:

[1, 2, 3].each { |x|
    p x
        p x
}

Not very useful in either case. At least in the do/end, once it
unindents everything on you, you could go in and manually reindent
with >> …

–Gavin “imap endcc” Sinclair

Ah, you must be one of those Gvim-using weirdos. In my world,
there is no … holding shift and pressing enter still
generates 0x0A.

– Dossy

···

On 2002.08.12, Gavin Sinclair gsinclair@soyabean.com.au wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

For some reason that seems to be the default in a lot of installations of
xemacs that other people around here use. This whole topic seems to be a
longstanding flame subject, too. It is well summed up here:
http://www.jwz.org/doc/tabs-vs-spaces.html

···

On Thu, Aug 01, 2002 at 06:50:55AM +0900, Jim Freeze wrote:

My experience is that 99% of people use mixed tabs and spaces.
So the result is that you get no-ones preferences. :slight_smile:


moved

I used to know the answer to that one, before I ate so many preservatives…
(Zippy)

Hmmm. I believe emacs can be made to EAT UP little innocent spaces and
comvert them to tabs of your liking and vice versa.

Anyhow, while off-topic I have to remark on the similarities between emacs
and the control panel of a nuclear power plant (you can do lots of things,
but very little happens by accident) and vim and a chainsaw (you can fell
trees – and you own leg – with a flick of a finger… :wink:

– Nikodemus

···

On Thu, 1 Aug 2002, Jim Freeze wrote:

My experience is that 99% of people use mixed tabs and spaces.
So the result is that you get no-ones preferences. :slight_smile:

That’s what expand and unexpand are for :slight_smile:

···

On Thu, Aug 01, 2002 at 06:50:55AM +0900, Jim Freeze wrote:

On Thu, Aug 01, 2002 at 06:21:40AM +0900, Albert Wagner wrote:

On Wednesday 31 July 2002 11:07 am, Jim Freeze wrote:

My experience is that 99% of people use mixed tabs and spaces.
So the result is that you get no-ones preferences. :slight_smile:


_ _

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

“You, sir, are nothing but a pathetically lame salesdroid!
I fart in your general direction!”
– Randseed on #Linux

Vim users may notice that the filetype plugin for Ruby sets up exactly
this; it changes shiftwidth to the most evil value in common use (2),
but does not set tabstop or expandtab, resulting in autoindent working
at 2, you working at tabstop, and if you haven’t set expandtab, them
mixing together into a horrible tab vs space war.

Space users: echo “set expandtab” >>~/.vimrc

Tab users: echo -e “source $VIMRUNTIME/ftplugin/ruby.vim\nsetlocal
sw=8” >~/.vim/ftplugin/ruby.vim

···

My experience is that 99% of people use mixed tabs and spaces.
So the result is that you get no-ones preferences. :slight_smile:


Thomas ‘Freaky’ Hurst - freaky@aagh.net - http://www.aagh.net/

Theory is gray, but the golden tree of life is green.
– Goethe

Works for me:

[1, 2, 3].each do |x|
    p x
    p x
end

Maybe you have an older buggier version of ruby.vim? I’m using this:
http://mugca.its.monash.edu.au/~djkea2/vim/syntax/ruby.vim
(it goes in $VIM/vim61b/syntax/ruby.vim or whatever your equivalent
directory is).

···

On Mon, Aug 12, 2002 at 12:42:04PM +0900, Dossy wrote:

True. Vim’s = (reindent) doesn’t Do The Right Thing for me and
especially breaks when do/end is used instead of {}.

Before:

[1, 2, 3].each do |x|
    p x
        p x
end

After =4j:

[1, 2, 3].each do |x|
p x
p x
end

Hmm…indents fine for me with either of your examples above. I have vim
6.1.48 I think (which ever is the current Gentoo version).


Signed,
Holden Glova

···

On Mon, 12 Aug 2002 15:42, Dossy wrote:

On 2002.08.12, Gavin Sinclair gsinclair@soyabean.com.au wrote:

Anyway, by “indenting a block” I meant “correcting the indentation”,
not “increasing the indent”. The former is handy when you’ve moved
some code into the do…end block and require all the indentation to
be fixed up.

True. Vim’s = (reindent) doesn’t Do The Right Thing for me and
especially breaks when do/end is used instead of {}.

Before:

[1, 2, 3].each do |x|
    p x
        p x
end

After =4j:

[1, 2, 3].each do |x|
p x
p x
end

Before:

[1, 2, 3].each { |x|
    p x
        p x
}

After =4j:

[1, 2, 3].each { |x|
    p x
        p x
}

Not very useful in either case. At least in the do/end, once it
unindents everything on you, you could go in and manually reindent
with >> …

–Gavin “imap endcc” Sinclair

Ah, you must be one of those Gvim-using weirdos. In my world,
there is no … holding shift and pressing enter still
generates 0x0A.

– Dossy

I did have an older version of ruby.vim, so I replaced mine
with the one at the URL you specify.

Still doesn’t work for me.

This is what :set shows:

autoindent filetype=ruby shiftwidth=2 ttyfast
comments=:# formatoptions=cql smartindent viminfo=‘20,"50
define=^\s* history=50 suffixesadd=.rb
expandtab ruler tabstop=2
backspace=indent,eol
cpoptions=aABceFsu
helpfile=/usr/share/vim/vim61/doc/help.txt.gz
include=^\s*<(load|require)>
includeexpr=substitute(substitute(v:fname,’::‘,’/‘,‘g’),’$‘,’.rb’,‘’)
iskeyword=48-57,_,A-Z,a-z,:
path=/usr/local/lib/site_ruby/1.6,/usr/local/lib/site_ruby/1.6/i386-linux,/usr
/local/lib/site_ruby,/usr/lib/ruby/1.6,/usr/lib/ruby/1.6/i386-linux,
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg
,.inx,.out,.toc

$ vim --version | head -2
VIM - Vi IMproved 6.1 (2002 Mar 24, compiled Apr 14 2002 20:39:56)
Included patches: 1-18

FWIW, this is the Debian Woody packaged version of Vim.

– Dossy

···

On 2002.08.12, Philip Mak pmak@animeglobe.com wrote:

Maybe you have an older buggier version of ruby.vim? I’m using this:
http://mugca.its.monash.edu.au/~djkea2/vim/syntax/ruby.vim
(it goes in $VIM/vim61b/syntax/ruby.vim or whatever your equivalent
directory is).


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

That is interesting. When I type :set I get a list of indentkeys and an
indentexpr. Here is what mine shows:

autoindent filetype=ruby incsearch scroll=34
tabstop=2
autowrite foldlevel=3 mouse=a shiftwidth=2
textwidth=78
background=dark foldmethod=syntax mousemodel=popup showcmd
ttyfast
backspace=2 foldminlines=10 number showmatch
viminfo='20,"50
expandtab history=50 ruler syntax=ruby
nowrap
directory=~/tmp,/tmp,/var/tmp,.
formatoptions=tcql
guifont=-misc-fixed-medium-r-normal---120---c-*-iso10646-1
indentexpr=GetRubyIndent()
indentkeys=0{,0},:,0#,!^F,o,O,e,=end,=else,=elsif,=when,=ensure,=rescue

suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc

Not sure why there is a such a diff. Just for completeness to this post…
[synack@Evergreen] src $ vim --version | head -2
VIM - Vi IMproved 6.1 (2002 Mar 24, compiled Aug 5 2002 23:27:36)
Included patches: 1, 3-15, 17-18, 20-22, 24-34, 36-72, 74-87, 89-92, 94-99,
101-118, 120-146


Signed,
Holden Glova

···

On Mon, 12 Aug 2002 16:01, Dossy wrote:

On 2002.08.12, Philip Mak pmak@animeglobe.com wrote:

Maybe you have an older buggier version of ruby.vim? I’m using this:
http://mugca.its.monash.edu.au/~djkea2/vim/syntax/ruby.vim
(it goes in $VIM/vim61b/syntax/ruby.vim or whatever your equivalent
directory is).

I did have an older version of ruby.vim, so I replaced mine
with the one at the URL you specify.

Still doesn’t work for me.

This is what :set shows:

autoindent filetype=ruby shiftwidth=2 ttyfast
comments=:# formatoptions=cql smartindent
viminfo=‘20,"50 define=^\s* history=50 suffixesadd=.rb
expandtab ruler tabstop=2
backspace=indent,eol
cpoptions=aABceFsu
helpfile=/usr/share/vim/vim61/doc/help.txt.gz
include=^\s*<(load|require)>
includeexpr=substitute(substitute(v:fname,’::‘,’/‘,‘g’),’$‘,’.rb’,‘’)
iskeyword=48-57,_,A-Z,a-z,:

path=/usr/local/lib/site_ruby/1.6,/usr/local/lib/site_ruby/1.6/i386-linux,/
usr /local/lib/site_ruby,/usr/lib/ruby/1.6,/usr/lib/ruby/1.6/i386-linux,
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.
ilg ,.inx,.out,.toc

$ vim --version | head -2
VIM - Vi IMproved 6.1 (2002 Mar 24, compiled Apr 14 2002 20:39:56)
Included patches: 1-18

FWIW, this is the Debian Woody packaged version of Vim.

– Dossy

That is interesting. When I type :set I get a list of indentkeys and an
indentexpr. Here is what mine shows:

[…]

indentexpr=GetRubyIndent()
indentkeys=0{,0},:,0#,!^F,o,O,e,=end,=else,=elsif,=when,=ensure,=rescue

Interesting. $VIM/indent/ruby.vim wasn’t being loaded.

Since I’m short on time, I just added this to my ~/.vimrc:

autocmd BufRead *.rb so /usr/share/vim/vim61/indent/ruby.vim

I’ll figure this out later. Thanks!

– Dossy

···

On 2002.08.12, Holden Glova dsafari@paradise.net.nz wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Two points:

  1. You can use :scr[iptnames] to find out which scripts/plugins have been
    sourced.

  2. I’ve become the maintainter of the ruby indent file, unless anyone disagrees
    :wink: I’m no good at writing indent rules yet. Any bug reports/solutions much
    appreciated. At the moment there are two that I’m aware of (the follwing are
    vim-indented)

def cartesianProduct(denumerable, &productBlock) #finite,finite is broken :frowning:
d = self.class.new
end

p = proc {
$_ }
x = 1

The second case is hardly important as it’s unusual code style, but the first
is very important. If an “inline” comment ends in ( or . or , or …
probably some others, the next line can’t be indented correctly. Again, any
help much appreciated.

Regards,
Gavin

···

----- Original Message -----
From: “Dossy” dossy@panoptic.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, August 12, 2002 11:39 PM
Subject: Re: Style question

On 2002.08.12, Holden Glova dsafari@paradise.net.nz wrote:

That is interesting. When I type :set I get a list of indentkeys and an
indentexpr. Here is what mine shows:

[…]

indentexpr=GetRubyIndent()
indentkeys=0{,0},:,0#,!^F,o,O,e,=end,=else,=elsif,=when,=ensure,=rescue

Interesting. $VIM/indent/ruby.vim wasn’t being loaded.

Since I’m short on time, I just added this to my ~/.vimrc:

autocmd BufRead *.rb so /usr/share/vim/vim61/indent/ruby.vim

I’ll figure this out later. Thanks!

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Two points:

  1. You can use :scr[iptnames] to find out which scripts/plugins have been
    sourced.

Thanks.

Interestingly, :scr shows that $VIMRUNTIME/indent.vim isn’t loaded.
Adding “so $VIMRUNTIME/indent.vim” now properly loads
$VIMRUNTIME/indent/ruby.vim for me.

  1. I’ve become the maintainter of the ruby indent file, unless anyone
    disagrees :wink: I’m no good at writing indent rules yet. Any bug
    reports/solutions much appreciated. At the moment there are two that
    I’m aware of (the follwing are vim-indented)

def cartesianProduct(denumerable, &productBlock) #finite,finite is broken :frowning:
d = self.class.new
end

Well, you didn’t put a URL to the “latest” indent/ruby.vim file, so
here’s a patch off the one I’ve currently got:

···

On 2002.08.13, Gavin Sinclair gsinclair@soyabean.com.au wrote:

======================================================================
— /usr/share/vim/vim61/indent/ruby.vim Sun Apr 14 14:48:26 2002
+++ ruby.vim Mon Aug 12 11:59:05 2002
@@ -30,8 +30,9 @@
return 0
endif

  • " If the line trailed with a *, +, comma, . or (, trust the user
  • if getline(lnum) =~ ‘(*|.|+|,|()(\s*#.*)=$’
  • " If the line trailed with a *, +, comma, . or ( but not in a comment,
  • " trust the user
  • if getline(lnum) =~ ‘([^#].)?(*|.|+|,|()(\s#.*)=$’
    return -1
    endif
    ======================================================================

I don’t know if this Does The Right Thing for all other cases,
but it seems to do the right thing with the test case you provided.

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Two points:

  1. You can use :scr[iptnames] to find out which scripts/plugins have
    been sourced.

Thanks.

Interestingly, :scr shows that $VIMRUNTIME/indent.vim isn’t loaded.
Adding “so $VIMRUNTIME/indent.vim” now properly loads
$VIMRUNTIME/indent/ruby.vim for me.

Make sure you have “filetype indent on” (and “filetype plugin on”) in your
.vimrc. The rest will follow automatically. The online help explains
these, but I just take them on faith as commands that make stuff work.

  1. I’ve become the maintainter of the ruby indent file, unless anyone
    disagrees :wink: I’m no good at writing indent rules yet. Any bug
    reports/solutions much appreciated. At the moment there are two that
    I’m aware of (the follwing are vim-indented)

def cartesianProduct(denumerable, &productBlock) #finite,finite is
broken :frowning: d = self.class.new
end

Well, you didn’t put a URL to the “latest” indent/ruby.vim file, so
here’s a patch off the one I’ve currently got:

[snip]

I don’t know if this Does The Right Thing for all other cases,
but it seems to do the right thing with the test case you provided.

Thanks a million; I’ll investigate today. For those interested, I’m
keeping “the latest” at www/soyabean.com.au/gavin/vim/index.html.
(ftplugin/ruby.vim is there as well.) There’s no change to the vim6.1
version yet. I’ll post here when there is (which should be soon once I
incorporate Dossy’s patch.

– Dossy

Gavin

···

On 2002.08.13, Gavin Sinclair gsinclair@soyabean.com.au wrote: