Pregunta

Emacs 24 ruby-mode insists on indenting if expressions the following way:

    before1 = if params[:before]
            Time.zone.at(params[:before].to_i)
    end

Which i find just plain wrong. The expected behavior should be:

    before1 = if params[:before]
      Time.zone.at(params[:before].to_i)
    end

That is - the if block should be indented by exactly one level relative to the line in which the if expression starts. Is there any way to achieve this?

¿Fue útil?

Solución 2

I guess you actually meant to say that Emacs aligns the if with the end, which is actually pretty idiomatic in Ruby (and the style enforced by tools like RuboCop). The second indentation style is popular for method class with blocks, but not for expressions like if/unless/case.

Currently there is now way to change this behaviour. There are plans to introduce a more flexible indentation scheme in ruby-mode in the future, but that's not going to happen in the next Emacs release.

At any rate - it's not a bug, it's a feature :-)

Otros consejos

If your Emacs is recent enough (24.4+) and you're using the SMIE indentation engine (ruby-use-smie is non-nil), you can use ruby-align-to-stmt-keywords:

(add-to-list 'ruby-align-to-stmt-keywords 'if)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top