From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: Creating new org headers from code blocks Date: Fri, 19 Sep 2014 13:45:34 +0200 Message-ID: <87zjdval5t.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUwdU-0005xU-HW for emacs-orgmode@gnu.org; Fri, 19 Sep 2014 07:46:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUwdO-0005B4-TI for emacs-orgmode@gnu.org; Fri, 19 Sep 2014 07:46:00 -0400 Received: from plane.gmane.org ([80.91.229.3]:57919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUwdO-0005AA-NH for emacs-orgmode@gnu.org; Fri, 19 Sep 2014 07:45:54 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XUwdI-000401-RE for emacs-orgmode@gnu.org; Fri, 19 Sep 2014 13:45:48 +0200 Received: from e178189109.adsl.alicedsl.de ([85.178.189.109]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Sep 2014 13:45:48 +0200 Received: from tjolitz by e178189109.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Sep 2014 13:45:48 +0200 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: emacs-orgmode@gnu.org Rainer M Krug 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