emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Greg Minshall <minshall@umich.edu>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: odd behavior for begin_src org :results
Date: Wed, 01 May 2013 17:57:09 -0400	[thread overview]
Message-ID: <19624.1367445429@greg-minshalls-mbp.local> (raw)
In-Reply-To: Your message of "Wed, 01 May 2013 14:01:12 -0600." <87k3ni4ghj.fsf@gmail.com>

Eric,

thanks for the answer.  another "#+begin_src org" question.  it appears
that only *string* values are allowed for any :var that are defined
(i.e., ':var bar="foo"', and *not* ':var bar=3').  since i'm not 100%
sure of the semantics, maybe this is desired.

if one *should* be allowed to pass in, e.g., tables, numbers, etc., then
maybe org-babel-expand-body:org in ob-org.el wants to change from the
current
----
(defun org-babel-expand-body:org (body params)
  (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
    (setq body (replace-regexp-in-string
		(regexp-quote (format "$%s" (car var)))  (cdr var) body
		nil 'literal)))
  body)
----
to something like this
----
  (defun org-babel-expand-body:org (body params)
    (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
      (setq body (replace-regexp-in-string
                  (regexp-quote (format "$%s" (car var)))  
                  (if (stringp (cdr var))
                      (cdr var)
                    (format "%s" (prin1 (cdr var))))
                  body nil 'literal)))
    body)
----
(as otherwise replace-regexp-in-string notices that (cdr var) is *not* a
string, and attempts to execute it.)

maybe^2 it would make even more sense to use the "#+begin_src
emacs-lisp" equivalent routine from ob-emacs-lisp.el as a template?
----
(defun org-babel-expand-body:emacs-lisp (body params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
         (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 "\n)")
		 (concat body "\n"))))
    (if (or (member "code" result-params)
	    (member "pp" result-params))
	(concat "(pp " body ")") body)))
----
(my elisp isn't strong enough to evaluate this.)

cheers, Greg

  reply	other threads:[~2013-05-01 21:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01 19:08 odd behavior for begin_src org :results Greg Minshall
2013-05-01 20:01 ` Eric Schulte
2013-05-01 21:57   ` Greg Minshall [this message]
2013-05-03  7:46     ` Sebastien Vauban
2013-05-03 15:53       ` 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=19624.1367445429@greg-minshalls-mbp.local \
    --to=minshall@umich.edu \
    --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).