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 ()
     (if (not (member "*R*" (mapcar (function buffer-name) (buffer-list))))
           (setq w1 (selected-window))
           (setq w1name (buffer-name))
           (setq w2 (split-window w1 nil t))
           (set-window-buffer w2 "*R*")
           (set-window-buffer w1 w1name))))

   (defun my-ess-eval ()
     (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 [(control return)] 'my-ess-eval)))

   (add-hook 'inferior-ess-mode-hook
               (local-set-key [s-up] 'comint-previous-input)
               (local-set-key [s-down] 'comint-next-input)))

   (add-hook 'Rnw-mode-hook
               (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.

  • Welcome to Emacs.SE! Please clarify what you mean by “not working.” – Dan May 21 at 12:14
  • @Dan When I hit (ctrl return) the emacs will: 1. Open up R buffer 2. Evaluate code in R buffer After installation of projectile, emacs keep opening new R buffers with different names, but not evaluating any R code. – Tomas May 21 at 12:15
  • @Tomas I don't think your C-RET bindings are needed. If I understand correctly, they are doing something very similar to the default. That said, if you do want to keep them, you want to check if any buffer name starts with *R, possibly with something like this: (mapcar (lambda (s) (string-match "*R" (buffer-name s))) (buffer-list)) – Alex May 21 at 12:28
  • FWIW, you can use (unless CONDITION ...) instead of the more verbose (if (not CONDITION) (progn ...)). – Drew May 21 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.