3
votes

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?

3

3 Answers

3
votes

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

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.

0
votes

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