all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Possible fix for :includes header argument in org-babel C source blocks
@ 2020-04-29  0:48 Brandon Guttersohn
  2020-05-24 16:25 ` Bastien
  0 siblings, 1 reply; 22+ messages in thread
From: Brandon Guttersohn @ 2020-04-29  0:48 UTC (permalink / raw)
  To: emacs-devel


[-- 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


^ permalink raw reply related	[flat|nested] 22+ messages in thread
* Possible fix for :includes header argument in org-babel C source blocks
@ 2020-05-02 14:37 Ori
  2020-05-03  3:43 ` Richard Stallman
  0 siblings, 1 reply; 22+ messages in thread
From: Ori @ 2020-05-02 14:37 UTC (permalink / raw)
  To: brandon, emacs-devel

Hi Brandon,

Some other interesting test results, the first of which makes me think that string un-escaping could be going too far and perhaps the problem lies elsewhere:

    :includes "example.h\""
results in:
    #includes example.h"

    :includes '("\"/some/path/to/example.h\"" "<example_2.h>")
results in:
    #include "/some/path/to/example.h"
    #include <example_2.h>

That works with just one sting in the list as well:
    :includes '("\"/some/path/to/example.h\"")
results in:
    #include "/some/path/to/example.h"


This is on Emacs 26 with org 9.3.4

Ori



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

end of thread, other threads:[~2020-06-03  4:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-29  0:48 Possible fix for :includes header argument in org-babel C source blocks Brandon Guttersohn
2020-05-24 16:25 ` Bastien
2020-05-27 22:20   ` Kévin Le Gouguec
2020-05-28  2:30     ` Kyle Meyer
2020-05-28  8:25       ` Kévin Le Gouguec
2020-05-28 10:09         ` Kévin Le Gouguec
2020-05-29  2:47           ` Kyle Meyer
2020-05-29 12:41             ` Failing tests (was: Possible fix for :includes header argument in org-babel C source blocks) Kévin Le Gouguec
2020-05-31  4:59               ` Kyle Meyer
2020-06-01 14:48                 ` Failing tests Kévin Le Gouguec
2020-06-01 14:56                   ` Kévin Le Gouguec
2020-06-03  4:20                   ` Kyle Meyer
2020-06-01 13:54               ` Bastien
2020-05-29  3:37           ` Possible fix for :includes header argument in org-babel C source blocks Brandon Guttersohn
2020-05-29  9:57             ` Kévin Le Gouguec
2020-05-30 17:29               ` Brandon Guttersohn
2020-06-01 13:55                 ` Bastien
2020-06-01 20:17                   ` Kévin Le Gouguec
2020-06-02  0:02                     ` Brandon Guttersohn
2020-05-29  2:45         ` Kyle Meyer
  -- strict thread matches above, loose matches on Subject: below --
2020-05-02 14:37 Ori
2020-05-03  3:43 ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.