【问题标题】:Emacs Ruby method parameter indentationEmacs Ruby 方法参数缩进
【发布时间】:2011-12-19 04:17:06
【问题描述】:

我想让 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。

哈希缩进我喜欢的方式......如果我可以让方法调用像哈希一样缩进,我会很高兴。有什么想法吗?

【问题讨论】:

  • +1,我还没有弄清楚如何修复关闭的paren对齐。

标签: ruby emacs code-formatting


【解决方案1】:

我相信有一个像 C-c o 这样的键序列,你可以用光标在右括号上按下它,它会显示使用的变量并让你输入一个新值(如 0 或 +)。试试看!

【讨论】:

    【解决方案2】:

    Dmitry Gutov 已发布this fix,使用建议,这似乎有效:

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

    【讨论】:

      【解决方案3】:

      当前 Emacs 主干(将作为 24.4 发布)中的 Ruby 缩进就像您要求的那样工作,无需任何额外的调整。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-23
        • 2011-10-20
        • 1970-01-01
        • 1970-01-01
        • 2016-08-08
        • 1970-01-01
        • 1970-01-01
        • 2011-01-07
        相关资源
        最近更新 更多