emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] [babel] Add option to display process buffer when editing R source code blocks
@ 2010-04-07 14:41 Julien Barnier
  2010-04-08 20:02 ` Dan Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Barnier @ 2010-04-07 14:41 UTC (permalink / raw)
  To: emacs-orgmode

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.

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
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [babel] Add option to display process buffer when editing R source code blocks
  2010-04-07 14:41 [PATCH] [babel] Add option to display process buffer when editing R source code blocks Julien Barnier
@ 2010-04-08 20:02 ` Dan Davison
  2010-04-13  9:46   ` Julien Barnier
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Davison @ 2010-04-08 20:02 UTC (permalink / raw)
  To: Julien Barnier; +Cc: emacs-orgmode

Julien Barnier <julien@no-log.org> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [babel] Add option to display process buffer when editing R source code blocks
  2010-04-08 20:02 ` Dan Davison
@ 2010-04-13  9:46   ` Julien Barnier
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Barnier @ 2010-04-13  9:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi Dan,

> 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.

Ah, yes, I didn't notice the existence of
org-babel-switch-to-session. It is indeed much cleaner that my patch
:-)

The "features" I would miss compared top my quick and dirty-function
is the fact that the source code buffer is displayed above the session
one (I really don't like having the session above), the fact that when
I quit the source code editing, the session buffer is closed too, and
the ability to keep org file buffer open with the source and the
session ones.

I can reproduce the behavios I was looking for with the following
modifications to your function. But this is another quick and dirty
hack, and I can't say if it cuold meet the needs of others :

(defun dan/org-babel-switch-to-code-with-session (&optional arg keep-org)
    "Switch to code edit buffer and display session. If keep-org is
    non nil, keep the org file buffer open, too."
    (interactive "P")
    (let ((info (org-babel-get-src-block-info)))
      (org-edit-src-code)
      (if keep-org
        (split-window-vertically)
        (delete-other-windows))
      (save-excursion
      (org-babel-switch-to-session arg info))
      (other-window -1)))

I think I'll stick with this function for the moment. 

> 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.

Ah yes, didn't know these ones either...

> 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.

Yes, I feel I have some more customization opportunities lying in
these documentation pages... 

Thanks for your detailed answer !

-- 
Julien

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-13  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-07 14:41 [PATCH] [babel] Add option to display process buffer when editing R source code blocks Julien Barnier
2010-04-08 20:02 ` Dan Davison
2010-04-13  9:46   ` Julien Barnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).