unofficial mirror of emacs-devel@gnu.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; 4+ 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] 4+ 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; 4+ 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] 4+ messages in thread

* Re: 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, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2020-05-03  3:43 UTC (permalink / raw)
  To: Ori; +Cc: brandon, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

How does a system do un-escaping?  With RECAPTCHA?

;-}

-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





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

* Re: Possible fix for :includes header argument in org-babel C source blocks
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2020-05-24 16:25 UTC (permalink / raw)
  To: Brandon Guttersohn; +Cc: emacs-devel

Hi Brandon,

Brandon Guttersohn <brandon@guttersohn.org> writes:

> 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.
>
> [...]
>
> The attached patch will wrap filenames in quotes if they do not begin
> with "<", and works for me.

Thanks for reporting this and for suggesting this patch, I think it is
good enough.  I have applied it to the master branch of Org:

https://code.orgmode.org/bzg/org-mode/commit/44cb98fdb6

Best,

-- 
 Bastien



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

end of thread, other threads:[~2020-05-24 16:25 UTC | newest]

Thread overview: 4+ 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
  -- 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 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).