Reformat Ruby source code in vim?

I'm in the process of converting to vim from emacs to help save my
hands. I'm using the excellent vim-ruby gem to syntax color my code.

One thing that I haven't figured out how to do yet in vim is
reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
really useful during refactoring when moving code fragments from one
place to another.

Thanks!
-John
http://www.iunknown.com

ggVG=

···

On 8/28/06, John Lam <drjflam@gmail.com> wrote:

I'm in the process of converting to vim from emacs to help save my
hands. I'm using the excellent vim-ruby gem to syntax color my code.

One thing that I haven't figured out how to do yet in vim is
reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
really useful during refactoring when moving code fragments from one
place to another.

Thanks!
-John
http://www.iunknown.com

--
Kent
---

To save my hands, I switched to using the dvorak layout and also to
using this keyboard: Kinesis Advantage2 Ergonomic Keyboard | Kinesis Keyboards and Mice .
Highly recommended.

---John

···

On 8/28/06, John Lam <drjflam@gmail.com> wrote:

I'm in the process of converting to vim from emacs to help save my
hands. [snip]

Awesome. Thanks, Kent!

-John

···

On 8/28/06, Kent Sibilev <ksruby@gmail.com> wrote:

ggVG=

On 8/28/06, John Lam <drjflam@gmail.com> wrote:
> I'm in the process of converting to vim from emacs to help save my
> hands. I'm using the excellent vim-ruby gem to syntax color my code.
>
> One thing that I haven't figured out how to do yet in vim is
> reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
> really useful during refactoring when moving code fragments from one
> place to another.
>
> Thanks!
> -John
> http://www.iunknown.com
>

--
Kent
---
http://www.datanoise.com

Hi,

gg=G works too, and it's shorter :slight_smile:

···

--
Bruno Michel

Kent Sibilev a écrit :

ggVG=

On 8/28/06, John Lam <drjflam@gmail.com> wrote:

I'm in the process of converting to vim from emacs to help save my
hands. I'm using the excellent vim-ruby gem to syntax color my code.

One thing that I haven't figured out how to do yet in vim is
reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
really useful during refactoring when moving code fragments from one
place to another.

Thanks!
-John
http://www.iunknown.com

Ah yes - I'm still learning about motions, as well as visual mode. Now
I just have to download this information into my fingers :slight_smile:

One other thing - is it possible to syntax color a ruby instance
method in vim? I spent some time this morning tweaking my .vimrc to
color things the same way the Vibrant Ink theme in Textmate does, but
the Ruby syntax file in vim doesn't seem to attempt to try and pick
out method names where there's an explicit receiver (eg.
foo.method_name).

Thanks,
-John

···

On 8/28/06, Bruno Michel <bruno@exceliance.fr> wrote:

Hi,

gg=G works too, and it's shorter :slight_smile:

--
Bruno Michel

Kent Sibilev a écrit :
> ggVG=
>
> On 8/28/06, John Lam <drjflam@gmail.com> wrote:
>> I'm in the process of converting to vim from emacs to help save my
>> hands. I'm using the excellent vim-ruby gem to syntax color my code.
>>
>> One thing that I haven't figured out how to do yet in vim is
>> reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
>> really useful during refactoring when moving code fragments from one
>> place to another.
>>
>> Thanks!
>> -John
>> http://www.iunknown.com
>>
>

It would be interesting to see how textmate does this, cause I can't
think of a way to determine whether foo.method_name is an instance
method or a class method for example.

John Lam schrieb:

···

the Ruby syntax file in vim doesn't seem to attempt to try and pick
out method names where there's an explicit receiver (eg.
foo.method_name).

def foo.method_name... is always a singleton class method, isn't it? :wink:

James Edward Gray II

···

On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:

It would be interesting to see how textmate does this, cause I can't
think of a way to determine whether foo.method_name is an instance
method or a class method for example.

> It would be interesting to see how textmate does this, cause I can't
> think of a way to determine whether foo.method_name is an instance
> method or a class method for example.

def foo.method_name... is always a singleton class method, isn't it? :wink:

I am afraid it might be a class method
look at this code

class Foo
    foo = Foo # auch
    def foo.method_name
    ...
end
Foo.methods.grep "method_name"

Ruby is full of surprises :wink:

Cheers
Robert

James Edward Gray II

···

On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:

On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:

> It would be interesting to see how textmate does this, cause I can't
> think of a way to determine whether foo.method_name is an instance
> method or a class method for example.

def foo.method_name... is always a singleton class method, isn't it? :wink:

I am afraid it might be a class method

A class method is a singleton method on a class:

>> class Foo
>> foo = Foo
>> def foo.method_name
>> end
>> end
=> nil
>> Foo.singleton_methods
=> ["method_name"]

James Edward Gray II

···

On Aug 28, 2006, at 11:47 AM, Robert Dober wrote:

On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:

On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:

>>
>> > It would be interesting to see how textmate does this, cause I
>> can't
>> > think of a way to determine whether foo.method_name is an instance
>> > method or a class method for example.
>>
>> def foo.method_name... is always a singleton class method, isn't
>> it? :wink:
>
> I am afraid it might be a class method

A class method is a singleton method on a class:

lucky escape :wink:

···

On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:

On Aug 28, 2006, at 11:47 AM, Robert Dober wrote:
> On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:
>> On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:

class Foo

>> foo = Foo
>> def foo.method_name
>> end
>> end
=> nil
>> Foo.singleton_methods
=> ["method_name"]

James Edward Gray II

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

Not at all. That's why I said "singleton class" in the first place.

Hey man, all this singleton class stuff is just finally starting to sink into my brain, don't set me back on the path to enlightenment! :wink:

James Edward Gray II

···

On Aug 28, 2006, at 12:26 PM, Robert Dober wrote:

On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:

On Aug 28, 2006, at 11:47 AM, Robert Dober wrote:

> On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:
>>
>> On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:
>>
>> > It would be interesting to see how textmate does this, cause I
>> can't
>> > think of a way to determine whether foo.method_name is an instance
>> > method or a class method for example.
>>
>> def foo.method_name... is always a singleton class method, isn't
>> it? :wink:
>
> I am afraid it might be a class method

A class method is a singleton method on a class:

lucky escape :wink:

>>
>> >>
>> >> > It would be interesting to see how textmate does this, cause I
>> >> can't
>> >> > think of a way to determine whether foo.method_name is an
>> instance
>> >> > method or a class method for example.
>> >>
>> >> def foo.method_name... is always a singleton class method, isn't
>> >> it? :wink:
>> >
>> > I am afraid it might be a class method
>>
>> A class method is a singleton method on a class:
>
> lucky escape :wink:

Not at all. That's why I said "singleton class" in the first place.

Sorry explanation below...

Hey man, all this singleton class stuff is just finally starting to

sink into my brain, don't set me back on the path to enlightenment! :wink:

ok, ok, I 'll try to learn :wink:

James Edward Gray II

Hmm I was just kidding, thaught you were etc.
Now
   @flags[:serious] = true

I think I read you know.
Do you mean when defining
   def Foo.x
it does not matter if Foo is a class or anyting else, the "singleton method"
is defined on behalf of the "Object"?

As it is Object#methods and not Class#methods I was calling in my funny code
above.

I was not aware of that.

Thanks
Robert

···

On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:

On Aug 28, 2006, at 12:26 PM, Robert Dober wrote:
> On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:
>> On Aug 28, 2006, at 11:47 AM, Robert Dober wrote:
>> > On 8/28/06, James Edward Gray II <james@grayproductions.net> wrote:
>> >> On Aug 28, 2006, at 10:42 AM, Robert Retzbach wrote:

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

I'm not sure I understood you here. What I was saying is, whenever you see:

   def abc.some_method
     # ...
   end

You can be sure that some_method() was just defined as a singleton method of abc. This is often used to make "class methods" in Ruby, but that's really just applying a familiar term to a Ruby concept.

It's always a singleton method being defined, as I understand it.

James Edward Gray II

···

On Aug 28, 2006, at 2:12 PM, Robert Dober wrote:

I think I read you know.
Do you mean when defining
  def Foo.x
it does not matter if Foo is a class or anyting else, the "singleton method"
is defined on behalf of the "Object"?