emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* export to org, header args disappear
@ 2014-05-16  3:58 Brady Trainor
  2014-05-21  2:24 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Brady Trainor @ 2014-05-16  3:58 UTC (permalink / raw)
  To: emacs-orgmode



I have code blocks such as

#+BEGIN_SRC emacs-lisp :tangle no
...
#+END_SRC

and when I export the file to org, it becomes

#+BEGIN_SRC emacs-lisp
...
#+END_SRC

Is there an option to include the header args on export?

Thank you,

Brady

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

* Re: export to org, header args disappear
  2014-05-16  3:58 export to org, header args disappear Brady Trainor
@ 2014-05-21  2:24 ` Bastien
  2014-05-21  6:03   ` Aaron Ecay
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2014-05-21  2:24 UTC (permalink / raw)
  To: Brady Trainor; +Cc: emacs-orgmode

Hi Brady,

Brady Trainor <algebrat@uw.edu> writes:

> I have code blocks such as
>
> #+BEGIN_SRC emacs-lisp :tangle no
> ...
> #+END_SRC
>
> and when I export the file to org, it becomes
>
> #+BEGIN_SRC emacs-lisp
> ...
> #+END_SRC
>
> Is there an option to include the header args on export?

Not to my knowledge -- I played a bit with implementing a new
"verbatim" value for the :exports parameter, but I finally find
this confusing.  Maybe someone will have better ideas.

-- 
 Bastien

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

* Re: export to org, header args disappear
  2014-05-21  2:24 ` Bastien
@ 2014-05-21  6:03   ` Aaron Ecay
  2014-05-21 12:06     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Aaron Ecay @ 2014-05-21  6:03 UTC (permalink / raw)
  To: Bastien, Brady Trainor; +Cc: emacs-orgmode

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

Hello Bastien and Brady,

The babel/export interface does not attempt to manage the header args
when it rewrites source blocks.  I think this code is pretty subtle.
Check out the (let (... (replacement ...)) ...) code in
‘org-babel-exp-process-buffer’ and the attached patch which fixes the
problem (superficially; I’m not sure if it’s the correct fundamental
approach).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-org-fix-export-of-source-blocks-with-header-args.patch --]
[-- Type: text/x-diff, Size: 4496 bytes --]

From 7faf58afa659cf63042464dbd15ad62239416832 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
Date: Wed, 21 May 2014 01:58:18 -0400
Subject: [PATCH] ox-org: fix export of source blocks with header args

---
 lisp/ob-exp.el              | 52 +++++++++++++++++++++++++--------------------
 testing/lisp/test-ob-exp.el |  6 +++---
 2 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 220a3c3..ce45d84 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -311,7 +311,7 @@ The function respects the value of the :exports header argument."
 	     (org-babel-exp-code info)))))
 
 (defcustom org-babel-exp-code-template
-  "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
+  "#+BEGIN_SRC %lang%switches%params\n%body\n#+END_SRC"
   "Template used to export the body of code blocks.
 This template may be customized to include additional information
 such as the code block name, or the values of particular header
@@ -322,7 +322,7 @@ and the following %keys may be used.
  name ------ the name of the code block
  body ------ the body of the code block
  switches -- the switches associated to the code block
- flags ----- the flags passed to the code block
+ params ---- the parameters passed to the code block
 
 In addition to the keys mentioned above, every header argument
 defined for the code block may be used as a key and will be
@@ -332,27 +332,33 @@ replaced with its value."
 
 (defun org-babel-exp-code (info)
   "Return the original code block formatted for export."
-  (setf (nth 1 info)
-	(if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
-	    (replace-regexp-in-string
-	     (org-babel-noweb-wrap) "" (nth 1 info))
-	  (if (org-babel-noweb-p (nth 2 info) :export)
-	      (org-babel-expand-noweb-references
-	       info org-babel-exp-reference-buffer)
-	    (nth 1 info))))
-  (org-fill-template
-   org-babel-exp-code-template
-   `(("lang"  . ,(nth 0 info))
-     ("body"  . ,(org-escape-code-in-string (nth 1 info)))
-     ("switches" . ,(let ((f (nth 3 info)))
-		      (and (org-string-nw-p f) (concat " " f))))
-     ("flags" . ,(let ((f (assq :flags (nth 2 info))))
-		   (and f (concat " " (cdr f)))))
-     ,@(mapcar (lambda (pair)
-		 (cons (substring (symbol-name (car pair)) 1)
-		       (format "%S" (cdr pair))))
-	       (nth 2 info))
-     ("name"  . ,(or (nth 4 info) "")))))
+  ;; Here we assume that point is in the source block, an assumption
+  ;; we inherit from `org-babel-exp-src-block'.
+  (let* ((sb (org-element-at-point))
+	 (params (org-element-property :parameters sb)))
+    (setf (nth 1 info)
+	  (if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
+	      (replace-regexp-in-string
+	       (org-babel-noweb-wrap) "" (nth 1 info))
+	    (if (org-babel-noweb-p (nth 2 info) :export)
+		(org-babel-expand-noweb-references
+		 info org-babel-exp-reference-buffer)
+	      (nth 1 info))))
+    (org-fill-template
+     org-babel-exp-code-template
+     `(("lang"  . ,(nth 0 info))
+       ("body"  . ,(org-escape-code-in-string (nth 1 info)))
+       ("switches" . ,(let ((f (nth 3 info)))
+			(and (org-string-nw-p f) (concat " " f))))
+       ("flags" . ,(let ((f (assq :flags (nth 2 info))))
+		     (and f (concat " " (cdr f)))))
+       ("params" . ,(when (and params (not (string= params "")))
+		      (concat " " params)))
+       ,@(mapcar (lambda (pair)
+		   (cons (substring (symbol-name (car pair)) 1)
+			 (format "%S" (cdr pair))))
+		 (nth 2 info))
+       ("name"  . ,(or (nth 4 info) ""))))))
 
 (defun org-babel-exp-results (info type &optional silent hash)
   "Evaluate and return the results of the current code block for export.
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index 1fe810b..b5738d5 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -289,7 +289,7 @@ Here is one at the end of a line. =2=
 : 2
 
 #+NAME: src1
-#+BEGIN_SRC emacs-lisp
+#+BEGIN_SRC emacs-lisp :exports both
 \(+ 1 1)
 #+END_SRC"
     (org-test-with-temp-text
@@ -316,9 +316,9 @@ Here is one at the end of a line. =2=
   "Test exporting a source block with a flag."
   (should
    (string-match
-    "\\`#\\+BEGIN_SRC emacs-lisp -some-flag$"
+    "\\`#\\+BEGIN_SRC emacs-lisp -x$"
     (org-test-with-temp-text
-	"#+BEGIN_SRC emacs-lisp :flags -some-flag\n\(+ 1 1)\n#+END_SRC"
+	"#+BEGIN_SRC emacs-lisp -x\n\(+ 1 1)\n#+END_SRC"
       (org-export-execute-babel-code)
       (buffer-string)))))
 
-- 
1.9.3


[-- Attachment #3: Type: text/plain, Size: 15 bytes --]


--
Aaron Ecay

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

* Re: export to org, header args disappear
  2014-05-21  6:03   ` Aaron Ecay
@ 2014-05-21 12:06     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2014-05-21 12:06 UTC (permalink / raw)
  To: Aaron Ecay; +Cc: emacs-orgmode, Brady Trainor

Hi Aaron,

Aaron Ecay <aaronecay@gmail.com> writes:

> The babel/export interface does not attempt to manage the header args
> when it rewrites source blocks.  I think this code is pretty subtle.
> Check out the (let (... (replacement ...)) ...) code in
> ‘org-babel-exp-process-buffer’ and the attached patch which fixes the
> problem (superficially; I’m not sure if it’s the correct fundamental
> approach).

I'm not sure either this is fundamentally correct, but it works fine
for me.  I'll let Eric decide on whether this can go to master or not,
and if Eric does not have the time, just go ahead and push the change.

Thanks for this!

-- 
 Bastien

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

end of thread, other threads:[~2014-05-21 12:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-16  3:58 export to org, header args disappear Brady Trainor
2014-05-21  2:24 ` Bastien
2014-05-21  6:03   ` Aaron Ecay
2014-05-21 12:06     ` Bastien

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