From: Jay Kamat <jaygkamat@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Support for 'using namespace *' in ob-C.el
Date: Mon, 31 Jul 2017 01:03:53 -0700 [thread overview]
Message-ID: <CACe_Yv_o+t29fbg4KWn87EQ5feFFCEOkbAJjPbD3Bm+VqVT1Nw@mail.gmail.com> (raw)
In-Reply-To: <874lu3mcw7.fsf@nicolasgoaziou.fr>
[-- Attachment #1: Type: text/plain, Size: 3548 bytes --]
Hello!
Sorry for the late reply, I was pretty busy last week. An updated
patch is attached!
> 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.
Done. I needed to tweak the code a bit though to get it to work and to
prevent flagging valid C headers as errors with org lint.
> Using `org-entry-get' is no longer supported. You can replace the `or'
> with
>
> (cdr (assq :namespaces params))
Done, I also replaced the other uses of 'org-entry-get' around the one
I modified
> Nitpick: I would put the "\n" on another line.
I agree, and done :)
> Could you also provide an ORG-NEWS entry for the feature?
Done. I'm not sure if it went in the right place and if it's formatted
correctly though, so can you give that a look over to make sure it
looks good?
Thanks again for taking the time to review this for me :D
Let me know if you spot anything fishy or wrong.
Also, RE: Copyright, this is the form I need to send, correct?
http://orgmode.org/request-assign-future.txt
-Jay
On Sun, Jul 23, 2017 at 7:44 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Jay Kamat <jaygkamat@gmail.com> 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
[-- Attachment #2: 0001-ob-C.el-Add-support-for-specifying-namespaces-in-C-C.patch --]
[-- Type: text/x-patch, Size: 3492 bytes --]
From bf08fb4f89024428a95615bdfede86e3c883d87c Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sun, 16 Jul 2017 21:55:24 -0700
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.
TINYCHANGE
---
etc/ORG-NEWS | 14 ++++++++++++++
lisp/ob-C.el | 34 ++++++++++++++++++++++++++++------
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 936ecc36b2..1d08f9ba9d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -200,6 +200,20 @@ To use =vertica= in an sql =SRC_BLK= set the =:engine= like this:
SELECT * FROM nodes;
,#+END_SRC
#+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
Added a nullary function that returns a list of files as a possible
diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 2bdda68d58..ccd150eac9 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -46,6 +46,20 @@
(defvar org-babel-default-header-args:C '())
+;; org lint header arguments for C and 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"
"Command used to compile a C source code file into an executable.
May be either a command in the path, like gcc
@@ -196,15 +210,18 @@ its header arguments."
(colnames (cdr (assq :colname-names params)))
(main-p (not (string= (cdr (assq :main params)) "no")))
(includes (org-babel-read
- (or (cdr (assq :includes params))
- (org-entry-get nil "includes" t))
- nil))
+ (cdr (assq :includes params))
+ nil))
(defines (org-babel-read
- (or (cdr (assq :defines params))
- (org-entry-get nil "defines" t))
- nil)))
+ (cdr (assq :defines params))
+ nil))
+ (namespaces (org-babel-read
+ (cdr (assq :namespaces params))
+ nil)))
(when (stringp includes)
(setq includes (split-string includes)))
+ (when (stringp namespaces)
+ (setq namespaces (split-string namespaces)))
(when (stringp defines)
(let ((y nil)
(result (list t)))
@@ -224,6 +241,11 @@ its header arguments."
(mapconcat
(lambda (inc) (format "#define %s" inc))
(if (listp defines) defines (list defines)) "\n")
+ ;; namespaces
+ (mapconcat
+ (lambda (inc) (format "using namespace %s;" inc))
+ namespaces
+ "\n")
;; variables
(mapconcat 'org-babel-C-var-to-C vars "\n")
;; table sizes
--
2.11.0
next prev parent reply other threads:[~2017-07-31 8:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-17 5:31 [PATCH] Support for 'using namespace *' in ob-C.el Jay Kamat
2017-07-23 14:44 ` Nicolas Goaziou
2017-07-31 8:03 ` Jay Kamat [this message]
2017-07-31 15:34 ` Charles C. Berry
2017-08-01 5:54 ` Jay Kamat
2017-08-01 16:48 ` Nicolas Goaziou
2017-08-01 16:48 ` Nicolas Goaziou
2017-08-02 1:40 ` Jay Kamat
2017-08-02 6:49 ` Nicolas Goaziou
2017-08-01 8:22 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACe_Yv_o+t29fbg4KWn87EQ5feFFCEOkbAJjPbD3Bm+VqVT1Nw@mail.gmail.com \
--to=jaygkamat@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.