4

I'm using Emacs 24 on Windows to write some R code. Up until about 30 minutes ago, whenever I would write a new function, ESS would automatically indent the lines following the function declaration and pressing the tab key on a new blank line would jump me to the appropriately indented starting position inside the declaration.

EG:

foo <- function() {
    first line started here
    second line here.  .etc
}

Now, it is hard wrapping everything to the left, and not responding by automatically indenting after the function declaration or when I hit the tab key.

foo <- function() {
first line
second line
}

I've googled, but my google-fu is failing me on this. Anyone know how to restore default tab behavior to ESS in Emacs?

FloppyDisk
  • 1,693
  • 16
  • 25

3 Answers3

6

just for the record. Whenever such things happens, select the whole buffer C-x h and press C-M-\ to indent the whole region. This will show unambiguously the syntax error.

VitoshKa
  • 8,387
  • 3
  • 35
  • 59
1

Try to add a space after "#". I don't think ESS-mode handles # as a comment unless you have space after it.

Storstamp
  • 425
  • 2
  • 8
  • It's not doing it just for comments, it's doing it for code too. I'll update to reflect that. – FloppyDisk Oct 15 '12 at 20:26
  • Sorry for asking, but I guess you have run "source" on the file from R to check that the syntax is correct? – Storstamp Oct 15 '12 at 20:28
  • Well, I feel really dumb now. I did have a syntax error in the file and completely missed it. D'oh. Thanks for being patient and the suggestion! – FloppyDisk Oct 15 '12 at 20:48
  • 1
    normally when you think ESS has messed you around, you've forgotten the (for example) the opening brace of a function. Happens to me far more often than I care to admit. – richiemorrisroe Oct 15 '12 at 21:06
0

I just came across the same problem you describe.

None of the above seemed to work, but I narrowed it down to using a carriage return and then an open parenthesis inside a string, like so:

### indent ( <tab> ) working fine up to here 
   s1 <- "string
(then this in brackets)"
### now indent does nothing!

The fact that it's balanced later doesn't help. I think EMACS reads this as opening a new expression/ block in spite of the fact that it occurs in a quoted string. This seems to apply also to expression openers { and [. It only seems to happen when the 'open expression' symbol appears at the start of the line...

In my case the string was part of a plot label, so the solution was to use \n instead.

dardisco
  • 5,086
  • 2
  • 39
  • 54