3
votes

In Emacs, using ruby-mode, I can't find a way to stop this happening:

foo = if something?
        42
      else
        7
      end

When our in-house conventions are:

foo = if something?
  42
else
  7
end

(Same goes for begin..end and case..when).

Also, while it's less of a nuisance, our convention for case..when is to indent each when.

case whatever
  when foo
    "a"
  when bar
    "b"
  else
    "c"
end

I know people generally say you should align the when with the case, but it's not the convention of our company, so does anybody know how to customize this too? I can find very little customization for ruby-mode. The only thing I've really been able to customize is the indentation inside parentheses.

2
I'm not posting this as an answer, but given that ruby-mode is written by Matz himself, I just adopted to its conventions in the few cases where it was different from my personal ones. Are your company's rules set in stone or open for discussion? - Michael Kohl
They're open for discussion, but I think changing conventions on an already established project, just to adhere to one person's text editor is perhaps not ideal ;) I may look into what's involved in adding some more config options, such as ruby-indent-case-when and ruby-deep-indent-block-assignment or something. Maybe. Currently I just subconsciously know to use C-q C-j to create newlines in places where my indentation would be changed. - d11wtq
Sure, but if the one person's text editor's Ruby mode was written by Ruby's creator, that could help the argument. Anyway, more config options would definitely be appreciated. - Michael Kohl
If you are interested in modifying ruby-mode indentation, check out my example at github.com/lewang/le_emacs_libs/blob/master/… - event_jr
@event_jr That's great thanks! - d11wtq

2 Answers

4
votes

In Emacs 24.4 and newer, you can set ruby-align-to-stmt-keywords to '(if begin case), or simply to t, to resolve the first part of your question.

It won't change the indentation offset of when, though. That would have to be a different option.

2
votes

There is no way to customize this. ruby-mode is pretty barebone as far as indentation customizations are concerned and Matz (its original author) is totally adamant in supporting the standard style for case indentation.