From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Young Subject: Re: [babel, ess] How can I make S-RET to be multi-session friendly? Date: Sat, 11 Aug 2012 10:33:20 -0400 Message-ID: References: <9q01ujfoqh2.fsf@gmx.us> <87boiidil2.fsf@gmx.com> <9q0sjbuvar7.fsf@gmx.us> <87a9y214m8.fsf@gmx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0Ckl-0000DF-Mp for emacs-orgmode@gnu.org; Sat, 11 Aug 2012 10:33:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0Ckk-0003FC-Hj for emacs-orgmode@gnu.org; Sat, 11 Aug 2012 10:33:23 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:43933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0Ckk-0003F1-8j for emacs-orgmode@gnu.org; Sat, 11 Aug 2012 10:33:22 -0400 Received: by wibhn17 with SMTP id hn17so985586wib.12 for ; Sat, 11 Aug 2012 07:33:21 -0700 (PDT) In-Reply-To: <87a9y214m8.fsf@gmx.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Mikhail Titov Cc: emacs-orgmode@gnu.org Hello All, Well, despite being relatively new to elisp, I've decided to take a crack at one of your problems. I'm not too sure what is causing the strange behaviour of the session property, but I have some thoughts on getting that one function working. Bear with me :-) It seems that for me, the inferior ess process is not being properly associated with the src edit buffer. It is being set correctly by org-babel-R-associate-session, and then being set a second time incorrectly by org-babel-edit-prep:R. Commenting out line 5 in org-babel-edit-prep:R seems to fix this issue, although I'm honestly not sure if or what it breaks. Everything seems ok for me, but ymmv. Heres the change: #+begin_src emacs-lisp (defun org-babel-edit-prep:R (info) (let ((session (cdr (assoc :session (nth 2 info))))) (when (and session (string-match "^\\*\\(.+?\\)\\*$" session)) (save-match-data (org-babel-R-initiate-session session nil)) ;;(setq ess-local-process-name (match-string 1 session))))) ))) #+end_src Is there any one having such issues, or who can weigh in on what exactly is happening here? Without making the above change, it is possible to manually attach an ess process to the current src buffer by using the command: C-c C-s (ess-switch-process) You'll have to specify the process name, rather than the buffer name, and the session must have already been started. From here all ESS functions should work. For example, calling: C-c C-z (ess-switch-to-end-of-ESS) will open the session buffer. I've implemented a variation of the function you mentioned, which uses the inferior process discussed above. It should do something at least remotely like the function you were asking for, and will work with babel sessions, as long as the ess process is associated properly. I've made one change worth mentioning: the function now prompts for a buffer name to set up on if no ess process is associated, instead of only and always using *R*. Try it out, and let me know what you think. Of course feel free to tweak & share! This is my real first dive into lisp, so if anyone has anything to share please do. #+begin_src emacs-lisp (defun my-ess-eval () (interactive) (update-ess-process-name-list) (if (not (ess-make-buffer-current)) ;; Obtain the target ess session (let ((session (read-string "Use session: " (let ((proc (get-process ess-current-process-name))) (if (processp proc) (buffer-name (process-buffer proc))))))) ;; Obtain buffer matching session (if (not (get-buffer session)) ;; If there is no buffer, create a new one (save-excursion (inferior-ess) (rename-buffer session))) (setq ess-local-process-name (process-name (get-buffer-process session))))) (ess-make-buffer-current) (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))) (add-hook 'Rnw-mode-hook '(lambda () (local-set-key [(shift return)] 'my-ess-eval))) (require 'ess-site) #+end_src Sincerely, Andrew Young