Org-mode fails to export when passing arguments to code blocks that exports results - emacs

When passing arguments to code block that exports results Org-mode fails to export with the error "Wrong type argument: listp". How can I fix this?
Here is an example. When it is exported it gives the error 'Wrong type argument: listp, "bar"'.
#+TITLE: Example
#+SOURCE: example-one
#+BEGIN_SRC emacs-lisp :exports results
(setq foo "bar")
#+END_SRC
#+SOURCE: example-two
#+BEGIN_SRC emacs-lisp :exports results :var x=example-one
(setq foo (concat x x))
#+END_SRC
I am running Org-mode 7.6 in Emacs 23.3.1.

This issue might simply be with the older copy of Org that you're running. Tested it today with a recent git pull and get the results below. As pmr suggested, you might have better luck asking on the mailing list ( emacs-orgmode#gnu.org ) since there might be someone there who would know what caused this issue and what might have been changed to resolve it in later versions.
The features and examples discussed in the manual are based on the current release version (7.8.03 in this case) so they will not always be compatible with older versions. Does the info-node in your version indicate that it should work?
These 2 commands will show you the associated info-nodes for that section of the Org Manual
; The node itself
(Info-goto-node "(org) var")
; Parent node, in case the first node isn't present
(Info-goto-node "(org) Working With Source Code")
Test Results
Org
* Test variable passing
Headlines are created to split the code blocks apart. When trying to eval on export I'm getting a syntax read error which was reported here: http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html
** Ex 1
#+name: example-one
#+BEGIN_SRC emacs-lisp :exports results
(setq foo "bar")
#+END_SRC
** Ex 2
#+name: example-two
#+BEGIN_SRC emacs-lisp :exports results :var x=example-one
(setq foo (concat x x))
#+END_SRC
Latex
\vspace*{1cm}
Headlines are created to split the code blocks apart. When trying to eval on export I'm getting a syntax read error which was reported here: \href{http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html}{http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html}
\section{Ex 1}
\label{sec-1}
\begin{verbatim}
bar
\end{verbatim}
\section{Ex 2}
\label{sec-2}
\begin{verbatim}
barbar
\end{verbatim}

in your .emacs file - make sure you have the following line:
(setq org-babel-load-languages
(quote ((emacs-lisp . t))))

Related

What can cause org-auto-tangle to result nil for all noweb code block evaluations

I'm using literate programming for some configuration files and would like to have some parts from elisp code block evaluations. I tried evaluating named code blocks with :noweb tangle but they always results nil and I do not see any errors in the *Messages*. Here's a simplified hello world example and the results I got.
Org file
#+title: Hello
#+PROPERTY: header-args :tangle hello.txt :cache no :exports none
#+auto_tangle: t
#+name: hello-world-output
#+begin_src emacs-lisp :tangle no :eval no-export :results output
(print "Hello world")
#+end_src
#+name: hello-world-value
#+begin_src emacs-lisp :tangle no :eval no-export :results value
"Hello world"
#+end_src
#+begin_src text :noweb tangle
<<hello-world-output>> -> <<hello-world-output()>>
<<hello-world-value>> -> <<hello-world-value()>>
#+end_src
Tangled results
(print "Hello world") -> nil
"Hello world" -> nil
I also checked that org-link-elisp-confirm-function and org-confirm-babel-evaluate both have nil value, so they should not be preventing evaluation.
EDIT: I forgot to mention that I used org-auto-tangle. Issue doesn't occur when calling org-bable-tangle directly.
I had the same issue and below solved it for me.
According to the code of org-auto-tangle the code will not be evaluated by default. In order to have the code auto evaluated you need to add your org file to the org-auto-tangle-babel-safelist. I've posted the definition of the variable and a link to the README with an example of how to set the variable.
(defvar org-auto-tangle-babel-safelist '()
"List of full path of files for which code blocks need to be evaluated.
By default, code blocks are not evaluated during the auto-tangle to avoid
possible code execution from unstrusted source. To enable code blocks evaluation
for a specific file, add its full path to this list.")
https://github.com/yilkalargaw/org-auto-tangle#babel-auto-tangle-safelist

Org babel print elisp variable

Using org, I'd like to execute Lisp code which prints the value of a variable into a results block. E.g. I'm trying to print the value of org-babel-default-header-args.
I've tried this:
#+BEGIN_SRC elisp :exports both
(print 'org-babel-default-header-args)
#+END_SRC
#+BEGIN_SRC elisp :exports both
(org-babel-default-header-args)
#+END_SRC
#+BEGIN_SRC elisp :exports both
(symbol-value 'org-babel-default-header-args)
#+END_SRC
The closest thing I've gotten to work is this:
#+BEGIN_SRC elisp :exports both
(describe-variable 'org-babel-default-header-args)
#+END_SRC
But that prints out some extra text. I'd like to literally just print the value of the variable.
To print the value of a variable foo, use
(print foo)
without quoting it. Quote inhibits evaluation: that's exactly what you don't want to do here.

Org-mode Babels :file with link abbreviations

I have some link-abbreviations in org-mode like this:
(setq org-link-abbrev-alist
'(("dropboxpath" . "~/Dropbox")
("cloudpath" . "~/")
("imgpath" . "~/images")
("gitpath" . "~/git")
))
It works fine and as i am working on different systems and syncing my org-files the paths are different on every system. My problem is the following:
#+BEGIN_SRC plantuml :file gitpath:/test.png
<some plantumlstuff here>
#+END_SRC
This is not working, org-babel does not recognize the link abbreviation.
I also tried the following (where temp is a variable containing the path to the git-directory):
#+BEGIN_SRC plantuml :file (concat temp "/test.png")
This works in principle but gives me the following result:
#+RESULTS:
[[file:~/git/test.png]]
This does not meet my requirements though because i need gitpath in order to make it work over all my machines...
#+RESULTS:
[[gitpath:/test.png]]
Does anybody have a suitable solution to this problem?
You can simply refer to org-link-abbrev-alist. Since that variable is structured as an alist, you can use assoc. It returns the first element of the alist that matches the supplied key.
(concat
(car (assoc "gitpath" org-link-abbrev-alist))
"/test.png")

Org-mode: overwriting globals #+PROPERTIES: in block headers?

It is often the case that I want to have :results silent for all the code blocks in an Org-mode document. Do simplify my block headers, I define this in my Org-mode document:
#+PROPERTY: header-args :results silent
That works properly: all the codeblocks uses the :results silent option in the blocks' header.
However, if I specify :results output in one of the code block, it will still be silent. I would have expected that it would overwrite the global setting, but it doesn't seem so.
Am I right by saying that or is there something I am missing to get this behavior?
Here is an example of what I would like to do:
#+PROPERTY: header-args :results silent
...
#+BEGIN_SRC clojure
;; this one is silent
(def foo "bar)
#+END_SRC
...
#+BEGIN_SRC clojure :results output
;; this one is being outputted
(def foo "bar)
#+END_SRC
This seems to be a bug, present even in the most up-to-date version of org-mode. I've reported it on the org-mode mailing list.
EDIT: Charles Berry pointed out on the ML that this is not a bug. The opposite of "silent" is "replace", so the second source block should read:
#+BEGIN_SRC elisp :results output replace
;; this one is being outputted
(princ "foo")
#+END_SRC
See http://thread.gmane.org/gmane.emacs.orgmode/108001/focus=108008
and the :results section in the manual http://orgmode.org/org.html#results
Note that you get to pick one value for every section (collection, type, format, handling) - if you don't pick a value for a section, a default value is picked. In the above, there was no explicit value for "handling", so the default value from the property still controlled.

org-babel sbe syntax

Can anyone give examples of using the sbe function in ob-table.el? I must be missing something because I haven't been able to get it to work with straight-up elisp.
#+name: add1(x=1) :results silent
#+begin_src python
return x + 1
#+end_src
This works:
| 1 | 2 | 3 | 4 |
#+TBLFM: #1$4='(sbe add1 (x $3))
But this does not:
#+begin_src emacs-lisp
(sbe add1 (x 2))
#+end_src
error: Wrong type argument: sequencep, 2
Changing 2 to a list just aggravates it further:
#+begin_src emacs-lisp
(sbe add1 (x (list 2))
#+end_src
error: Wrong type argument: buffer-or-string-p, 2
If I'm understanding your question correctly you're trying to use your named source block outside of tables to call for results.
First of all, your :results silent belongs on the #+begin_src line and not the #+name (only relevant if you ever evaluate that block directly). I'm switching to emacs-lisp from python simply because I don't have python on this machine so can't evaluate the block otherwise, the function remains equivalent.
#+name: add1(x=1)
#+begin_src emacs-lisp :results silent
(+ x 1)
#+end_src
In Org Tables the proper command is the one you used: #+tblfm: #1$4='(sbe add1 (x $3))
When using code blocks outside of tables you have to use #+CALL: instead (see Evaluating Code Blocks).
For example:
#+CALL: add1(x=2)
#+RESULTS: add1(x=2)
: 3
#+CALL: add1(4)
#+RESULTS: add1(4)
: 5
#+call: add1(add1(2))
#+RESULTS: add1(add1(2)
: 4
Edit (Adding in answer from comment):
If you simply want to clean up your formulas and be better able to read through them to make changes, the formula editor C-c ' will let you see them more clearly as well as highlight cell references to ensure you're selecting the right regions.