emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <eric.schulte@gmx.com>
To: "Olaf.Hamann" <O.Hamann@gmx.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] would like to to do simple text block expansion with parameters or multiline macro replacement text
Date: Sat, 21 Apr 2012 11:33:40 -0400	[thread overview]
Message-ID: <87y5ppnlpn.fsf@gmx.com> (raw)
In-Reply-To: <4F929586.8050005@gmx.net> (Olaf Hamann's message of "Sat, 21 Apr 2012 13:09:58 +0200")

"Olaf.Hamann" <O.Hamann@gmx.net> writes:

>> I think I will try to adapt m4 as org-language so that it can be used
>> for executing src-blocks.
>
> m4 is no solution as it does not support multibyte character
>
>

I missed the beginning of this thread, but would the following very
simple support for text block evaluation be sufficient?

#+begin_src emacs-lisp
(defun org-babel-expand-body:text (body params)
  (mapc
   (lambda (pair)
     (let ((name (symbol-name (car pair)))
           (value (cdr pair)))
       (setq body
             (replace-regexp-in-string
              (concat "\$" (regexp-quote name))
              (if (stringp value) value (format "%S" value))
              body))))
   (mapcar #'cdr (org-babel-get-header params :var)))
  body)

(defun org-babel-execute:text (body params)
  (org-babel-expand-body:text body params))
#+end_src

#+begin_src text :var name="Eric"
  Hi, my name is $name.
#+end_src

#+RESULTS:
: Hi, my name is Eric.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

      reply	other threads:[~2012-04-21 17:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-07 17:22 [babel] would like to to do simple text block expansion with parameters or multiline macro replacement text Olaf.Hamann
2012-04-12 11:04 ` Olaf.Hamann
2012-04-21 11:09   ` Olaf.Hamann
2012-04-21 15:33     ` Eric Schulte [this message]

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=87y5ppnlpn.fsf@gmx.com \
    --to=eric.schulte@gmx.com \
    --cc=O.Hamann@gmx.net \
    --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).