From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: Bug: Cannot set header-args :includes with multiple includes [8.2.7 (8.2.7-4-g880362-elpa @ /home/will/.emacs.d/elpa/org-20140616/)] Date: Thu, 04 Sep 2014 21:47:47 +0200 Message-ID: <5408C1E3.2090102@free.fr> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030405080904000203020503" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPd0e-0006ap-6B for emacs-orgmode@gnu.org; Thu, 04 Sep 2014 15:48:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPd0X-0006cz-Pw for emacs-orgmode@gnu.org; Thu, 04 Sep 2014 15:47:56 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:56565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPd0X-0006bV-JK for emacs-orgmode@gnu.org; Thu, 04 Sep 2014 15:47:49 -0400 Received: from [IPv6:2a01:e35:2e21:def0:a139:a609:75f6:1ea1] (unknown [IPv6:2a01:e35:2e21:def0:a139:a609:75f6:1ea1]) by smtp1-g21.free.fr (Postfix) with ESMTP id 479EF940034 for ; Thu, 4 Sep 2014 21:47:48 +0200 (CEST) In-Reply-To: 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 This is a multi-part message in MIME format. --------------030405080904000203020503 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Le 26/08/2014 18:24, Will Everett a =C3=A9crit : > > > I believe the :includes header argument is incorrectly parsing lists > of includes for c++. This snippet: > > #+BEGIN_SRC C++ :includes > using namespace std; > printf("Hello "); > cout << "world"; > #+END_SRC > > produces a compiler error: > > warning: extra tokens at end of #include directive > #include > > Here is a patch to fix the issue. The :includes, :defines, :imports headers have been extended to accept multiple items without parenthesis. All the following forms are now allow= ed: :includes :includes "strings.h" :includes '( ) :includes (mapcar (lambda (x) (concat "")) '("abc" "def" "ghi")) (same for :imports) :defines AA 22 BB 33 :defines "AA 22 BB 33" :defines '("abc 123" "def 456") :defines (mapcar (lambda (x) (concat x " " x "_def")) '("A" "BB" "CCC")) This works either in the header as here: #+BEGIN_SRC C++ :includes "strings.h" #+END_SRC or in a property drawer, like that: :PROPERTIES: :includes: "strings.h" :END: Have fun Thierry --------------030405080904000203020503 Content-Type: text/x-diff; name="0001-Enable-multiple-files-in-includes-header.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Enable-multiple-files-in-includes-header.patch" >From 63ab1d364f0e425d8d02ce946021611a1a3b7ce6 Mon Sep 17 00:00:00 2001 From: Thierry Banel Date: Thu, 4 Sep 2014 19:30:54 +0200 Subject: [PATCH] Enable multiple files in :includes header * ob-C.el (org-babel-C-expand-C) (org-babel-C-expand-D): :includes, :defines, :imports now accept several items separated by blanks without enclosing them in parenthesis. Thanks to Will Everett for reporting this. --- lisp/ob-C.el | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lisp/ob-C.el b/lisp/ob-C.el index 076276e..c42ccea 100644 --- a/lisp/ob-C.el +++ b/lisp/ob-C.el @@ -186,13 +186,26 @@ it's header arguments." (let ((vars (mapcar #'cdr (org-babel-get-header params :var))) (colnames (cdar (org-babel-get-header params :colname-names))) (main-p (not (string= (cdr (assoc :main params)) "no"))) - (includes (or (cdr (assoc :includes params)) - (org-babel-read (org-entry-get nil "includes" t)))) + (includes (org-babel-read + (or (cdr (assoc :includes params)) + (org-entry-get nil "includes" t)) + nil)) (defines (org-babel-read (or (cdr (assoc :defines params)) - (org-babel-read (org-entry-get nil "defines" t)))))) - (unless (listp includes) (setq includes (list includes))) + (org-entry-get nil "defines" t)) + nil))) + (when (stringp includes) + (setq includes (split-string includes))) (setq includes (append includes '("" "" ""))) + (when (stringp defines) + (let ((y nil) + (result (list t))) + (dolist (x (split-string defines)) + (if (null y) + (setq y x) + (nconc result (list (concat y " " x))) + (setq y nil))) + (setq defines (cdr result)))) (mapconcat 'identity (list ;; includes @@ -225,7 +238,8 @@ it's header arguments." (main-p (not (string= (cdr (assoc :main params)) "no"))) (imports (or (cdr (assoc :imports params)) (org-babel-read (org-entry-get nil "imports" t))))) - (unless (listp imports) (setq imports (list imports))) + (when (stringp imports) + (setq imports (split-string imports))) (setq imports (append imports '("std.stdio" "std.conv"))) (mapconcat 'identity (list -- 1.9.1 --------------030405080904000203020503--