Indent wierdness.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Indent wierdness.

Hugh Sasse
I know this is post 6.4, but still:

how does this code
 <url: http://www.whytheluckystiff.net/articles/seeingMetaclassesClearly.html >
[the first box] indent for you:

 class Object
   # The hidden singleton lurks behind everyone
   def metaclass; class << self; self; end; end
   def meta_eval &blk; metaclass.instance_eval &blk; end

   # Adds methods to a metaclass
   def meta_def name, &blk
     meta_eval { define_method name, &blk }
   end

   # Defines an instance method within a class
   def class_def name, &blk
     class_eval { define_method name, &blk }
   end
 end


For me it ends up like this:

class Object
  # The hidden singleton lurks behind everyone
  def metaclass; class << self; self; end; end
def meta_eval &blk; metaclass.instance_eval &blk; end

# Adds methods to a metaclass
def meta_def name, &blk
  meta_eval { define_method name, &blk }
end

# Defines an instance method within a class
def class_def name, &blk
  class_eval { define_method name, &blk }
end
 end


Is this reproducable?

        Thank you,
        Hugh
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: Indent wierdness.

Nikolai Weibull-5
Hugh Sasse wrote:

>    def metaclass; class << self; self; end; end

Problem with counting of def and class versus ends.  We only see things
at the beginning of the line.

So don't write it in the shrivelled-up-I’m-in-a-book kind of way;
instead, write it as:


  def metaclass
    class << self; self; end
  end

That won’t fool the indenter.  Perhaps we can rewrite the regular
expressions to do this kind of stuff, but I don’t remember if there were
issues with doing so.

If you want, please try redefining s:end_start_regex so that it can find
the ‘class’ in the above example as well.  That’d solve a lot of issues.
Perhaps my reasoning has been far too restrictive when it comes to that
variable.  You can try something like

let s:end_start_regex = '\%(^\|[^.:]\)\@<=\<\%(module\|class\|def\|if' .
        \ '\|for\|while\|until\|case\|unless\|begin\|do\)\>'

and report back on how that works.  It solves the issues you were having
now, but please verify that it doesn’t introduce something nasty....

Thanks,
        nikolai

--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: Indent wierdness.

Nikolai Weibull-5
Hugh Sasse wrote:

> On Fri, 21 Oct 2005, Nikolai Weibull wrote:

> > So don't write it in the shrivelled-up-I’m-in-a-book kind of way;

> :-) I pasted it from the web.

Precisely;  ;-),
        nikolai

--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel