emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ken Mankoff <mankoff@gmail.com>
To: org-mode-email <emacs-orgmode@gnu.org>
Subject: Modify a variable before it is passed to babel (or exported)?
Date: Mon, 16 Sep 2019 10:21:41 -0700	[thread overview]
Message-ID: <87v9ts5f8a.fsf@gmail.com> (raw)


I'd like to modify a variable with a babel block before another block sees the variable. For example, I always want to add one to a variable:

#+NAME: add-one
#+BEGIN_SRC bash :results verbatim :var data=0
data=$(( data + 1 ))
echo $data
#+END_SRC

#+RESULTS: add_one
: 1

Test it:

#+CALL: add_one(data=42)

#+RESULTS:
: 43

Can I use =add_one= to modify data passed elsewhere?

For example, given 

#+NAME: table
| 42 |

I'm having trouble defining a =print_table= function that prints 43, using the =add_one= either via :prologue or <<noweb>> or some other method. Preferably prologue because then the add_one function could be in a different language.


I can get halfway to what I want with a :post option, but need this to be a :pre or :prologue. Example using :post

#+NAME: python_using_add_one
#+BEGIN_SRC python :results output values :post add-one(data=*this*) 
print(42)
#+END_SRC

#+RESULTS: python_using_add_one
: 43

Any suggestions how to use this feature with :pre or :prologue?

Thanks,

  -k

             reply	other threads:[~2019-09-16 17:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16 17:21 Ken Mankoff [this message]
2019-09-16 20:02 ` Modify a variable before it is passed to babel (or exported)? Ken Mankoff

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=87v9ts5f8a.fsf@gmail.com \
    --to=mankoff@gmail.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).