1

Does someone know if it is possible to set the #+NAME label for source blocks as a variable?

E.g.; I would like to be able to set the label with elisp, something like:

#+NAME: (concat "name_" "block_1")
#+begin_src emacs-lisp 
 (print 1)
#+end_src

#+RESULTS: (concat "name_" "block1")
: 1

Apparently the elisp code is not recognized and taken as a string. The desired behaviour would be:

#+NAME: (concat "name_" "block_1")
#+begin_src emacs-lisp 
 (print 1)
#+end_src

#+RESULTS: name_block1
: 1
6
  • The elisp tag does not mean what you think it means (and there is a pending edit to remove it): emacs.stackexchange.com/tags/elisp/info
    – NickD
    Jun 29 at 12:58
  • 1
    I'm pretty sure you cannot do what you describe above, but I don't understand the context: what exactly are you trying to do that led you to the above question?
    – NickD
    Jun 29 at 17:28
  • Thank you @NickD for your comment. Context: I have a lot of repetitive code for extracting analyses results that relies on inputs from other code blocks. I pass the inputs inside the code body with the :var header, and I would like to have a similarly flexible mechanism to set the name labels (I need unique labels for plotting and subsequent code blocks that could rely on these names). If it is not possible to the name label as variable I can also reorganize my code and pull most of the code blocks together, save results in separate objects and then report the results in org-mode.
    – 01000001
    Jun 30 at 7:50
  • I would suggest that you edit your question and add the comment (perhaps expanding it to provide a small example) to the question itself. Also, it seems that you might have a solution/workaround already (although I think the description could benefit from an example there as well). Is it the case that the solution is inadequate? In particular, I don't understand how specifying names with lisp code accomplishes your goal: don't you still have to specify the prefix and the (unique) suffix somehow? Why not do it directly? In short, I think your question is unclear (still).
    – NickD
    Jun 30 at 12:11
  • 1
    The answer to that is "no": names are strings and they are specified in the buffer directly. There is no provision for evaluating them in any form.
    – NickD
    Jun 30 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.