首页 > 解决方案 > Emacs ESS 在 %>% 后缩进

问题描述

对于 R 代码,我当前的 emacs ESS 样式是 C++,这会导致

worst <- flights_sml %>%
    group_by(year, month, day)

即继续在 . 之后缩进 4 个空格%>%。我希望它是2个空格。

我怎样才能做到这一点?

标签: remacsindentationess

解决方案


你想要什么并不完全清楚。如果在连续语句中只需要 2 个空格,例如管道之后的那些,则以下应该有效

(setq ess-offset-continued '(straight 2))

因此,缩进仍将默认为 C++ 样式中设置的 4 个空格,例如。结果看起来像

worst <- flights_sml %>%
  group_by(year, month, day)

f <- function(x) {
    x
}  

否则,如果你总是想要 2 个空间偏移

(setq ess-indent-offset 2)

您可以在模式挂钩中自定义这些变量,例如。

(defun my-R-hook ()
  (setq-local ess-style 'C++)
  (setq-local ess-offset-continued '(straight 2)))

ess-offset-continued有关详细信息,请参阅文档ess-style-alist


推荐阅读