I have recently installed projectile
package into my Emacs. It's great package, however, now my C-RET
binding to ESS (R) is not working any more.
Part of my current init.el
related to ESS looks like this:
(setq ess-local-process-name "R")
(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 [(control return)] 'my-ess-eval)))
(add-hook 'inferior-ess-mode-hook
(lambda()
(local-set-key [s-up] 'comint-previous-input)
(local-set-key [s-down] 'comint-next-input)))
(add-hook 'Rnw-mode-hook
(lambda()
(local-set-key [(control return)] 'my-ess-eval)))
I am not familiar with Emacs Lisp, so I am bit struggling to make it work. For me it seems it has lot to do with the my-ess-start-R
function in the member
part. The projectile
always concatenate a string with the name of the project after *R*
buffer name.
So far I tried to play around with regexp expression to match the buffer name, but no luck.
How it used to be:
If the R buffer is not open, open one, after hitting C-RET
If the R buffer is already open, evaluate the R Code after hitting C-RET
Current situation:
After hitting C-RET
the first time Emacs keep opening new R buffers in the format of "R:(project name)(N)" where (project name) is project name coming from projectile
and (N) is the count of the buffer. After hitting C-RET
the second time new buffer with (N+1) opens.
In the *Messages*
buffer I can see an error:
my-ess-start-R: Wrong type argument: bufferp, nil
Expected results:
1. Open R buffer after hitting C-RET
if the buffer is not yet open
2. Evaluate R code in R buffer, again after hitting C-RET
if the buffer is already open
Any help of how to modify the function would be really helpful.
projectile
, emacs keep opening new R buffers with different names, but not evaluating any R code. – Tomas May 21 '19 at 12:15*R
, possibly with something like this:(mapcar (lambda (s) (string-match "*R" (buffer-name s))) (buffer-list))
– Alex May 21 '19 at 12:28(unless CONDITION ...)
instead of the more verbose(if (not CONDITION) (progn ...))
. – Drew May 21 '19 at 15:11