Emacs Ruby方法参数缩进

27

我想让Emacs像这样缩进Ruby方法调用:

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

我能得到的最接近的答案是:

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

我使用的是ruby-deep-indent-paren、ruby-deep-indent-paren-style和ruby-deep-arglist,它们都被设置为nil。

哈希(Hashes)的缩进方式符合我的喜好...如果我能让方法调用的缩进方式与哈希一样,那就太棒了。有什么想法吗?


1
+1,我还没有弄清楚如何修复那个括号的对齐问题。 - d11wtq
3个回答

12

Dmitry Gutov发布了这个修复程序,使用了建议,看起来是有效的:

(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)))))

6

在即将发布的Emacs 24.4中,Ruby的缩进方式已经默认支持你所说的功能,无需额外的调整。


0

我相信有一个类似于 C-c o 的键序列,你可以在光标停留在右括号上按下它,这将会显示出使用的变量,并让你输入新值(比如 0 或 +)。尝试一下吧!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接