emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Creating new org headers from code blocks
@ 2014-09-19 10:04 Rainer M Krug
  2014-09-19 11:45 ` Thorsten Jolitz
  0 siblings, 1 reply; 7+ messages in thread
From: Rainer M Krug @ 2014-09-19 10:04 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1162 bytes --]

Hi

I have some R code which generates several graphics. I would now like to
generate in R text which is then interpreted by org, upon export, as
normal org code. Furthermore, I would like to create new org headers from
the R code. Imagine I have the R code block below. Executed, I get the
results below:

--8<---------------cut here---------------start------------->8---
* Some code block
#+begin_src R :results raw :wrap :exports both
c("** New header", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
#+end_src

#+RESULTS:
#+BEGIN_RESULTS
,** New header
[[./graph1.pdf]]

,** and second header
and some text
#+END_RESULTS
--8<---------------cut here---------------end--------------->8---

I can leave the :wrap, but then the results are not overwritten, but
appended - otherwise it works as expected.

How can I achieve that I get 

,----
| ** New header
| [[./graph1.pdf]]
| 
| ** and second header
| and some text
`----

in the org file, but also that the result gets overwritten upon repeated
execution?

Thanks,

Rainer


-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Creating new org headers from code blocks
  2014-09-19 10:04 Creating new org headers from code blocks Rainer M Krug
@ 2014-09-19 11:45 ` Thorsten Jolitz
  2014-09-19 12:15   ` Rainer M Krug
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-09-19 11:45 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <Rainer@krugs.de> writes:

Hi,

> I have some R code which generates several graphics. I would now like to
> generate in R text which is then interpreted by org, upon export, as
> normal org code. Furthermore, I would like to create new org headers from
> the R code. Imagine I have the R code block below. Executed, I get the
> results below:
>
> --8<---------------cut here---------------start------------->8---
> * Some code block
> #+begin_src R :results raw :wrap :exports both
> c("** New header", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
> #+end_src
>
> #+RESULTS:
> #+BEGIN_RESULTS
> ,** New header
> [[./graph1.pdf]]
>
> ,** and second header
> and some text
> #+END_RESULTS
> --8<---------------cut here---------------end--------------->8---
>
> I can leave the :wrap, but then the results are not overwritten, but
> appended - otherwise it works as expected.
>
> How can I achieve that I get 
>
> ,----
> | ** New header
> | [[./graph1.pdf]]
> | 
> | ** and second header
> | and some text
> `----
>
> in the org file, but also that the result gets overwritten upon repeated
> execution?

I asked about this ':results raw' limitation before and was told to RTFM
;)

(although its not really on the page where I would look for it:
http://orgmode.org/manual/results.html).

You could look-up that thread in the mailing-list for some tips, and/or
use this on a temporary buffer-copy just before you want to act on the
raw results:

#+BEGIN_SRC emacs-lisp :results none
  (defvar tj/fixed-width-to-raw-langs '("R")
    "List of Babel langs for `tj/fixed-width-to-raw-results'.")

  (defun tj/fixed-width-to-raw-results ()
    "Call `org-toggle-fixed-width' on ':results pp'."
    (org-babel-map-src-blocks nil
      (and (member lang tj/toggle-fixed-width-src-block-langs)
           (member "pp" (split-string header-args " " t))
           (save-excursion
             (goto-char (org-babel-where-is-src-block-result))
             (forward-line)
             (while (org-in-fixed-width-region-p)
               (org-toggle-fixed-width)
               (forward-line))))))

#+END_SRC

#+begin_src R :results pp replace
 c("** New header2", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
#+end_src

#+results:
: ** New header2
: [[./graph1.pdf]]
: 
: ** and second header
: and some text

-- 
cheers,
Thorsten

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

* Re: Creating new org headers from code blocks
  2014-09-19 11:45 ` Thorsten Jolitz
@ 2014-09-19 12:15   ` Rainer M Krug
  2014-09-19 12:43     ` Thorsten Jolitz
  0 siblings, 1 reply; 7+ messages in thread
From: Rainer M Krug @ 2014-09-19 12:15 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3243 bytes --]

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Rainer M Krug <Rainer@krugs.de> writes:
>
> Hi,
>
>> I have some R code which generates several graphics. I would now like to
>> generate in R text which is then interpreted by org, upon export, as
>> normal org code. Furthermore, I would like to create new org headers from
>> the R code. Imagine I have the R code block below. Executed, I get the
>> results below:
>>
>> --8<---------------cut here---------------start------------->8---
>> * Some code block
>> #+begin_src R :results raw :wrap :exports both
>> c("** New header", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
>> #+end_src
>>
>> #+RESULTS:
>> #+BEGIN_RESULTS
>> ,** New header
>> [[./graph1.pdf]]
>>
>> ,** and second header
>> and some text
>> #+END_RESULTS
>> --8<---------------cut here---------------end--------------->8---
>>
>> I can leave the :wrap, but then the results are not overwritten, but
>> appended - otherwise it works as expected.
>>
>> How can I achieve that I get 
>>
>> ,----
>> | ** New header
>> | [[./graph1.pdf]]
>> | 
>> | ** and second header
>> | and some text
>> `----
>>
>> in the org file, but also that the result gets overwritten upon repeated
>> execution?
>
> I asked about this ':results raw' limitation before and was told to RTFM
> ;)
>
> (although its not really on the page where I would look for it:
> http://orgmode.org/manual/results.html).

Thanks for pointing me to RTFM - there I found "drawer" and

,----
| #+begin_src R :results  raw drawer 
| c("*** Mean", "[[file:./netimpacts_mean.pdf]]","", "*** Mode","[[file:./netimpacts_mode.pdf]]")
| #+end_src
`----

results in

,----
| #+RESULTS:
| :RESULTS:
| *** Mean
| [[file:./netimpacts_mean.pdf]]
| 
| *** Mode
| [[file:./netimpacts_mode.pdf]]
| :END:
`----

which is nicely highlighted as headers, exported as headers and
replaced.

Perfect.

I don't quite understand your code below and what it is supposed to do.

Thanks,

Rainer

>
> You could look-up that thread in the mailing-list for some tips, and/or
> use this on a temporary buffer-copy just before you want to act on the
> raw results:

>
> #+BEGIN_SRC emacs-lisp :results none
>   (defvar tj/fixed-width-to-raw-langs '("R")
>     "List of Babel langs for `tj/fixed-width-to-raw-results'.")
>
>   (defun tj/fixed-width-to-raw-results ()
>     "Call `org-toggle-fixed-width' on ':results pp'."
>     (org-babel-map-src-blocks nil
>       (and (member lang tj/toggle-fixed-width-src-block-langs)
>            (member "pp" (split-string header-args " " t))
>            (save-excursion
>              (goto-char (org-babel-where-is-src-block-result))
>              (forward-line)
>              (while (org-in-fixed-width-region-p)
>                (org-toggle-fixed-width)
>                (forward-line))))))
>
> #+END_SRC
> #+begin_src R :results pp replace
>  c("** New header2", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
> #+end_src
>
> #+results:
> : ** New header2
> : [[./graph1.pdf]]
> : 
> : ** and second header
> : and some text

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Creating new org headers from code blocks
  2014-09-19 12:15   ` Rainer M Krug
@ 2014-09-19 12:43     ` Thorsten Jolitz
  2014-09-19 12:55       ` Rainer M Krug
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-09-19 12:43 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <Rainer@krugs.de> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
> I don't quite understand your code below and what it is supposed to do.

Drawers are probably better in most cases, but this code lets you use
':results pp replace' while developing, but converts the fixed-width pp
results into raw results when desired (e.g. in a buffer copy before some
action is taken).

>> #+BEGIN_SRC emacs-lisp :results none
>>   (defvar tj/fixed-width-to-raw-langs '("R")
>>     "List of Babel langs for `tj/fixed-width-to-raw-results'.")
>>
>>   (defun tj/fixed-width-to-raw-results ()
>>     "Call `org-toggle-fixed-width' on ':results pp'."
>>     (org-babel-map-src-blocks nil
>>       (and (member lang tj/toggle-fixed-width-src-block-langs)
>>            (member "pp" (split-string header-args " " t))
>>            (save-excursion
>>              (goto-char (org-babel-where-is-src-block-result))
>>              (forward-line)
>>              (while (org-in-fixed-width-region-p)
>>                (org-toggle-fixed-width)
>>                (forward-line))))))
>>
>> #+END_SRC
>> #+begin_src R :results pp replace
>>  c("** New header2", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
>> #+end_src
>>
>> #+results:
>> : ** New header2
>> : [[./graph1.pdf]]
>> : 
>> : ** and second header
>> : and some text

-- 
cheers,
Thorsten

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

* Re: Creating new org headers from code blocks
  2014-09-19 12:43     ` Thorsten Jolitz
@ 2014-09-19 12:55       ` Rainer M Krug
  2014-09-19 13:32         ` Thorsten Jolitz
  0 siblings, 1 reply; 7+ messages in thread
From: Rainer M Krug @ 2014-09-19 12:55 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Rainer M Krug <Rainer@krugs.de> writes:
>
>> Thorsten Jolitz <tjolitz@gmail.com> writes:
>> I don't quite understand your code below and what it is supposed to do.
>
> Drawers are probably better in most cases, but this code lets you use
> ':results pp replace' while developing, but converts the fixed-width pp
> results into raw results when desired (e.g. in a buffer copy before some
> action is taken).

OK - I see. But what is the advantage in this approach? Drawer do
perfectly what I want, i.e. encapsulating an org structure in a for
replacement when re-calculated, inside the drawer they behave like
normal org structure (folding, ...) and upon export they are exported as
org code would be - or am I missing something?

Rainer



>
>>> #+BEGIN_SRC emacs-lisp :results none
>>>   (defvar tj/fixed-width-to-raw-langs '("R")
>>>     "List of Babel langs for `tj/fixed-width-to-raw-results'.")
>>>
>>>   (defun tj/fixed-width-to-raw-results ()
>>>     "Call `org-toggle-fixed-width' on ':results pp'."
>>>     (org-babel-map-src-blocks nil
>>>       (and (member lang tj/toggle-fixed-width-src-block-langs)
>>>            (member "pp" (split-string header-args " " t))
>>>            (save-excursion
>>>              (goto-char (org-babel-where-is-src-block-result))
>>>              (forward-line)
>>>              (while (org-in-fixed-width-region-p)
>>>                (org-toggle-fixed-width)
>>>                (forward-line))))))
>>>
>>> #+END_SRC
>>> #+begin_src R :results pp replace
>>>  c("** New header2", "[[./graph1.pdf]]", "", "** and second header", "and some text" )
>>> #+end_src
>>>
>>> #+results:
>>> : ** New header2
>>> : [[./graph1.pdf]]
>>> : 
>>> : ** and second header
>>> : and some text

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Creating new org headers from code blocks
  2014-09-19 12:55       ` Rainer M Krug
@ 2014-09-19 13:32         ` Thorsten Jolitz
  2014-09-19 13:40           ` Rainer M Krug
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-09-19 13:32 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <Rainer@krugs.de> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Rainer M Krug <Rainer@krugs.de> writes:
>>
>>> Thorsten Jolitz <tjolitz@gmail.com> writes:
>>> I don't quite understand your code below and what it is supposed to do.
>>
>> Drawers are probably better in most cases, but this code lets you use
>> ':results pp replace' while developing, but converts the fixed-width pp
>> results into raw results when desired (e.g. in a buffer copy before some
>> action is taken).
>
> OK - I see. But what is the advantage in this approach? Drawer do
> perfectly what I want, i.e. encapsulating an org structure in a for
> replacement when re-calculated, inside the drawer they behave like
> normal org structure (folding, ...) and upon export they are exported as
> org code would be - or am I missing something?

There are none (for you) then, but it might be useful anyway in some
situations, at least the results look more like part of the document
when you care about the looks of the org file too (not only the export
results). 

-- 
cheers,
Thorsten

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

* Re: Creating new org headers from code blocks
  2014-09-19 13:32         ` Thorsten Jolitz
@ 2014-09-19 13:40           ` Rainer M Krug
  0 siblings, 0 replies; 7+ messages in thread
From: Rainer M Krug @ 2014-09-19 13:40 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1268 bytes --]

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Rainer M Krug <Rainer@krugs.de> writes:
>
>> Thorsten Jolitz <tjolitz@gmail.com> writes:
>>
>>> Rainer M Krug <Rainer@krugs.de> writes:
>>>
>>>> Thorsten Jolitz <tjolitz@gmail.com> writes:
>>>> I don't quite understand your code below and what it is supposed to do.
>>>
>>> Drawers are probably better in most cases, but this code lets you use
>>> ':results pp replace' while developing, but converts the fixed-width pp
>>> results into raw results when desired (e.g. in a buffer copy before some
>>> action is taken).
>>
>> OK - I see. But what is the advantage in this approach? Drawer do
>> perfectly what I want, i.e. encapsulating an org structure in a for
>> replacement when re-calculated, inside the drawer they behave like
>> normal org structure (folding, ...) and upon export they are exported as
>> org code would be - or am I missing something?
>
> There are none (for you) then, but it might be useful anyway in some
> situations, at least the results look more like part of the document
> when you care about the looks of the org file too (not only the export
> results). 

True.

Thanks a lot,

Rainer

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]

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

end of thread, other threads:[~2014-09-19 13:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-19 10:04 Creating new org headers from code blocks Rainer M Krug
2014-09-19 11:45 ` Thorsten Jolitz
2014-09-19 12:15   ` Rainer M Krug
2014-09-19 12:43     ` Thorsten Jolitz
2014-09-19 12:55       ` Rainer M Krug
2014-09-19 13:32         ` Thorsten Jolitz
2014-09-19 13:40           ` Rainer M Krug

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