Created
October 13, 2009 01:58
-
-
Save kjhealy/208908 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ESS: Emacs Speaks Statistics | |
(load "~/elisp/vendor/ess/lisp/ess-site.el") | |
;; Use shift-enter to split window & launch R (if not running), execute highlighted | |
;; region (if R running & area highlighted), or execute current line | |
;; (and move to next line, skipping comments). Nice. | |
;; See http://www.emacswiki.org/emacs/EmacsSpeaksStatistics, | |
;; FelipeCsaszar. Adapted to spilit vertically instead of | |
;; horizontally. | |
(setq ess-ask-for-ess-directory nil) | |
(setq ess-local-process-name "R") | |
(setq ansi-color-for-comint-mode 'filter) | |
(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-start-R () | |
(interactive) | |
(if (not (member "*R*" (mapcar (function buffer-name) (buffer-list)))) | |
(progn | |
(delete-other-windows) | |
(setq w1 (selected-window)) | |
(setq w1name (buffer-name)) | |
(setq w2 (split-window w1 nil t)) | |
(R) | |
(set-window-buffer w2 "*R*") | |
(set-window-buffer w1 w1name)))) | |
(defun my-ess-eval () | |
(interactive) | |
(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 | |
'(lambda() | |
(local-set-key [(shift return)] 'my-ess-eval))) | |
(add-hook 'inferior-ess-mode-hook | |
'(lambda() | |
(local-set-key [C-up] 'comint-previous-input) | |
(local-set-key [C-down] 'comint-next-input))) | |
(require 'ess-site) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had the same problem. The culprit is where the window is split and R is started (lines 24, 25). The code starts the R interpreter in the wrong window. At first this is not a problem but later when the current line is executed (line 32, 33), the incorrect window has focus and the wrong line is executed. My version of my-ess-start-R looks like this:
This code does something slightly different than the version above. If there's only one window, it is split and R is started in the right window (the new one). If there are several windows, R is started in one of them (but not in the window that contains the code). This means that my version is more conservative and doesn't unnecessarily mess with the layout of the windows. Which behavior you prefer is a matter of taste, of course. Hope that helps.