From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] Support for 'using namespace *' in ob-C.el Date: Sun, 23 Jul 2017 16:44:08 +0200 Message-ID: <874lu3mcw7.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZNii-0004mz-5r for emacs-orgmode@gnu.org; Sun, 23 Jul 2017 16:43:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZNif-0006de-45 for emacs-orgmode@gnu.org; Sun, 23 Jul 2017 16:43:20 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:39906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dZNie-0006d8-Tt for emacs-orgmode@gnu.org; Sun, 23 Jul 2017 16:43:17 -0400 In-Reply-To: (Jay Kamat's message of "Sun, 16 Jul 2017 22:31:01 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Jay Kamat Cc: emacs-orgmode@gnu.org Hello, Jay Kamat 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 :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