emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Inject value of macro into code using a variable
@ 2019-10-15 16:37 wlharvey4 via Emacs-orgmode
  2019-10-15 19:42 ` Nicolas Goaziou
  2019-10-16  6:23 ` Fraga, Eric
  0 siblings, 2 replies; 3+ messages in thread
From: wlharvey4 via Emacs-orgmode @ 2019-10-15 16:37 UTC (permalink / raw)
  To: emacs-orgmode

Is it possible to inject the value of a macro into code using a variable?

I set a macro called ‘version’ with a version number at the top of my .org file.  I would like to do something like this:

#+macro:version Version 0.2.5

#+name:code-name
#+begin_src js :tangle some-file.js :var ver={{{version}}} :exports both :results output
const version = ver;
#+end_src

When this code is evaluated during export, there is an error:

org-babel-ref-resolve: Reference ‘{{{version}}}’ not found in this buffer

Regards,
Wesley

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Inject value of macro into code using a variable
  2019-10-15 16:37 Inject value of macro into code using a variable wlharvey4 via Emacs-orgmode
@ 2019-10-15 19:42 ` Nicolas Goaziou
  2019-10-16  6:23 ` Fraga, Eric
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2019-10-15 19:42 UTC (permalink / raw)
  To: wlharvey4 via Emacs-orgmode; +Cc: wlharvey4

Hello,

wlharvey4 via Emacs-orgmode <emacs-orgmode@gnu.org> writes:

> Is it possible to inject the value of a macro into code using
> a variable?

No, macros are mostly text replacement. They are not Babel related.

You may want to pass arguments to Babel blocks using other Babel blocks.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Inject value of macro into code using a variable
  2019-10-15 16:37 Inject value of macro into code using a variable wlharvey4 via Emacs-orgmode
  2019-10-15 19:42 ` Nicolas Goaziou
@ 2019-10-16  6:23 ` Fraga, Eric
  1 sibling, 0 replies; 3+ messages in thread
From: Fraga, Eric @ 2019-10-16  6:23 UTC (permalink / raw)
  To: wlharvey4 via Emacs-orgmode; +Cc: wlharvey4@mac.com

On Tuesday, 15 Oct 2019 at 09:37, wlharvey4 via Emacs-orgmode wrote:
> Is it possible to inject the value of a macro into code using a variable?

I use properties for this, as in:

#+begin_src org
  ,#+property: version 2.0.5
  ,#+header: :var version=(esf/get-parameter "benzenefeed")
  [...]
  ,#+begin_src somelanguage
  [... code that uses version ...]
  ,#+end_src
#+end_src

where
#+begin_src emacs-lisp
  (defun esf/get-parameter (p)
    (let ((value (org-entry-get (point) p 'inherit)))
      (message "parameter %s value obtained %s" p value)
      (if value
          (if (string-match-p "^[-+ ]*[[:digit:].]+$" value)
              (string-to-number value)
            value)
        (error "Property parameter \"%s\" not known." p))))
#+end_src 

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.2.6-552-g8c5a78

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-16  6:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 16:37 Inject value of macro into code using a variable wlharvey4 via Emacs-orgmode
2019-10-15 19:42 ` Nicolas Goaziou
2019-10-16  6:23 ` Fraga, Eric

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).