From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [PATCH] [babel] Add option to display process buffer when editing R source code blocks Date: Thu, 08 Apr 2010 16:02:10 -0400 Message-ID: <87d3y94ssd.fsf@stats.ox.ac.uk> References: <87sk77tjd8.fsf@z.nozav.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nzxx1-0003QH-4T for emacs-orgmode@gnu.org; Thu, 08 Apr 2010 16:03:43 -0400 Received: from [140.186.70.92] (port=45111 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nzxwm-0003ND-Sz for emacs-orgmode@gnu.org; Thu, 08 Apr 2010 16:03:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nzxvc-0002HL-0T for emacs-orgmode@gnu.org; Thu, 08 Apr 2010 16:02:18 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:33504) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nzxvb-0002Gv-PD for emacs-orgmode@gnu.org; Thu, 08 Apr 2010 16:02:15 -0400 In-Reply-To: <87sk77tjd8.fsf@z.nozav.org> (Julien Barnier's message of "Wed, 07 Apr 2010 16:41:55 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Julien Barnier Cc: emacs-orgmode@gnu.org Julien Barnier writes: > Hi, > > This is a small patch to org-babel-R.el which allows to automatically > display the R process buffer when editing R source code blocks with > org-edit-src-code. Hi Julien, Could I suggest a slightly different route? We already have the functions org-babel-switch-to-session and org-babel-load-session, which work for any language. These switch to the process buffer, like your patch does. I agree with you about wanting a function that ends up displaying the process buffer and the code edit buffer. I have the following personal function which achieves that: (defun dan/org-babel-switch-to-code-with-session (&optional arg) "Switch to code edit buffer and display session" (interactive "P") (save-excursion (org-babel-switch-to-session arg nil)) (org-edit-src-code)) Could you experiment with these functions, and see if they are satisfactory, amd let us know if we can improve things? E.g. we could include a function like my one above to display both the session with the edit-buffer. Note that o-b-load-session additionally loads the body of the block into the session; and that switch-session, if called with a prefix arg, assigns variables from the header args in the session[1]. These are bound to M-down and M-up when on a code block. Oh, and also... org-babel-switch-to-session and org-babel-load-session use the emacs function pop-to-buffer. That means that there's all sorts of extra control you can have over how the windows are displayed. See the documentation for things like pop-to-buffer, pop-up-windows, split-window-sensibly, special-display-buffer-names, etc. Dan Footnotes: [1] Just fixed bug here; please pull latest version. > > A custom variable allows to choose between no process buffer > (default), only the source code block and the process buffer, or the > org file, the source code block and the process buffer. > > As I'm quite new to git, I hope my patch is usable, because I > generated it from a org-babel-R.el file which already had some > modifications from master. > > Sincerely, > > -- > Julien > > > --- > contrib/babel/lisp/langs/org-babel-R.el | 27 ++++++++++++++++++++++++++- > 1 files changed, 26 insertions(+), 1 deletions(-) > > diff --git a/contrib/babel/lisp/langs/org-babel-R.el b/contrib/babel/lisp/langs/org-babel-R.el > index 8b333cc..3924089 100644 > --- a/contrib/babel/lisp/langs/org-babel-R.el > +++ b/contrib/babel/lisp/langs/org-babel-R.el > @@ -218,7 +218,32 @@ Currently, insert hline if column names in output have been requested." > (if column-names-p > (cons (car result) (cons 'hline (cdr result))) > result)) > - > + > + > +(defcustom org-babel-R-edit-src-show-process nil > + "Layout of windows while editing R source blocks in org files" > + :group 'org-babel > + :type '(choice (const :tag "No process buffer" nil) > + (const :tag "Show source block and process buffer" "full") > + (const :tag "Show org file, source block and process buffer" "split"))) > + > +(defadvice org-edit-src-code (around org-edit-src-code-with-R-process activate) > + "Display process buffer when eidting R source code blocks" > + (if org-babel-R-edit-src-show-process > + (let* ((info (org-babel-get-src-block-info)) > + (lang (first info)) > + (R-src-block (and info (string= (upcase lang) "R")))) > + ad-do-it > + (when R-src-block > + (cond ((string= org-babel-R-edit-src-show-process "split") > + (split-window-vertically) > + (ess-switch-to-end-of-ESS) > + (other-window -1)) > + ((string= org-babel-R-edit-src-show-process "full") > + (delete-other-windows) > + (ess-switch-to-end-of-ESS) > + (other-window 1))))) > + ad-do-it)) > > (provide 'org-babel-R) > ;;; org-babel-R.el ends here