1

I have a src block to get a value from some table:

#+NAME: ref
#+BEGIN_SRC emacs-lisp :var  name="" table=main
(let ((key (if (symbolp name) (symbol-name name) name)))
  (nth 2 (assoc key table)))
#+END_SRC

In Org I can execute this by:

#+CALL: ref("value")

How can I do the same only in Lisp?

I tried this:

(defun a/ref (params)
  (save-excursion
    (goto-char (point-min))
    (org-babel-goto-named-src-block "ref")
    (org-babel-execute-src-block nil nil params) 
    (org-babel-read-result)))

(a/ref '(("value")))

But it didn't work

2
2

I think what you are looking for is related to the library of babel. In this example, I construct something similar to the babel-call org element and use it to get the info needed for org-babel-execute-src-block to execute it with the argument.

#+name: main
| x     | 1 | a |
| value | 2 | b |

#+NAME: ref
#+BEGIN_SRC emacs-lisp :var  name="" table=main
(let ((key (if (symbolp name) (symbol-name name) name)))
  (nth 2 (assoc key table)))
#+END_SRC

#+call: ref("value")

#+RESULTS:
: b

The equivalent in elisp is:

#+BEGIN_SRC emacs-lisp
(org-babel-execute-src-block nil (org-babel-lob-get-info '(babel-call (:call "ref" :arguments "\"value\""))))
#+END_SRC

#+RESULTS:
: b

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.