emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Vladimir Alexiev <vladimir@sirma.bg>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-babel-read should have option NOT to interpret as elisp
Date: Sun, 27 Feb 2011 08:51:37 -0700	[thread overview]
Message-ID: <877hclbgxz.fsf@gmail.com> (raw)
In-Reply-To: loom.20110227T151052-783@post.gmane.org

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

Vladimir Alexiev <vladimir@sirma.bg> writes:

> I keep perl regexps in a table, and some of them start with "(".
> I'd like these to be left alone (returned unmodified as a string).
>
> (info "(org)var") doesn't mention special processing of table cells,
> but the doc of org-babel-read says:
>
> Convert the string value of CELL to a number if appropriate.
> Otherwise if cell looks like lisp (meaning it starts with a
> "(" or a "'") then read it as lisp, otherwise return it
> unmodified as a string.
>
> So it seems to me that this special behavior of org-babel-read 
> should be documented in info, and controllable by a user option.
>

When passing values directly through header arguments the solution would
be to wrap the string in double-quotes so that it is interpreted as a
literal string, e.g.,

#+begin_src perl :var it="(+ 1 1)" :results output
  printf "passed in %s", $it
#+end_src

#+results:
: passed in (+ 1 1)

However I do agree that this would be onerous to have to wrap every cell
of a table in double quotes...

I'm attaching a patch which inhibits the lisp evaluation of values read
from tables and lists.  This should solve your issue above.  I'm not
directly applying this patch, because it would be a breaking change for
anyone who is currently relying on the ability to fill a table or list
with to-be-evaluated emacs-lisp statements.  If anyone is in that
situation please respond to this email in the next couple of days,
otherwise I am leaning towards applying this patch to the main
repository.

Best -- Eric

p.s. this patch can be applied with the "git am" command.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-inhibit-lisp-evaluation-of-values-read-from-table.patch --]
[-- Type: text/x-diff, Size: 2700 bytes --]

From f57ff0b724f0420751dd90600553d988aec507f1 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Sun, 27 Feb 2011 08:47:36 -0700
Subject: [PATCH] ob: inhibit lisp evaluation of values read from tables and lists

* lisp/ob.el (org-babel-read-table): Inhibit lisp evaluation of values
  when reading from tables.
  (org-babel-read-list): Inhibit lisp evaluation of values when
  reading from lists.
  (org-babel-read): Add optional argument which can be used to inhibit
  lisp evaluation of value.
---
 lisp/ob.el |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lisp/ob.el b/lisp/ob.el
index 6e98263..b4ce3cd 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -1386,12 +1386,13 @@ following the source block."
   "Read the table at `point' into emacs-lisp."
   (mapcar (lambda (row)
             (if (and (symbolp row) (equal row 'hline)) row
-              (mapcar #'org-babel-read row)))
+              (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval)) row)))
           (org-table-to-lisp)))
 
 (defun org-babel-read-list ()
   "Read the list at `point' into emacs-lisp."
-  (mapcar #'org-babel-read (mapcar #'cadr (cdr (org-list-parse-list)))))
+  (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval))
+	  (mapcar #'cadr (cdr (org-list-parse-list)))))
 
 (defvar org-link-types-re)
 (defun org-babel-read-link ()
@@ -1901,18 +1902,18 @@ block but are passed literally to the \"example-block\"."
 	     (apply #'string (reverse out)))))
        str))))
 
-(defun org-babel-read (cell)
+(defun org-babel-read (cell &optional inhibit-lisp-eval)
   "Convert the string value of CELL to a number if appropriate.
-Otherwise if cell looks like lisp (meaning it starts with a
-\"(\" or a \"'\") then read it as lisp, otherwise return it
-unmodified as a string.
-
-This is taken almost directly from `org-read-prop'."
+Otherwise if cell looks like lisp (meaning it starts with a \"(\"
+or a \"'\") then read it as lisp, otherwise return it unmodified
+as a string.  Optional argument NO-LISP-EVAL inhibits lisp
+evaluation for situations in which is it not appropriate."
   (if (and (stringp cell) (not (equal cell "")))
       (or (org-babel-number-p cell)
-          (if (or (equal "(" (substring cell 0 1))
-                  (equal "'" (substring cell 0 1))
-                  (equal "`" (substring cell 0 1)))
+          (if (and (not inhibit-lisp-eval)
+		   (or (equal "(" (substring cell 0 1))
+		       (equal "'" (substring cell 0 1))
+		       (equal "`" (substring cell 0 1))))
               (eval (read cell))
             (progn (set-text-properties 0 (length cell) nil cell) cell)))
     cell))
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2011-02-27 16:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27 14:14 org-babel-read should have option NOT to interpret as elisp Vladimir Alexiev
2011-02-27 15:51 ` Eric Schulte [this message]
2011-02-27 23:28   ` Vladimir Alexiev
2011-02-27 23:44     ` Eric Schulte
2011-02-28  0:30       ` Vladimir Alexiev
2011-03-01  3:11         ` Eric Schulte
2011-03-01 12:19           ` Vladimir Alexiev
2011-03-01 16:58             ` Eric Schulte
2011-03-02  7:20               ` Vladimir Alexiev
2011-03-02 14:56                 ` Eric Schulte
2011-02-28 10:07   ` Sébastien Vauban
2011-03-01  3:10     ` 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=877hclbgxz.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=vladimir@sirma.bg \
    /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).