Emacs Ruby method parameter indentation
Asked Answered
R

3

27

I want to make emacs indent ruby method calls like:

foo(
  :blah => 'bar',
  :shibby => 'baz'
)

The closest I can get is:

foo(
  :blah => 'bar',
  :shibby => 'baz'
  )

This is using ruby-deep-indent-paren, ruby-deep-indent-paren-style, ruby-deep-arglist all set to nil.

Hashes indent how I like... if I could just make method calls indent like hashes I would be happy. Any ideas?

Rosamariarosamond answered 1/11, 2011 at 1:14 Comment(1)
+1, I still haven't figured out how to fix that closing paren alignment neither.Calamander
S
12

Dmitry Gutov has posted this fix, using advice, which seems to work:

(defadvice ruby-indent-line (after unindent-closing-paren activate)
  (let ((column (current-column))
        indent offset)
    (save-excursion
      (back-to-indentation)
      (let ((state (syntax-ppss)))
        (setq offset (- column (current-column)))
        (when (and (eq (char-after) ?\))
                   (not (zerop (car state))))
          (goto-char (cadr state))
          (setq indent (current-indentation)))))
    (when indent
      (indent-line-to indent)
      (when (> offset 0) (forward-char offset)))))
Syndicalism answered 26/11, 2011 at 13:48 Comment(0)
I
6

Ruby indentation in the current Emacs trunk (to be released as 24.4) works like you're asking without any additional tweaks.

Instate answered 22/12, 2013 at 2:43 Comment(0)
C
0

I believe there is a key sequence like C-c o, that you could press with the cursor on that closing paren that would show what variable is used and let you type in a new value (like 0 or +). Try that!

Canasta answered 23/11, 2011 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.