7

Shifting from Rstudio to ESS took some time with me because of the steep learning curve of a versatile Emacs editor, but is was a worthwhile experience. What I am still missing in ESS is that outline or overview of the R script file based on comments (called sections in Rstudio) by pressing Ctrl+Shift+R to give # some comments or title here (see the screenshot).

enter image description here

After having a lot of sections and the file size becomes very large, it becomes increasingly difficult to navigate throughout a giant multi-section file. In Rstudio I press that orange button # to pop up a small window of all sections or # comments and by clicking any one of them will put me on that heading in the file.

Similar thing I found in AUCTeX is the C-c = which will show an outline clickable table to navigate that .tex file.

How to obtain this handy overview in ESS?

1 Answer 1

6

I like orgstruct-mode. In the following file you can collapse headings with Tab or S-Tab, much like in org-mode. Note that the eval part below collapsed the file to out-most level when opening the file.

##* sec1
x <- rnorm(10)
##** sec11
y <- x<0
##* sec 2
z <- x + y

## Local Variables:
## outline-regexp: "##*\\*+\\|\\`"
## orgstruct-heading-prefix-regexp: "##*\\*+\\|\\`"
## eval: (progn (orgstruct-mode) (org-global-cycle 3))
## End:
6
  • Great! even more flexible! but do you know how to activate/deactivate application of orstruct code while I am inside the buffer? to play with the code I have to kill/and open the same buffer and answer y or no for application of the safe code.
    – doctorate
    Commented Feb 9, 2015 at 7:58
  • The first part of regexp till \\| will detect the ## and multiples of following asterisks, but I wonder what is the benefit of the last part |\\` in regexp?
    – doctorate
    Commented Feb 9, 2015 at 8:58
  • do revert-file will reload file-local variables. There's a info page about if you search (I haven't got time atm). The \` matches the beginning of the buffer/string depending on context.
    – rasmus
    Commented Feb 9, 2015 at 9:06
  • is there any way to add a directive like in org-mode to determine level of folding for this buffer, #+STARTUP: overview kind of thing?
    – doctorate
    Commented Mar 18, 2016 at 12:30
  • doctorate, you could try different arguments ("levels") in the org-global-cycle call.
    – rasmus
    Commented Apr 8, 2016 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.