Emacs ESS Mode - Tabbing for Comment Region

佐手、 提交于 2019-11-28 04:50:32

Use '###' if you don't want the comments indented. According to the manual,

By default, comments beginning with ‘###’ are aligned to the beginning of the line. Comments beginning with ‘##’ are aligned to the current level of indentation for the block containing the comment. Finally, comments beginning with ‘#’ are aligned to a column on the right (the 40th column by default, but this value is controlled by the variable comment-column,) or just after the expression on the line containing the comment if it extends beyond the indentation column.

Either

(setq ess-fancy-comments nil)

if you never want to indent single-# comments, or

(add-hook 'ess-mode-hook 
          (lambda () 
            (local-set-key (kbd "RET") 'newline)))

if you want to change the behavior of Enter so it doesn't indent.

Jouni's answer didn't work for me. But I found an approach here that does: https://stat.ethz.ch/pipermail/ess-help/2016-May/010970.html

   (defun my-ess-settings ()
     (setq ess-indent-with-fancy-comments nil))
   (add-hook 'ess-mode-hook #'my-ess-settings)

Setting ess-indent-with-fancy-comments to nil will remove the weird single-# indentation, but it must be set either buffer-locally in a hook (as in Rob's answer), OR before ESS is loaded:

(setq ess-indent-with-fancy-comments nil)
(require 'ess)

Other ways to make sure it is set before ESS is loaded, is to set it in M-x configure, or to set it in the :init section of use-package.

What's going on is that ESS defines styles at initialization in ess-style-alist, and then applies the default style in every buffer. So to make sure these styles respect ess-indent-with-fancy-comment, you must make sure to set it before the styles are defined.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!