emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ernesto Durante <stobossey@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] babel: ob-C with Visual C++ and compilation-mode
Date: Mon, 25 Aug 2014 18:35:36 +0200	[thread overview]
Message-ID: <87bnr8zfvr.fsf_-_@gmail.com> (raw)
In-Reply-To: <87wqa1cii9.fsf@gmail.com> (Eric Schulte's message of "Sun, 17 Aug 2014 22:40:52 -0400")

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

Eric Schulte <schulte.eric@gmail.com> writes:

Hi Eric,

You will find in attachment three patches

+ First patch, modify org-babel-eval to load compilation-mode in case of errors 

+ Second patch, modify org-babel-eval to deal with Microsoft visual
C++ errors by concatenating the standard output with the standard error

+ Third patch, add to ob-C the missing function org-babel-expand-body:cpp

Best
Ernesto


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-babel-eval-compilation-mode-to-deal-with-errors-.patch --]
[-- Type: text/x-patch, Size: 886 bytes --]

From 3e4f163a2b357c58a52b7811539ff4032d432aaf Mon Sep 17 00:00:00 2001
From: Ernesto Durante <edurante@localhost.localdomain>
Date: Mon, 25 Aug 2014 17:27:24 +0200
Subject: [PATCH 1/3] org-babel-eval: compilation-mode to deal with errors in
 (C/C++/D)

---
 lisp/ob-eval.el | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 057590f..9fbbb42 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -57,6 +57,12 @@ STDERR with `org-babel-eval-error-notify'."
 	  (progn
 	    (with-current-buffer err-buff
 	      (org-babel-eval-error-notify exit-code (buffer-string)))
+	    (save-excursion
+	      (when (get-buffer org-babel-error-buffer-name)
+		(with-current-buffer org-babel-error-buffer-name
+		  (compilation-mode)
+		  ;;compilation-mode enforces read-only
+		  (read-only-mode 0))))
 	    nil)
 	(buffer-string)))))
 
-- 
1.8.3.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-babel-eval-showing-Microsoft-Visual-C-errors.patch --]
[-- Type: text/x-patch, Size: 1702 bytes --]

From 9e306dbb39325998a5149840b229ffa802ec40e9 Mon Sep 17 00:00:00 2001
From: Ernesto Durante <edurante@localhost.localdomain>
Date: Mon, 25 Aug 2014 17:54:51 +0200
Subject: [PATCH 2/3] org-babel-eval: showing Microsoft Visual C++ errors

---
 lisp/ob-eval.el | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 9fbbb42..0e69583 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -53,18 +53,21 @@ STDERR with `org-babel-eval-error-notify'."
       (setq exit-code
 	    (org-babel--shell-command-on-region
 	     (point-min) (point-max) cmd err-buff))
-      (if (or (not (numberp exit-code)) (> exit-code 0))
-	  (progn
-	    (with-current-buffer err-buff
-	      (org-babel-eval-error-notify exit-code (buffer-string)))
-	    (save-excursion
-	      (when (get-buffer org-babel-error-buffer-name)
-		(with-current-buffer org-babel-error-buffer-name
-		  (compilation-mode)
-		  ;;compilation-mode enforces read-only
-		  (read-only-mode 0))))
-	    nil)
-	(buffer-string)))))
+      (let ((outb-str (buffer-string)))
+	;;outb-str holds standard output + body
+	(if (or (not (numberp exit-code)) (> exit-code 0))
+	    (progn
+	      (with-current-buffer err-buff
+		(org-babel-eval-error-notify exit-code
+					     (concat outb-str (buffer-string))))
+	      (save-excursion
+		(when (get-buffer org-babel-error-buffer-name)
+		  (with-current-buffer org-babel-error-buffer-name
+		    (compilation-mode)
+		    ;;compilation-mode enforces read-only
+		    (read-only-mode 0))))
+	      nil)
+	  outb-str)))))
 
 (defun org-babel-eval-read-file (file)
   "Return the contents of FILE as a string."
-- 
1.8.3.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ob-C-fix-missing-function-org-babel-expand-body-cpp.patch --]
[-- Type: text/x-patch, Size: 893 bytes --]

From c93e02a52d57a5eeb7b9b8aba04c6764f8122d5c Mon Sep 17 00:00:00 2001
From: Ernesto Durante <edurante@localhost.localdomain>
Date: Mon, 25 Aug 2014 18:16:01 +0200
Subject: [PATCH 3/3] ob-C: fix missing function org-babel-expand-body:cpp

---
 lisp/ob-C.el | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 2e146d4..076276e 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -82,6 +82,11 @@ is currently being evaluated.")
 This function calls `org-babel-execute:C++'."
   (org-babel-execute:C++ body params))
 
+(defun org-babel-expand-body:cpp (body params)
+  "Expand a block of C++ code with org-babel according to it's
+header arguments."
+  (org-babel-expand-body:C++ body params))
+
 (defun org-babel-execute:C++ (body params)
   "Execute a block of C++ code with org-babel.
 This function is called by `org-babel-execute-src-block'."
-- 
1.8.3.1


[-- Attachment #5: Type: text/plain, Size: 2688 bytes --]




> Hi Ernesto,
>
> This looks like a good change and I'd like to apply it.  Could you
> re-submit this commit after doing the following.
>
> 1. ensure no lines go beyond 80 characters in length
> 2. remove all lines which include only closing parens
>    (such lines are generally considered bad lisp style)
> 3. commit to your local git repository with "git commit"
> 4. format the patch with "git format-patch"
>
> Thanks,
> Eric
>
> Ernesto Durante <stobossey@gmail.com> writes:
>
>> Hi,
>>
>> I am using ob-C with gcc and Microsoft Visual C++. These two compilers
>> have two different behaviours for outputting  errors. Gcc uses the
>> standard error output and Visual C++ uses the regular output. 
>> Under Windows, errors are not displayed because of the way
>> org-babel-eval is coded. To work on both platforms, the standard
>> output must be concatenated with the standard error.
>>
>> I modified the org-babel-eval in the following way.
>>
>>
>> diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
>> index 057590f..1a93460 100644
>> --- a/lisp/ob-eval.el
>> +++ b/lisp/ob-eval.el
>> @@ -53,12 +53,20 @@ STDERR with `org-babel-eval-error-notify'."
>>        (setq exit-code
>>  	    (org-babel--shell-command-on-region
>>  	     (point-min) (point-max) cmd err-buff))
>> -      (if (or (not (numberp exit-code)) (> exit-code 0))
>> -	  (progn
>> -	    (with-current-buffer err-buff
>> -	      (org-babel-eval-error-notify exit-code (buffer-string)))
>> -	    nil)
>> -	(buffer-string)))))
>> +	(let ((temp-buffer-str (buffer-string))) ;;temp-buffer-str holds standard output + body
>> +	  (if (or (not (numberp exit-code)) (> exit-code 0))
>> +	      (progn
>> +		(with-current-buffer err-buff
>> +		  (org-babel-eval-error-notify exit-code (format "%s%s" temp-buffer-str (buffer-string)))
>> +		  )
>> +		(save-excursion
>> +		  (when (get-buffer org-babel-error-buffer-name)
>> +		    (with-current-buffer org-babel-error-buffer-name
>> +		      (compilation-mode)
>> +		      (read-only-mode 0)
>> +		      )))
>> +		nil)
>> +	    temp-buffer-str)))))
>>
>>
>> One suggestion. It will be nice to put the error buffer in
>> compilation-mode, this way errors are highlighted and we can jump
>> directly into the source code. I modified org-babel-eval to launch the
>> compilation mode in case of errors. I also removed the read-only
>> attribute, else the buffer content of org-babel-error-buffer-name cannot
>> be erased.
>>
>> Clearly, it's not a good patch because org-babel-eval seems to be
>> a core function in babel. Maybe for ob-C, this function should be
>> replaced by a new function. 
>>
>> Thanks to everyone for orgmode and babel to exist. 
>>
>> Best
>> Ernesto
>>

  parent reply	other threads:[~2014-08-25 16:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 16:16 babel: ob-C with Visual C++ and compilation-mode Ernesto Durante
2014-08-11 19:40 ` Thierry Banel
2014-08-12 14:24   ` Ernesto Durante
2014-08-12 22:03     ` Thierry Banel
2014-08-13 20:58       ` Ernesto Durante
2014-08-14 20:40         ` Thierry Banel
2014-08-15 17:22           ` Ernesto Durante
2014-08-17 11:20             ` Thierry Banel
2014-08-18 11:19               ` Ernesto Durante
2014-08-18 12:51                 ` Eric Schulte
2014-08-24 13:05                   ` Ernesto Durante
2014-08-28 14:02                     ` Eric Schulte
2014-08-18 19:59                 ` Thierry Banel
2014-08-20 20:40                   ` Ernesto Durante
2014-08-21 19:48                     ` Thierry Banel
2014-08-24 12:57                       ` Ernesto Durante
2014-08-28 19:44                         ` Thierry Banel
2014-08-18  2:41         ` Eric Schulte
2014-08-18  2:40 ` Eric Schulte
2014-08-23 11:03   ` Ernesto Durante
2014-08-25 16:35   ` Ernesto Durante [this message]
2014-08-28 14:46     ` [PATCH] " Eric Schulte
2014-09-10  9:27       ` Achim Gratz

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnr8zfvr.fsf_-_@gmail.com \
    --to=stobossey@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).