From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: export to org, header args disappear Date: Wed, 21 May 2014 02:03:20 -0400 Message-ID: <87oayrr7to.fsf@gmail.com> References: <87lhtvswc3.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmzcs-0004b3-7f for emacs-orgmode@gnu.org; Wed, 21 May 2014 02:03:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmzci-0000BB-S8 for emacs-orgmode@gnu.org; Wed, 21 May 2014 02:03:42 -0400 In-Reply-To: <87lhtvswc3.fsf@bzg.ath.cx> 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: Bastien , Brady Trainor Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 =E2=80=98org-babel-exp-process-buffer=E2=80=99 and the attached patch which= fixes the problem (superficially; I=E2=80=99m not sure if it=E2=80=99s the correct fu= ndamental approach). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-org-fix-export-of-source-blocks-with-header-args.patch >From 7faf58afa659cf63042464dbd15ad62239416832 Mon Sep 17 00:00:00 2001 From: Aaron Ecay 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 --=-=-= Content-Type: text/plain -- Aaron Ecay --=-=-=--