Can I get vim to correctly indent this Ruby code (Nokogiri)?

1

The first XML Builder Example for Nokogiri looks like this:

builder = Nokogiri::XML::Builder.new do |xml|
    xml.root {
      xml.products {
        xml.widget {
          xml.id_ "10"
          xml.name "Awesome widget"
        }
      }
    }
 end
 puts builder.to_xml

Even though I have the Ruby Vim files installed, Vim's autoindent flattens the above example like this:

builder = Nokogiri::XML::Builder.new do |xml|
  xml.root {
    xml.products {
    xml.widget {
    xml.id_ "10"
    xml.name "Awesome widget"
  }
  }
  }
end
puts builder.to_xml

Does anybody know how to get Vim to autoindent this correctly?

Nathan Long

Posted 2011-02-21T20:26:22.790

Reputation: 20 371

Answers

1

I can reproduce this.

The indentation rules are defined in the function GetRubyIndent, which is in /usr/share/vim/vimcurrent/indent/ruby.vim on Linux and Unix systems.

The problem seems to be that GetMSL returns 8 for line 3, but also returns 8 rather than 12 for line 4.

If you have a bit of time, have a look at the source code and try to find and fix the problem.

If not, you might like to report it as a bug at the RubyForge Vim/Ruby project site.

Mikel

Posted 2011-02-21T20:26:22.790

Reputation: 7 890