6

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?

Drew
  • 75,699
  • 9
  • 109
  • 225
doctorate
  • 1,789
  • 16
  • 39

1 Answers1

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:
rasmus
  • 2,682
  • 13
  • 20
  • 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 Feb 09 '15 at 07: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 Feb 09 '15 at 08: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 Feb 09 '15 at 09: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 Mar 18 '16 at 12:30
  • doctorate, you could try different arguments ("levels") in the `org-global-cycle` call. – rasmus Apr 08 '16 at 14:25
  • could you please suggest one which is compatible with `#+STARTUP: overview` directive? – doctorate Apr 08 '16 at 15:12