[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] Support for 'using namespace *' in ob-C.el

From: Jay Kamat
Subject: [O] [PATCH] Support for 'using namespace *' in ob-C.el
Date: Sun, 16 Jul 2017 22:31:01 -0700


A problem that I came across recently was the difficulty of writing
C++ tutorials for beginners to programming in org mode. In such
tutorials, it would be ideal to keep as much boilerplate away from the
examples so they don't ask questions (until we get to those topics).

The shortest ob-C++ example available is:

#+begin_src C++ :includes <iostream>
  std::cout<<"Hello World!\n";

However, it would be nice to add a "using namespace std" to this
source code block, so it can become:

#+BEGIN_SRC C++ :includes <iostream> :namespaces std
  cout << "Hello world\n";

Which makes it cleaner and easier to read, especially for very short
code snippets, using a bunch of std tools.

Attached are patches for adding a :namespaces export option to C++
blocks, and a patch to documentation on worg that documents this

One concern that I have is that "using namespace *;" is only available
in C++ and not C, but there isn't an easy way I could find to limit
it's usage to only C++ blocks without a bunch of restructuring, so
this will fail if you attempt to set a namespace on a plain C block.
Since it's clear that namespaces aren't part of plain C, I don't think
this is too big of a deal.

Please give this a more thorough review than usual, I'm very new to all of this!

Thanks again for creating/maintaining org mode, it's the greatest!

Also, this contribution puts me very close to the 15 line limit before
I need to get FSF papers signed. I intend to sign papers soon, but I'm
a little busy right now, and I'll get around to submitting the request
later on.



I'm getting an error when I try to run:
#+BEGIN_SRC C :exports output :includes stdio.h
printf("hello world\n");
because 'stdio.h' is not surrounded by quotes. I can do <stdio.h> and
have it work fine, but how can I include quotes in the header line?
They seem to be stripped by org, and backslash ecaping them does not

Attachment: 0001-ob-C.el-Add-support-for-specifying-namespaces-in-C-C.patch
Description: Text Data

Attachment: 0001-Add-documentation-for-ob-C-namespaces.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]