0

I have this elisp code:

#+BEGIN_SRC emacs-lisp :dir ~/org/test

(defun test ()
  (setq args '(org-babel-get-src-block-info))
  (cdr (assoc ':dir args)))
(test)

#+END_SRC

But when I execute the code block, I get a message saying that no output was produced... what am I doing wrong?

2
  • 1
    Please do not use tag elisp for questions about how to use Elisp. It's for questions about the nature of the language, compared to other languages, in particular other Lisp dialects. Thx.
    – Drew
    Apr 24, 2020 at 15:24
  • @Stefan I just edited the question, thanks!
    – Adam
    Apr 24, 2020 at 15:49

2 Answers 2

1

You should:

  1. Unquote '(org-babel-get-src-block-info) and
  2. Replace (cdr (assoc ':dir args)) with (assoc-default :dir (nth 2 args))

That is:

#+BEGIN_SRC emacs-lisp :dir ~/org/test
(defun test ()
  (setq args (org-babel-get-src-block-info))
  (assoc-default :dir (nth 2 args)))
(test)
#+END_SRC

Or:

#+BEGIN_SRC emacs-lisp :dir ~/org/test
(let* ((info (org-babel-get-src-block-info))
       (params (nth 2 info)))
  (assoc-default :dir params))
#+END_SRC
1
  • Works great -- thanks Jagrg! If you want to write this up as a single function, I'll accept it as the answer.
    – Adam
    Apr 26, 2020 at 18:39
0

For a start, you are quoting the call to org-babel-get-src-block-info, so the function is never called. Second, you probably want to change the test function to something like this:

(defun test()
   (let ((args (org-babel-get-src-block-info)))
      args))

until you understand what the call to org-babel-get-src-block-info returns. In fact, it would be a good idea to try doing M-: (org-babel-get-src-block-info) RET, so you can see clearly what the function returns. Third, babel has strange ideas about what to do with the output. In this particular case, you might want to set :results raw (despite the disadvantage that you have to delete the results by hand every time), so as to avoid the strange interpretation.

Your Answer

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

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