From: Brandon Guttersohn <brandon@guttersohn.org>
To: emacs-devel@gnu.org
Subject: Possible fix for :includes header argument in org-babel C source blocks
Date: Tue, 28 Apr 2020 19:48:01 -0500 [thread overview]
Message-ID: <21b0cd85-d678-2fe6-3c22-e41abc6cf242@guttersohn.org> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 857 bytes --]
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?
[-- Attachment #1.2: Type: text/html, Size: 1267 bytes --]
[-- Attachment #2: 0001-Fix-support-for-non-system-C-include-directives-in-o.patch --]
[-- Type: text/x-patch, Size: 1164 bytes --]
From e16887fd17c24397b3f9709fcb81e522adab13ee Mon Sep 17 00:00:00 2001
From: Brandon Guttersohn <brandon@guttersohn.org>
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
next reply other threads:[~2020-04-29 0:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 0:48 Brandon Guttersohn [this message]
2020-05-24 16:25 ` Possible fix for :includes header argument in org-babel C source blocks Bastien
-- strict thread matches above, loose matches on Subject: below --
2020-05-02 14:37 Ori
2020-05-03 3:43 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=21b0cd85-d678-2fe6-3c22-e41abc6cf242@guttersohn.org \
--to=brandon@guttersohn.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.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).