From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Brandon Guttersohn Newsgroups: gmane.emacs.devel Subject: Possible fix for :includes header argument in org-babel C source blocks Date: Tue, 28 Apr 2020 19:48:01 -0500 Message-ID: <21b0cd85-d678-2fe6-3c22-e41abc6cf242@guttersohn.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------49DCC9EB0F1A628BAF781FF6" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="110120"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 29 03:41:59 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTbja-000SXp-Oz for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Apr 2020 03:41:58 +0200 Original-Received: from localhost ([::1]:35144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTbjZ-00009X-S3 for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Apr 2020 21:41:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40634) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTatg-0004x2-2o for emacs-devel@gnu.org; Tue, 28 Apr 2020 20:48:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTatf-0000KR-3n for emacs-devel@gnu.org; Tue, 28 Apr 2020 20:48:19 -0400 Original-Received: from mout-p-202.mailbox.org ([2001:67c:2050::465:202]:11636) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1jTate-00086k-19 for emacs-devel@gnu.org; Tue, 28 Apr 2020 20:48:18 -0400 Original-Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 49Bfy24hWszQlHy for ; Wed, 29 Apr 2020 02:48:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Original-Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id gn7uSSQaDf7A for ; Wed, 29 Apr 2020 02:48:07 +0200 (CEST) Content-Language: en-US X-Rspamd-Queue-Id: ACFD91739 X-Rspamd-Score: -5.39 / 15.00 / 15.00 Received-SPF: permerror client-ip=2001:67c:2050::465:202; envelope-from=brandon@guttersohn.org; helo=mout-p-202.mailbox.org X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2001:67c:2050::465:202 X-Mailman-Approved-At: Tue, 28 Apr 2020 21:41:29 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:248064 Archived-At: This is a multi-part message in MIME format. --------------49DCC9EB0F1A628BAF781FF6 Content-Type: multipart/alternative; boundary="------------FFFA1AA1D5310CB6A2A83CD6" --------------FFFA1AA1D5310CB6A2A83CD6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hey all, I think I may have a small fix for executing C source blocks in org-babel. Or, possibly just a bad case of user error. The issue (in emacs 27 with -q) is that it doesn't seem possible to specify non-system header files with the :includes header argument. For example; while the following line:     #+BEGIN_SRC C :includes ...produces reasonable code...     #include ...all of the following lines...     #+BEGIN_SRC C :includes example.h     #+BEGIN_SRC C :includes "example.h"     #+BEGIN_SRC C :includes "\"example.h\"" ...just result in this...     #include example.h ...rather than this...     #include "example.h" The attached patch will wrap filenames in quotes if they do not begin with "<", and works for me. Is this a reasonable fix, or maybe I'm misusing the feature? --------------FFFA1AA1D5310CB6A2A83CD6 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hey all, I think I may have a small fix for executing C source blocks in org-babel. Or, possibly just a bad case of user error.

The issue (in emacs 27 with -q) is that it doesn't seem possible to specify non-system header files with the :includes header argument.

For example; while the following line:

    #+BEGIN_SRC C :includes <example.h>

...produces reasonable code...

    #include <example.h>

...all of the following lines...

    #+BEGIN_SRC C :includes example.h
    #+BEGIN_SRC C :includes "example.h"
    #+BEGIN_SRC C :includes "\"example.h\""

...just result in this...

    #include example.h

...rather than this...

    #include "example.h"

The attached patch will wrap filenames in quotes if they do not begin with "<", and works for me.

Is this a reasonable fix, or maybe I'm misusing the feature?

--------------FFFA1AA1D5310CB6A2A83CD6-- --------------49DCC9EB0F1A628BAF781FF6 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-support-for-non-system-C-include-directives-in-o.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-support-for-non-system-C-include-directives-in-o.pa"; filename*1="tch" >From e16887fd17c24397b3f9709fcb81e522adab13ee Mon Sep 17 00:00:00 2001 From: Brandon Guttersohn Date: Tue, 28 Apr 2020 19:16:41 -0500 Subject: [PATCH] Fix support for non-system C include directives in org-babel C source blocks in org-babel support an ":includes" header argument, which can generate #include directives prior to execution. Without this patch, only system header files (enclosed in < and >) seem to work, as double quotes are neither added nor preserved. With this patch, any include file name which does not begin with a < character will be wrapped in double quotes. --- lisp/org/ob-C.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/org/ob-C.el b/lisp/org/ob-C.el index 3a26bc014b..00711cad12 100644 --- a/lisp/org/ob-C.el +++ b/lisp/org/ob-C.el @@ -232,7 +232,10 @@ org-babel-C-expand-C (list ;; includes (mapconcat - (lambda (inc) (format "#include %s" inc)) + (lambda (inc) + (if (string-prefix-p "<" inc) + (format "#include %s" inc) + (format "#include \"%s\"" inc))) includes "\n") ;; defines (mapconcat -- 2.24.1 --------------49DCC9EB0F1A628BAF781FF6--