d11wtq
d11wtq

Reputation: 35318

Emacs ruby-mode, indenting wildly inside parentheses?

Excuse my emacs newbiness here, but does anybody know how to get around this? When coding in emacs, in ruby-mode, it indents to the correct level (i.e. by 2 spaces) after all the keywords, like def, class, module, begin etc, but when breaking parameter lists across multiple lines, it indents to a seemingly random position, like 40 or so columns over.

I've been reading around emacs tab settings and seem to just be going around in circles and not getting to information I'm looking for, so I figured I'd ask here.

Here's a screenshot of where it is placing the cursor in a parameter list. I've tried indenting inside of curly braces (e.g. for a block, or a hash) and that is working ok, it's the parentheses that are messing it up.

Bug

Upvotes: 15

Views: 3805

Answers (3)

Beni Cherniavsky-Paskin
Beni Cherniavsky-Paskin

Reputation: 10059

ruby-deep-indent-paren and related vars have no effect for me because ruby-use-smie is t. Setting both to nil didn't seem to help either :-(

But switching to enh-ruby-mode, it's working!

  • Setting enh-ruby-deep-indent-paren to nil had an effect.
  • Setting enh-ruby-bounce-deep-indent to t allows me to press Tab again to toggle between the styles!

Upvotes: 1

aghull
aghull

Reputation: 4591

Basically it's trying to line up the args in a multi-line list of parenthesized arguments, like:

function_call (arg1,
               arg2);

Setting the ruby-deep-indent-paren to nil as above changes the behvaior to the annoying double-indenting for mixed braces, e.g.:

if (cond) then
  do_stuff
end
function_call (&proc {
    do_stuff
  })

The indenting wierdness is really bothering me. I edited Mats' original ruby-mode.el code to try and indent more sanely. But I can't get it cleaned up for the life of me.

Upvotes: 0

d11wtq
d11wtq

Reputation: 35318

http://compgroups.net/comp.emacs/Ruby-mode-indentation-of-continuation-lines

(setq ruby-deep-indent-paren nil)

Or temporarily, within the current session:

M-x set-variable RET ruby-deep-indent-paren RET nil RET

Inside of a parentheses it will now indent like it does everywhere else. There is still a minor bug in the case of what I posted above. It indents 2 spaces further than I want it to, because I'm confusing it with the combination of ( and {.

Upvotes: 16

Related Questions