How to configure the ESS windows similar to the Rstudio layout?

What happened?

Hi! I’m trying to pass my R coding workflow to Emacs, but I’m not completely satisfied with the windows’ layout. The basic layout which I like to have is the classic’s Rstudio panes layout,

In the ESS manual they explain how to do it using display-buffer-alist. However, I think this variable is heavily modified by the doom’s popup rules.

I tried this config, but for the moment the help[R] and R dired buffers disappear when I press q or ESC and they appear in the wrong order.

(set-popup-rule! "^\\*R dired"    :action '(display-buffer-in-side-window) :side 'right :slot -1 :width 0.33 :quit nil :ttl 0)
(set-popup-rule! "^\\*R" :action '(display-buffer-in-side-window) :side 'bottom :width 0.5 :quit nil :ttl nil)
(set-popup-rule! "^\\*help\\[R\\]" :action '(display-buffer-in-side-window) :side 'right :slot 1 :width 0.33 :quit nil :ttl 0)

This is how it looks normally when I invoke ess-display-help-on-object or ess-rdired

What did you expect to happen?

Doing some manual windows arrangements, I get something similar to the Rstudio layout. The main is idea is that any of these windows are popups, but permanents buffers inside this workspace. Also, I could be great if this layout could be present only if I’m editing .R (or similar) files.

Steps to reproduce

Just apply the configuration above and try to open the help and rdired buffers in an R file.

System information

Thanks for the help!

I believe this is because q is bound to kill-current-buffer here. Undo it with:

(map! :after ess-help
      :map ess-help-mode-map
      :n "q" nil)

Remove the :actions '(display-buffer-in-side-window), and your popup rules should be practically identical to what was suggested in the ESS manual. The next thing I’d suspect is how are you switching to/opening those buffers? Depending on the method, you could easily circumnavigate display-buffer-alist's rules.

Could you expand on what this means? I don’t personally use R, so best not to assume I know what commands are involved, but they could offer a clue as to why those popup rules aren’t working. Ah, just noticed you mentioned ess-display-help-on-object and ess-rdired. I’ll look into those.

1 Like

ess-display-help (used by ess-display-help-on-object) asserts some opinions on how windows are displayed which may be what’s causing this issue.

See if simplifying this function by force helps:

;;; add to $DOOMDIR/config.el
(defadvice! fix-ess-display-help (buff)
  :override #'ess-display-help
  (pop-to-buffer buff))

If nothing changes, try using what the ESS manual suggests, but on +popup-mode-hook:

(add-hook! '+popup-mode-hook
  (setq display-buffer-alist
        (append `(("^\\*R Dired"
                   (display-buffer-reuse-window display-buffer-in-side-window)
                   (side . right)
                   (slot . -1)
                   (window-width . 0.33)
                   (reusable-frames . nil))
                  ("^\\*R"
                   (display-buffer-reuse-window display-buffer-at-bottom)
                   (window-width . 0.5)
                   (reusable-frames . nil))
                  ("^\\*Help"
                   (display-buffer-reuse-window display-buffer-in-side-window)
                   (side . right)
                   (slot . 1)
                   (window-width . 0.33)
                   (reusable-frames . nil)))
                display-buffer-alist)))
1 Like

Hi Henrik,

You’re right. I modified my config and I have this:

(map! :after ess-help
      :map ess-help-mode-map
      :n "q" nil
      :n "ESC" nil)

(map! :after ess-rdired
      :map ess-rdired-mode-map
      :n "q" nil
      :n "ESC" nil)

This way the help and the rdired buffer won’t disappear if I press q or ESC.

And with respect to the windows’ layout, the problem was that the *R dired* buffer was captured by the regex \\*R instead of \\*R dired. I discovered this using +popup/diagnose.

The solution was to change the regex to make it a little more robust,

(set-popup-rule! "^\\*R[:\\*]"  :side 'bottom :width 0.5 :quit nil :ttl nil)
(set-popup-rule! "^\\*R dired\\*"     :side 'right :slot -1 :width 0.33 :quit nil :ttl 0)
(set-popup-rule! "^\\*help\\[R\\]"  :side 'right :slot 1 :width 0.33 :quit nil :ttl 0)

I’ll see if I need to tweak it a little with time.

I made a little demo to show how does it work:

  1. Open the R inferior process with C-c C-c or C-c C-z if there is a running process already.
  2. Open the help on point with SPC m h.
  3. Open the Rdired buffer with C-c C-. o

ess2

The keybindings could be improved to make them more doomish, but for the moment is fine.

This is the final layout

Thanks a lot for the help!

@hlissner I was thinking about the default’s choices in the ESS module in particular with the behavior in the *R* buffer. For the user it could be a little confusing.

The issue with this keybinding it also kills the R inferior process (with all the attached data). It was extremely frustrating to load a lot of variables, press q and noticed that I had lost everything.

It wouldn’t be better something like delete-window or bury-buffer as less drastic alternatives to hide the *R*, *R dired* and *R [help] buffers.

WDYT?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.