emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] babel: ob-C with Visual C++ and compilation-mode


From: Thierry Banel
Subject: Re: [O] babel: ob-C with Visual C++ and compilation-mode
Date: Mon, 18 Aug 2014 21:59:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

Le 18/08/2014 13:19, Ernesto Durante a écrit :
I think the problem we are trying to integrate C++/C like
Lisp,Python,Haskell or programming languages which can rely on a session
to share their content. In a way, the idea of Babel originated from such
a session oriented languages. 

C++ is very different. We cannot inject codes through a online session.
It's really a non sense. C++ is constructed around the idea of a project
(or a Makefile). A typical C++ project holds header files + source files +
a main file.

As you have pointed out, the current C++ mode, is very specialized for
dealing with a main file. It's right name should be something
like :mainC++ .

So how to deal with a C++ project ? 

I enjoy programming in Qt and I have been trying to integrate into Babel, a Qmake
project. I finally end up by creating three specialized C++ mode:
qheader, qsource and qmain. It was frustating because I couldn't reuse the
standard C++ mode and in some way the core API in ob-C.

It's my personal conclusion that orgmode gives a new light on C++/Qmake
project by making it more accessible more easy to grasp.

Does it make sense to you ?

You are trying to create a C++ project bigger than a few lines, in Org-mode.
This is very close to the idea of "literate programming" from Donal Knuth.
You may find inspiration here:
http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming

There is an example of a "hello world" shell project split over three source blocks.
Here it is translated from Shell to C++ (try it, it works):


#+name: hello-world-prefix
#+begin_src C++ :exports none
  printf ("/-----------------------------------------------------------\\\n");
#+end_src

#+name: hello-world-postfix
#+begin_src C++ :exports none
  printf ("\\-----------------------------------------------------------/\n");
#+end_src

#+name: hello-world-main-begin
#+begin_src C++ :exports none
#include <stdio.h>
int main()
{
#+end_src

#+name: hello-world-main-end
#+begin_src C++ :exports none
  return 0;
}
#+end_src

#+name: hello-world
#+begin_src C++ :tangle hello :exports none :noweb yes :results output
  <<hello-world-main-begin>>
  <<hello-world-prefix>>
  printf ("|                       hello world                         |\n");
  <<hello-world-postfix>>
  <<hello-world-main-end>>
#+end_src

#+RESULTS: hello-world
: /-----------------------------------------------------------\
: |                       hello world                         |
: \-----------------------------------------------------------/




reply via email to

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