[ESS] Automatic split windows on R buffer on ESS code execution

Paul Johnson pauljohn32 at gmail.com
Mon Jan 25 03:20:42 CET 2010

On Fri, Jan 22, 2010 at 1:10 PM, Prof. Ronaldo Reis Junior
<ronaldo.reis at unimontes.br> wrote:
> Hi,
> I'm using Emacs 23.1+1-5 with ESS 5.7.1-1. When I send a R command to R
> terminal to be executed with any key (Ctrl+c Ctrl+c or Ctrl+b Ctrl+b, etc) the
> code is executed in a background R buffer. The I need to use Ctrl+x 2 to split
> windows, then ctrl+x o to put cursor on the inferior window and then Ctrl-x b
> to change the buffer to *R* buffer.
> Exist any way to make it automatic? When a send a code from a ESS script
> session to R emacs open a inferior window in *R* buffer?

Dear Everybody:

I have some startup commands that I like with ESS R and they address
this problem.  This starts R in its own emacs frame.  It does some
other things that make Emacs more familiar to students.
For convenience, Shift-Return in the R code file will send the command
to the Emacs buffer (which is running in its own frame).

I do not like to have horizontal splits, and there's a command here
that encouraged Emacs not to use them.
(setq split-window-preferred-function nil)
This doesn't prevent you from inserting splits if you need them, but
you don't get them so often automatically.

I keep this set of commands in the site-start.d directory.  Here's the
one I've used lately:

;;Set up emacs-ess for Emacs with other things we like at KU.
;;;;;; This file is automatically loaded by emacs's site-start.el
;;;;;; when you start a new emacs session.
(require 'pc-select)
 '(cua-mode t nil (cua-base))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t))

(setq inferior-ess-own-frame t)
(setq inferior-ess-same-window nil)
;;;;;create a new frame for each help instance
(setq ess-help-own-frame t)
;;;;;If you want all help
;;;;; buffers to go into one frame do:
(setq ess-help-own-frame 'one)

(setq ess-ask-for-ess-directory nil)
(setq ess-local-process-name "R")

(setq split-window-preferred-function nil)

 (setq ansi-color-for-comint-mode 'filter)
  (setq comint-prompt-read-only t)
     (setq comint-scroll-to-bottom-on-input t)
  (setq comint-scroll-to-bottom-on-output t)
  (setq comint-move-point-for-output t)

(defun my-ess-eval ()
;;  (my-ess-start-R)
  (if (and transient-mark-mode mark-active)
        (call-interactively 'ess-eval-region)
    (call-interactively 'ess-eval-line-and-step)))

(add-hook 'ess-mode-hook
             (local-set-key [(shift return)] 'my-ess-eval)))

Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

More information about the ESS-help mailing list