I am using the Emacs-Speaks-Statistics (ESS) mode for Emacs. When editing R code, any comment lines (those starting with #) automatically get tabbed to the far right when I create a new line above it. How should I change my .emacs.el file to fix this?
For example, I have:
# Comment
Now, after putting my cursor at the beginning of the line and pressing Enter, I get:
# Comment
Thanks for any hints.
Use '###' if you don't want the comments indented. According to the manual,
Either
if you never want to indent single-
#
comments, orif 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
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: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 ofuse-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 respectess-indent-with-fancy-comment
, you must make sure to set it before the styles are defined.