[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [PATCH] Support for 'using namespace *' in ob-C.el
From: |
Nicolas Goaziou |
Subject: |
Re: [O] [PATCH] Support for 'using namespace *' in ob-C.el |
Date: |
Sun, 23 Jul 2017 16:44:08 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Hello,
Jay Kamat <address@hidden> writes:
> 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";
> #+END_SRC
>
>
> Which makes it cleaner and easier to read, especially for very short
> code snippets, using a bunch of std tools.
Good idea.
> 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.
I suggest to add the following to "ob-C.el" so that `org-lint' can issue
a warning whenever :namespaces is used in a C block.
(defconst org-babel-header-args:C '((includes . :any))
"C-specific header arguments.")
(defconst org-babel-header-args:C++
`(,(append '((namespaces . :any))
org-babel-header-args:C))
"C++-specific header arguments.")
> 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.
Thank you. FYI, in many cases, the whole process is very quick and not
time-consuming.
> Subject: [PATCH] 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.
Some comments follow.
> + (namespaces (org-babel-read
> + (or (cdr (assq :namespaces params))
> + (org-entry-get nil "namespaces" t))
> + nil)))
Using `org-entry-get' is no longer supported. You can replace the `or'
with
(cdr (assq :namespaces params))
> + ;; namespaces
> + (mapconcat
> + (lambda (inc) (format "using namespace %s;" inc))
> + namespaces "\n")
Nitpick: I would put the "\n" on another line.
Could you also provide an ORG-NEWS entry for the feature?
Regards,
--
Nicolas Goaziou