mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 18:36:26 +00:00
ob-C.el: Add support for specifying namespaces in C/C++
* lisp/ob-C.el (org-babel-C-expand-C): Add a :namespaces export option to C++ org babel blocks. Namespaces specified here will be added to the file in the format 'using namespace %s;'. Multiple namespaces can be specified, separated by spaces. TINYCHANGE
This commit is contained in:
parent
27e5beaa64
commit
0c1b4da1f6
14
etc/ORG-NEWS
14
etc/ORG-NEWS
|
@ -218,6 +218,20 @@ To use =vertica= in an sql =SRC_BLK= set the =:engine= like this:
|
||||||
SELECT * FROM nodes;
|
SELECT * FROM nodes;
|
||||||
,#+END_SRC
|
,#+END_SRC
|
||||||
#+END_EXAMPLE
|
#+END_EXAMPLE
|
||||||
|
**** C++: New header ~:namespaces~
|
||||||
|
|
||||||
|
The new ~:namespaces~ export option can be used to specify namespaces
|
||||||
|
to be used within a C++ org source block. Its usage is similar to
|
||||||
|
~:includes~, in that it can accept multiple, space-separated
|
||||||
|
namespaces to use. This header is equivalent to adding ~using
|
||||||
|
namespace <name>;~ in the source block. Here is a "Hello World" in C++
|
||||||
|
using ~:namespaces~:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
,#+BEGIN_SRC C++ :results output :namespaces std :includes <iostream>
|
||||||
|
cout << "Hello World" << endl;
|
||||||
|
,#+END_SRC
|
||||||
|
#+end_example
|
||||||
|
|
||||||
*** New ~function~ scope argument for the Clock Table
|
*** New ~function~ scope argument for the Clock Table
|
||||||
Added a nullary function that returns a list of files as a possible
|
Added a nullary function that returns a list of files as a possible
|
||||||
|
|
29
lisp/ob-C.el
29
lisp/ob-C.el
|
@ -46,6 +46,19 @@
|
||||||
|
|
||||||
(defvar org-babel-default-header-args:C '())
|
(defvar org-babel-default-header-args:C '())
|
||||||
|
|
||||||
|
(defconst org-babel-header-args:C '((includes . :any)
|
||||||
|
(defines . :any)
|
||||||
|
(main . :any)
|
||||||
|
(flags . :any)
|
||||||
|
(cmdline . :any)
|
||||||
|
(libs . :any))
|
||||||
|
"C/C++-specific header arguments.")
|
||||||
|
|
||||||
|
(defconst org-babel-header-args:C++
|
||||||
|
(append '((namespaces . :any))
|
||||||
|
org-babel-header-args:C)
|
||||||
|
"C++-specific header arguments.")
|
||||||
|
|
||||||
(defcustom org-babel-C-compiler "gcc"
|
(defcustom org-babel-C-compiler "gcc"
|
||||||
"Command used to compile a C source code file into an executable.
|
"Command used to compile a C source code file into an executable.
|
||||||
May be either a command in the path, like gcc
|
May be either a command in the path, like gcc
|
||||||
|
@ -196,15 +209,18 @@ its header arguments."
|
||||||
(colnames (cdr (assq :colname-names params)))
|
(colnames (cdr (assq :colname-names params)))
|
||||||
(main-p (not (string= (cdr (assq :main params)) "no")))
|
(main-p (not (string= (cdr (assq :main params)) "no")))
|
||||||
(includes (org-babel-read
|
(includes (org-babel-read
|
||||||
(or (cdr (assq :includes params))
|
(cdr (assq :includes params))
|
||||||
(org-entry-get nil "includes" t))
|
|
||||||
nil))
|
nil))
|
||||||
(defines (org-babel-read
|
(defines (org-babel-read
|
||||||
(or (cdr (assq :defines params))
|
(cdr (assq :defines params))
|
||||||
(org-entry-get nil "defines" t))
|
nil))
|
||||||
|
(namespaces (org-babel-read
|
||||||
|
(cdr (assq :namespaces params))
|
||||||
nil)))
|
nil)))
|
||||||
(when (stringp includes)
|
(when (stringp includes)
|
||||||
(setq includes (split-string includes)))
|
(setq includes (split-string includes)))
|
||||||
|
(when (stringp namespaces)
|
||||||
|
(setq namespaces (split-string namespaces)))
|
||||||
(when (stringp defines)
|
(when (stringp defines)
|
||||||
(let ((y nil)
|
(let ((y nil)
|
||||||
(result (list t)))
|
(result (list t)))
|
||||||
|
@ -224,6 +240,11 @@ its header arguments."
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (inc) (format "#define %s" inc))
|
(lambda (inc) (format "#define %s" inc))
|
||||||
(if (listp defines) defines (list defines)) "\n")
|
(if (listp defines) defines (list defines)) "\n")
|
||||||
|
;; namespaces
|
||||||
|
(mapconcat
|
||||||
|
(lambda (inc) (format "using namespace %s;" inc))
|
||||||
|
namespaces
|
||||||
|
"\n")
|
||||||
;; variables
|
;; variables
|
||||||
(mapconcat 'org-babel-C-var-to-C vars "\n")
|
(mapconcat 'org-babel-C-var-to-C vars "\n")
|
||||||
;; table sizes
|
;; table sizes
|
||||||
|
|
Loading…
Reference in a new issue