emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [org-babel] Using the power of ESS inside an R source code block
@ 2010-10-24  9:44 Bernd Weiss
  2010-10-24 10:12 ` Bernd Weiss
  0 siblings, 1 reply; 7+ messages in thread
From: Bernd Weiss @ 2010-10-24  9:44 UTC (permalink / raw)
  To: emacs-orgmode

Dear all,

Yesterday, I spent some time (re-)discovering the power of org-babel and 
R. Everything works well but there is one issue that I find somewhat 
annoying (I apologise if this word is too rude). As a long-time ESS user 
I wish that I could use things like ESS syntax highlighting, indentation 
or some keybindings (e.g. for "<-") inside an R source code block. 
However, with respect to an e-mail from Eric Schulte

http://www.mail-archive.com/emacs-orgmode@gnu.org/msg22301.html

(or this one: 
https://stat.ethz.ch/pipermail/ess-help/2009-September/005544.html )

this seems to be a feature wich is hard to realise inside org-babel. Is 
this (still) correct? Or is it a problem with my 
installation/initialisation of org-mode/org-babel?[1]

Thanks,

Bernd


[1] This is the org-mode part in my .emacs:

;; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

(global-font-lock-mode 1)                     ; for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
;;(setq org-ditaa-jar-path 
"D:/programme/emacs/site-lisp/org-mode/contrib/scripts/ditaa.jar")

(setq org-directory "e:/projects/org/")
	
(setq org-confirm-babel-evaluate nil)

;; active Babel languages
(setq org-babel-load-languages
	(quote ((emacs-lisp . t)
		(R . t)
		(python . t)
			)
		)
	)

(setq org-src-fontify-natively t)

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-24  9:44 [org-babel] Using the power of ESS inside an R source code block Bernd Weiss
@ 2010-10-24 10:12 ` Bernd Weiss
  2010-10-25 14:29   ` Eric Schulte
  0 siblings, 1 reply; 7+ messages in thread
From: Bernd Weiss @ 2010-10-24 10:12 UTC (permalink / raw)
  To: emacs-orgmode

Am 24.10.2010 05:44, schrieb Bernd Weiss:
> Dear all,
>
> Yesterday, I spent some time (re-)discovering the power of org-babel
> and R. Everything works well but there is one issue that I find
> somewhat annoying (I apologise if this word is too rude). As a
> long-time ESS user I wish that I could use things like ESS syntax
> highlighting, indentation or some keybindings (e.g. for "<-") inside
> an R source code block. However, with respect to an e-mail from Eric
> Schulte
>
> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg22301.html
>
> (or this one:
> https://stat.ethz.ch/pipermail/ess-help/2009-September/005544.html )
>
> this seems to be a feature wich is hard to realise inside org-babel.
> Is this (still) correct? Or is it a problem with my
> installation/initialisation of org-mode/org-babel?[1]


Ok, one workaround are indirect buffers, right? This blog post is really 
helpful (see "A note about syntax highlighting in Emacs")

http://blogisticreflections.wordpress.com/2010/05/23/introduction-to-using-r-with-org-babel-part-1/

Bernd

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-24 10:12 ` Bernd Weiss
@ 2010-10-25 14:29   ` Eric Schulte
  2010-10-26 14:05     ` Dan Davison
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2010-10-25 14:29 UTC (permalink / raw)
  To: Bernd Weiss; +Cc: emacs-orgmode

Hi Bernd,

It seems that you have already found the best solution in the indirect
edit buffers (by calling C-c ' from inside of a code block).  I would
only add that in the email you mentioned below, I was specifically
talking about syntax highlighting of R code in Org-mode buffers, which
at the time I believed was not possible.  It would seem I was wrong, as
such syntax highlighting is now implemented in recent versions of
Org-mode through setting the `org-src-fontify-natively' variable.

Hope you enjoy using Org-mode with Ess.

Best -- Eric

Bernd Weiss <bernd.weiss@uni-koeln.de> writes:

> Am 24.10.2010 05:44, schrieb Bernd Weiss:
>> Dear all,
>>
>> Yesterday, I spent some time (re-)discovering the power of org-babel
>> and R. Everything works well but there is one issue that I find
>> somewhat annoying (I apologise if this word is too rude). As a
>> long-time ESS user I wish that I could use things like ESS syntax
>> highlighting, indentation or some keybindings (e.g. for "<-") inside
>> an R source code block. However, with respect to an e-mail from Eric
>> Schulte
>>
>> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg22301.html
>>
>> (or this one:
>> https://stat.ethz.ch/pipermail/ess-help/2009-September/005544.html )
>>
>> this seems to be a feature wich is hard to realise inside org-babel.
>> Is this (still) correct? Or is it a problem with my
>> installation/initialisation of org-mode/org-babel?[1]
>
>
> Ok, one workaround are indirect buffers, right? This blog post is
> really helpful (see "A note about syntax highlighting in Emacs")
>
> http://blogisticreflections.wordpress.com/2010/05/23/introduction-to-using-r-with-org-babel-part-1/
>
> Bernd
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-25 14:29   ` Eric Schulte
@ 2010-10-26 14:05     ` Dan Davison
  2010-10-27  0:35       ` Bernd Weiss
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Davison @ 2010-10-26 14:05 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Bernd Weiss, emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Hi Bernd,
>
> It seems that you have already found the best solution in the indirect
> edit buffers (by calling C-c ' from inside of a code block).  I would
> only add that in the email you mentioned below, I was specifically
> talking about syntax highlighting of R code in Org-mode buffers, which
> at the time I believed was not possible.  It would seem I was wrong, as
> such syntax highlighting is now implemented in recent versions of
> Org-mode through setting the `org-src-fontify-natively' variable.
>
> Hope you enjoy using Org-mode with Ess.
>
> Best -- Eric
>
> Bernd Weiss <bernd.weiss@uni-koeln.de> writes:
>
>> Am 24.10.2010 05:44, schrieb Bernd Weiss:

Hi Bernd,

>>> Dear all,
>>>
>>> Yesterday, I spent some time (re-)discovering the power of org-babel
>>> and R. Everything works well but there is one issue that I find
>>> somewhat annoying (I apologise if this word is too rude).

Not at all. Good to know what drawbacks users are encountering. I'm
happy to report that all three of the things you mention are now
possible in the Org buffer. You will need to be using a recent version
of Org-mode (i.e. from within the last few weeks).

>>> As a
>>> long-time ESS user I wish that I could use things like ESS syntax
>>> highlighting,

This, as Eric mentioned, is turned on with
`org-src-fontify-natively'. However from your config below it seems you
have set this variable. So that requires some explanation -- please let
us know if syntax highlighting in the Org buffer is working for you or
not.

>>> indentation 

Setting `org-src-tab-acts-natively' causes TAB to have the indenting
effect that you would get in an ESS buffer.[2]

Beyond these two variables, there is a general method that addresses the
issues you are raising. It involves using the function
`org-babel-do-key-sequence-in-edit-buffer'. For example, here is how to
make C-M-\ perform language-specific indentation on the active region in
the source block:

  (defun dan/org-indent-region ()
    (interactive)
    (or (org-babel-do-key-sequence-in-edit-buffer "\C-\M-\\")
        (indent-region)))

   (define-key org-mode-map "\C-\M-\\" 'dan/org-indent-region)


>>> or some keybindings (e.g. for "<-") inside
>>> an R source code block.

This one can be done with

  (defun dan/org-underscore-command ()
    (interactive)
    (or (org-babel-do-key-sequence-in-edit-buffer "_")
        (org-self-insert-command 1)))

   (define-key org-mode-map "_" 'dan/org-underscore-command)

And another one that you may like is for commenting code:

  (defun dan/org-comment-dwim (&optional arg)
    (interactive "P")
    (or (org-babel-do-key-sequence-in-edit-buffer "\M-;")
        (comment-dwim arg)))

   (define-key org-mode-map "\M-;" 'dan/org-comment-dwim)


I hope the above supplies the missing functionality.

Dan

>>> However, with respect to an e-mail from Eric
>>> Schulte
>>>
>>> http://www.mail-archive.com/emacs-orgmode@gnu.org/msg22301.html
>>>
>>> (or this one:
>>> https://stat.ethz.ch/pipermail/ess-help/2009-September/005544.html )
>>>
>>> this seems to be a feature wich is hard to realise inside org-babel.
>>> Is this (still) correct? Or is it a problem with my
>>> installation/initialisation of org-mode/org-babel?[1]
>>
>>
>> Ok, one workaround are indirect buffers, right? This blog post is
>> really helpful (see "A note about syntax highlighting in Emacs")
>>
>> http://blogisticreflections.wordpress.com/2010/05/23/introduction-to-using-r-with-org-babel-part-1/
>>
>> Bernd
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-26 14:05     ` Dan Davison
@ 2010-10-27  0:35       ` Bernd Weiss
  2010-10-27  7:51         ` Sébastien Vauban
  2010-10-27  8:54         ` Dan Davison
  0 siblings, 2 replies; 7+ messages in thread
From: Bernd Weiss @ 2010-10-27  0:35 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Am 26.10.2010 10:05, schrieb Dan Davison:

[...]

>>> Am 24.10.2010 05:44, schrieb Bernd Weiss:

[...]

>>>> Dear all,
>>>>
>>>> Yesterday, I spent some time (re-)discovering the power of org-babel
>>>> and R. Everything works well but there is one issue that I find
>>>> somewhat annoying (I apologise if this word is too rude).
>
> Not at all. Good to know what drawbacks users are encountering. I'm
> happy to report that all three of the things you mention are now
> possible in the Org buffer. You will need to be using a recent version
> of Org-mode (i.e. from within the last few weeks).


Hi Dan & Eric,

Again (and now on-list), thanks a lot for your reply and your help!


>>>> As a
>>>> long-time ESS user I wish that I could use things like ESS syntax
>>>> highlighting,
>
> This, as Eric mentioned, is turned on with
> `org-src-fontify-natively'. However from your config below it seems you
> have set this variable. So that requires some explanation -- please let
> us know if syntax highlighting in the Org buffer is working for you or
> not.

Yes, syntax highlighting seems to be work as expected.


>>>> indentation
>
> Setting `org-src-tab-acts-natively' causes TAB to have the indenting
> effect that you would get in an ESS buffer.[2]

That also works.

I only have a very (very) basic knowledge of elips. So, I guess it is 
possible to change the "depth" of indentation. The current indentation 
behaviour is as follows:

#+BEGIN_SRC R :results output :exports results
   library(MASS)
   plot(1,1)
   for(i in 1:10){
     print(i)
   }
[...]

However, I would prefer...

#+BEGIN_SRC R :results output :exports results
library(MASS)
plot(1,1)
for(i in 1:10){
   print(i)
}
[...]


> Beyond these two variables, there is a general method that addresses the
> issues you are raising. It involves using the function
> `org-babel-do-key-sequence-in-edit-buffer'. For example, here is how to
> make C-M-\ perform language-specific indentation on the active region in
> the source block:
>
>    (defun dan/org-indent-region ()
>      (interactive)
>      (or (org-babel-do-key-sequence-in-edit-buffer "\C-\M-\\")
>          (indent-region)))
>
>     (define-key org-mode-map "\C-\M-\\" 'dan/org-indent-region)
>
>
>>>> or some keybindings (e.g. for "<-") inside
>>>> an R source code block.
>
> This one can be done with
>
>    (defun dan/org-underscore-command ()
>      (interactive)
>      (or (org-babel-do-key-sequence-in-edit-buffer "_")
>          (org-self-insert-command 1)))
>
>     (define-key org-mode-map "_" 'dan/org-underscore-command)
>
> And another one that you may like is for commenting code:
>
>    (defun dan/org-comment-dwim (&optional arg)
>      (interactive "P")
>      (or (org-babel-do-key-sequence-in-edit-buffer "\M-;")
>          (comment-dwim arg)))
>
>     (define-key org-mode-map "\M-;" 'dan/org-comment-dwim)
>
>
> I hope the above supplies the missing functionality.
>
> Dan


Puh, as I told you I only have a very basic understanding of elisp... If 
I do a simple copy and paste, I see this error: "Symbol's value as 
variable is void: org-mode-map". I also guess that I should change 
"dan/org-underscore-command"...

However, you should not care about my little elips problems. You were 
really helpful in solving my most important problems!

Thanks,

Bernd

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-27  0:35       ` Bernd Weiss
@ 2010-10-27  7:51         ` Sébastien Vauban
  2010-10-27  8:54         ` Dan Davison
  1 sibling, 0 replies; 7+ messages in thread
From: Sébastien Vauban @ 2010-10-27  7:51 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bernd,

Bernd Weiss wrote:
> I only have a very (very) basic knowledge of elips. So, I guess it is possible
> to change the "depth" of indentation. The current indentation behaviour is as
> follows:
>
> #+BEGIN_SRC R :results output :exports results
>   library(MASS)
>   plot(1,1)
>   for(i in 1:10){
>     print(i)
>   }
> [...]
>
> However, I would prefer...
>
> #+BEGIN_SRC R :results output :exports results
> library(MASS)
> plot(1,1)
> for(i in 1:10){
>   print(i)
> }
> [...]

For that specific question:

#+begin_src emacs-lisp
;; don't indent the content of a source code block
(setq org-edit-src-content-indentation 0)
#+end_src

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [org-babel] Using the power of ESS inside an R source code block
  2010-10-27  0:35       ` Bernd Weiss
  2010-10-27  7:51         ` Sébastien Vauban
@ 2010-10-27  8:54         ` Dan Davison
  1 sibling, 0 replies; 7+ messages in thread
From: Dan Davison @ 2010-10-27  8:54 UTC (permalink / raw)
  To: Bernd Weiss; +Cc: emacs-orgmode

Bernd Weiss <bernd.weiss@uni-koeln.de> writes:

[...]

>>>>> As a
>>>>> long-time ESS user I wish that I could use things like ESS syntax
>>>>> highlighting,
>>
>> This, as Eric mentioned, is turned on with
>> `org-src-fontify-natively'. However from your config below it seems you
>> have set this variable. So that requires some explanation -- please let
>> us know if syntax highlighting in the Org buffer is working for you or
>> not.
>
> Yes, syntax highlighting seems to be work as expected.
>
>
>>>>> indentation
>>
>> Setting `org-src-tab-acts-natively' causes TAB to have the indenting
>> effect that you would get in an ESS buffer.[2]
>
> That also works.
>

Hi Bernd,

> I only have a very (very) basic knowledge of elips. So, I guess it is
> possible to change the "depth" of indentation. The current indentation
> behaviour is as follows:
>
> #+BEGIN_SRC R :results output :exports results
>   library(MASS)
>   plot(1,1)
>   for(i in 1:10){
>     print(i)
>   }
> [...]
>
> However, I would prefer...
>
> #+BEGIN_SRC R :results output :exports results
> library(MASS)
> plot(1,1)
> for(i in 1:10){
>   print(i)
> }

This should do that:

(setq org-edit-src-content-indentation 0)

Note that even if that variable has a value greater than zero, the
initial spaces are automatically removed when you go to the edit buffer
with C-c ', and also in tangled output.

>> Beyond these two variables, there is a general method that addresses the
>> issues you are raising. It involves using the function
>> `org-babel-do-key-sequence-in-edit-buffer'. For example, here is how to
>> make C-M-\ perform language-specific indentation on the active region in
>> the source block:
>>
>>    (defun dan/org-indent-region ()
>>      (interactive)
>>      (or (org-babel-do-key-sequence-in-edit-buffer "\C-\M-\\")
>>          (indent-region)))
>>
>>     (define-key org-mode-map "\C-\M-\\" 'dan/org-indent-region)
>>

[...]

> Puh, as I told you I only have a very basic understanding of
> elisp... If I do a simple copy and paste, I see this error: "Symbol's
> value as variable is void: org-mode-map".

That doesn't seem right. The above code needs to be evaluated /after/
Org-mode has loaded. But, once Org is loaded, that variable should
exist. For example, you should be able to call up the documentation for
the variable using

C-h v org-mode-map RET

Or alternatively, place the cursor immediately after the "p" of map, and
use C-x C-e to see the value displayed in the minibuffer. Do those work
for you?

How are you evaluating the above code? If you are putting it in your
.emacs and restarting emacs, then make sure it is after the part that
loads Org-mode. As a test, you could also try evaluating it with emacs
and Org-mode running: to evaluate an expression, place the cursor
immediately after the final parenthesis and use C-x C-e.

> I also guess that I should
> change "dan/org-underscore-command"...

As long as the names used in the function definition [the expression
starting "(defun ..."] match the names used in the corresponding
define-key expression then it'll be OK. There's no problem leaving the
names as they are. It tends to be a good idea to reserve names starting
with org- for things that are officially part of Org-mode.

Dan

>
> However, you should not care about my little elips problems. You were
> really helpful in solving my most important problems!
>
> Thanks,
>
> Bernd
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-10-27  8:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-24  9:44 [org-babel] Using the power of ESS inside an R source code block Bernd Weiss
2010-10-24 10:12 ` Bernd Weiss
2010-10-25 14:29   ` Eric Schulte
2010-10-26 14:05     ` Dan Davison
2010-10-27  0:35       ` Bernd Weiss
2010-10-27  7:51         ` Sébastien Vauban
2010-10-27  8:54         ` Dan Davison

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