orgmode emacs cannot export to html - emacs

When I evaluate a code block (see example below), it works. However; when I tried to export to html I got the next error:
Wrong type argument: stringp, nil
If I take the C from -- #+begin_src C -- , it will export without any problem. How I can solve the problem?
Thanks
#+begin_src C :includes <stdio.h> :exports both
int main(void){
printf("hello world");
return 0;
}
#+end_src
#+results:
: hello world

Change in .emacs
(let ((file (file-name-nondirectory buffer-file-name)))
for
(let ((file (or buffer-file-name "DEFAULT-NAME")))
Here is the link for more inf, but the idea is to replace all the instances of buffer-file-name.
org-mode can't edit C source code

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.

Any way to make org-babel properly indent noweb tangled code?

Tangling this:
#+BEGIN_SRC C :tangle no :noweb-ref begin
int main() {
printf("Line 1\n");
#+END_SRC
#+BEGIN_SRC C :tangle no :noweb-ref middle
printf("Second\n");
#+END_SRC
#+BEGIN_SRC C :tangle no :noweb-ref end
}
#+END_SRC
#+BEGIN_SRC C :tangle ~/test.c :noweb no-export
<<begin>>
<<middle>>
<<end>>
#+END_SRC
Yields this:
int main() {
printf("Line 1\n");
printf("Second\n");
}
I have org-src-preserve-indentation turned on, but it can't preserve what isn't there. The code editing windows can't set it correctly if it doesn't see the parts from the previous source code blocks. Finally, I don't want to have to go through all the previous snippets to figure out what the indentation should start at every time I start a new source code block.
Current hack is to tangle the source code, open the tangled file in a new buffer, select all and run c-indent-line-or-region, but I'm hoping there's something better than that.
Org-mode version: 8.2.5h
As mentioned, hooking into the org-babel-post-tangle-hook is the way to go. I use the following:
(defun tnez/src-cleanup ()
(indent-region (point-min) (point-max)))
(add-hook 'org-babel-post-tangle-hook 'tnez/src-cleanup)

org-mode doesn't like c++-mode

I'm using org-mode (Emacs: 24.3.1, org-mode: 7.9.3f 8.0.6) for a database of code snippets in different languages (so far mainly elisp and python). This works very nice using org-mode-babel, i.e. after creating a "code field" as explained in the documentation I can edit the code using the correct major-mode by issueing C-c ' (i.e. org-edit-special). However, when editing C++ source snippets such as
#+begin_src c++
std::vector<int> v( 100 );
std::iota( std::begin( v ), std::end( v ), 0 ); // Fill with 0, 1, ..., 99.
#+end_src
The error message
byte-code: Language mode `c++-mode' fails with: "Buffer *Org Src snippets.org[ c++ ]* has no process"
is prined (snippets.org is the name of the file I use to store the snippets). Furthermore, I can not save any changes made in the temporary buffer (which actually opens) and can not exit the temporary buffer using C-c '.
Anyone encountered this problem previously?
UPDATE: I found the culprit! The auto completion source ac-source-clang-async is responsible for screwing it up. My ac-clang config:
(defun ac-cc-mode-clang-setup ()
(message " * calling ac-cc-mode-clang-setup")
(setq ac-clang-complete-executable "~/.emacs.d/site-lisp/emacs-clang-complete-async/clang-complete")
(setq ac-clang-cflags
(mapcar (lambda (item)(concat "-I" item))
(split-string
"
/usr/include/c++/4.7
/usr/include/c++/4.7/x86_64-linux-gnu
/usr/include/c++/4.7/backward
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
/usr/local/root_v5.32.04/include
"
)))
(setq ac-clang-flags ac-clang-cflags)
;; (setq ac-sources (append '(ac-source-clang-async ac-source-yasnippet) ac-sources))
(setq ac-sources '(ac-source-filename ac-source-clang-async ac-source-yasnippet))
(ac-clang-launch-completion-process)
(ac-clang-update-cmdlineargs))
(defun ac-cc-mode-clang-config ()
(message " * calling ac-cc-mode-clang-config")
(add-hook 'c-mode-common-hook 'ac-cc-mode-clang-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup))
(ac-cc-mode-clang-config)
Upon commenting this out, everything works nicely. I assume that the problem occurs because ac-clang wants to execute clang on the source file, which does not exists because its a purely virtual buffer (meaning: there is no associated file). However, I don't want to lose support for using ac-clang when writing programs... I think this might be solved if ac-cc-mode-clang-config is only executed when I'm doing genuine C++ edits (not org-mode c++ edits). Any ideas how to solve this?
This works for me:
#+begin_src C++ :includes '(<vector> <numeric> <iostream>) :flags -std=c++11
std::vector<int> v( 100 );
std::iota( std::begin( v ), std::end( v ), 0 );
std::cout << v[7];
#+end_src
#+RESULTS:
: 7
Emacs 24.3.4. Org 8.0.6.
org-setup
(org-babel-do-load-languages
'org-babel-load-languages
'( (perl . t)
(ruby . t)
(sh . t)
(python . t)
(emacs-lisp . t)
(matlab . t)
(C . t)))
Try with "C++" (capital C) or "cpp". Also try using a very recent version (one week or so). I think Eric Schulte has patched something for this.
Solved it! This has actually already been a bug in ac-clang-async, where it was fixed some time ago. However, the problem persists if you have a function configuring ac-clang-async which is executed whenever c-mode-common-hook (or a similar hook) is executed. The configuration process then breaks org.
If you want the configuring process to be executed whenever a file is opened (i.e. if the include paths depend on some file/buffer-local variable), you should wrap your configuration in the following snippet:
(defun my-ac-clang-config()
(let ((filename (buffer-file-name)))
(if filename
; Your config stuff
)
)
)

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

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))))