tags:

views:

435

answers:

2

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.

+7  A: 

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 K. Seppänen
This is just sublime! Thanks!!!
aL3xa
Rather I think you should use "#" for end-of-line comments, and these are nicely indented to the same column on purpose --> nice code "listing".For the other comments, really do get in to the habit of using "##"(much more than "###"): These indent as other "statements" within that block of code
Martin Mächler
+7  A: 

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.

huaiyuan