Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Ruby method parameter indentation

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?

like image 520
Mike Hornblade Avatar asked Nov 01 '11 01:11

Mike Hornblade


2 Answers

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)))))
like image 163
Luke Girvin Avatar answered Nov 05 '22 16:11

Luke Girvin


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

like image 6
Dmitry Avatar answered Nov 05 '22 16:11

Dmitry