0

The process of tangling in org involves, according to https://orgmode.org/manual/Extracting-Source-Code.html, a calling buffer and a called buffer, each of which have their own hooks: org-babel-pre-tangle-hook and org-babel-tangle-body-hook. How could I pass a variable set within the calling buffer to the called buffer? I.e., if myvar has value 4 in the calling buffer, how could I make a variable in the called buffer that has the same name and value?

I realize this question does not show work; this is because I don't exactly have an idea of where to start looking to answer this question. So, an answer of how to do the above would be appreciated and would immediately fix my issue, but given the lack of shown work, if you instead have suggestions on things I could read to learn to do the above, that would also be highly appreciated!

4
  • The page you link to does not contain any mention of a "calling buffer" or a "called buffer", so I'm not sure what you mean. By the "calling buffer", do you mean the Org mode buffer where you execute the tangle command C-c C-v C-t? And by "called buffer", do you mean the buffers (note that there can be more than one) where the extracted source code ends up? I think the best thing to do is to provide an example: an Org mode file with some source code, the result file after you tangle and what exactly you want to accomplish. "Passing a variable" does not make any sense to me.
    – NickD
    Dec 17, 2023 at 21:21
  • 1
    I'm not familiar with tangling but, given the nature of variables in elisp generally, does using (defconst VARNAME VALUE) solve your problem? (That both defines a dynamic variable and unconditionally sets the value.)
    – phils
    Dec 17, 2023 at 21:24
  • The problem is that tangling can produce files containing source code in any language (C, C++, python...) and it's not clear to me what variables the OP is talking about. If I have an elisp variable available in an Org mode buffer, what (if anything) does it have to do with the tangled C (or whatever) program in the output file?
    – NickD
    Dec 18, 2023 at 2:44
  • Thank you for your comments! defconst did help out with my problem: I used this statement in combination with org-babel-pre-tangle-hook so that my constant took its value from the org buffer instead of the tangled file buffer
    – shintuku
    Dec 20, 2023 at 22:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.