emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: emacs-orgmode@gnu.org
Subject: [patch][babel] Fix for bug in ob-emacs-lisp.el
Date: Thu, 05 Jan 2012 18:20:37 +0000	[thread overview]
Message-ID: <m2d3ayroy2.fsf@btinternet.com> (raw)

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


A block with a comment on the final line of a source block currently
errors in an emacs-lisp block. 

This reduces down to the following at it's simplest:

#+begin_src emacs-lisp
#
#+end_src

Attached is a fix and regression tests

Best, Martyn


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bug-fix-and-tests --]
[-- Type: text/x-patch, Size: 3820 bytes --]

From 4962f73a139566c8f796467a8a0423afbc9c911e Mon Sep 17 00:00:00 2001
From: Martyn Jago <martyn.jago@btinternet.com>
Date: Thu, 5 Jan 2012 18:00:12 +0000
Subject: [PATCH] Bug fix in ob-emacs-lisp.el.

* lisp/ob-emacs-lisp.el: A comment on the last line of an emacs-lisp
code block would cause an error when the block is was executed. This
fix cures this behaviour.

* testing/lisp/test-ob-emacs-lisp.el:  Regression tests for the above
  fix.
---
 lisp/ob-emacs-lisp.el              |   14 +++---
 testing/lisp/test-ob-emacs-lisp.el |   82 ++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 7 deletions(-)
 create mode 100644 testing/lisp/test-ob-emacs-lisp.el

diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index afbc20d..c8af606 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -41,13 +41,13 @@
          (result-params (cdr (assoc :result-params params)))
          (print-level nil) (print-length nil)
          (body (if (> (length vars) 0)
-		   (concat "(let ("
-			 (mapconcat
-			  (lambda (var)
-			    (format "%S" (print `(,(car var) ',(cdr var)))))
-			  vars "\n      ")
-			 ")\n" body ")")
-		 body)))
+		    (concat "(let ("
+			    (mapconcat
+			     (lambda (var)
+			       (format "%S" (print `(,(car var) ',(cdr var)))))
+			     vars "\n      ")
+			    ")\n" body "\n)")
+		 (concat body "\n"))))
     (if (or (member "code" result-params)
 	    (member "pp" result-params))
 	(concat "(pp " body ")") body)))
diff --git a/testing/lisp/test-ob-emacs-lisp.el b/testing/lisp/test-ob-emacs-lisp.el
new file mode 100644
index 0000000..a83e8e9
--- /dev/null
+++ b/testing/lisp/test-ob-emacs-lisp.el
@@ -0,0 +1,82 @@
+;;; test-ob-emacs-lisp.el
+
+;; Copyright (c) 2012 Free Software Foundation, Inc.
+;; Authors: Eric Schulte, Martyn Jago
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Org-mode tests for ob-emacs-lisp.el live here
+
+\f
+;;; Code:
+
+(let ((load-path (cons (expand-file-name
+			".." (file-name-directory
+			      (or load-file-name buffer-file-name)))
+		       load-path)))
+  (require 'org-test)
+  (require 'org-test-ob-consts))
+
+\f
+;;; Tests
+
+(ert-deftest ob-emacs-lisp/commented-last-block-line-no-var ()
+  (org-test-with-temp-text-in-file "
+#+begin_src emacs-lisp
+;;
+#+end_src"
+    (progn
+      (org-babel-next-src-block)
+      (org-ctrl-c-ctrl-c)
+      (should (re-search-forward "results:" nil t))
+      (forward-line)
+      (should
+       (string=
+	"" 
+	(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
+  (org-test-with-temp-text-in-file "
+#+begin_src emacs-lisp
+\"some text\";;
+#+end_src"
+
+    (progn
+      (org-babel-next-src-block)
+      (org-ctrl-c-ctrl-c)
+      (should (re-search-forward "results:" nil t))
+      (forward-line)
+      (should
+       (string=
+	": some text" 
+	(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
+
+(ert-deftest ob-emacs-lisp/commented-last-block-line-with-var ()
+  (org-test-with-temp-text-in-file "
+#+begin_src emacs-lisp :var a=1
+;;
+#+end_src"
+    (progn
+      (org-babel-next-src-block)
+      (org-ctrl-c-ctrl-c)
+      (re-search-forward "results" nil t)
+      (forward-line)
+      (should (string=
+	       "" 
+	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
+  (org-test-with-temp-text-in-file "
+#+begin_src emacs-lisp :var a=2
+2;;
+#+end_src"
+    (progn
+      (org-babel-next-src-block)
+      (org-ctrl-c-ctrl-c)
+      (re-search-forward "results" nil t)
+      (forward-line)
+      (should (string=
+	       ": 2" 
+	       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
+(provide 'test-ob-emacs-lisp)
+
+ ;;; test-ob-emacs-lisp.el ends here
-- 
1.7.3.4


             reply	other threads:[~2012-01-05 18:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05 18:20 Martyn Jago [this message]
2012-01-06  7:29 ` [patch][babel] Fix for bug in ob-emacs-lisp.el Eric Schulte

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=m2d3ayroy2.fsf@btinternet.com \
    --to=martyn.jago@btinternet.com \
    --cc=emacs-orgmode@gnu.org \
    /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).