Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable auto-complete in Emacs Org-babel?

I would like to enable auto-complete for Babel code blocks in org-mode:

#+begin_src emacs-lisp
(setq )                 <--- language-aware auto-completion here
#+end_src

What do I need to add to my .emacs file in order to configure auto-complete to do this?

like image 474
stardiviner Avatar asked Feb 05 '13 09:02

stardiviner


2 Answers

Late to the party but today the default (and recommended way without other hacks) is to switch to the dedicated elisp buffer for that "hunk" using 'org-edit-special which today is mapped to

C-c- '

Hit the same to return to your org file editing.

like image 170
RichieHH Avatar answered Sep 17 '22 13:09

RichieHH


The most robust (and entirely not org-mode specific) way to do this involves an indirect buffer. Here's a blog post that explains indirect buffers in depth. Basically an indirect buffer mirrors the contents of a section of another buffer.

(defun narrow-to-region-indirect (start end)
  "Restrict editing in this buffer to the current region, indirectly."
  (interactive "r")
  (deactivate-mark)
  (let ((buf (clone-indirect-buffer nil nil)))
    (with-current-buffer buf
      (narrow-to-region start end))
      (switch-to-buffer buf)))

At this point, you will have a new buffer that contains the region you previously made. You can enable a major mode for that buffer and edit to your satisfaction--the changes you make are (like any good mirror should do) reflected in the original document.

like image 33
PythonNut Avatar answered Sep 18 '22 13:09

PythonNut