Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indent code in org-babel src blocks

In an org-mode file, with code like the following:

#+begin_src emacs-lisp
(add-to-list 'org-tab-before-tab-emulation-hook
             (lambda ()
               (when (within-the-body-of-a-begin-src-block)
                 (indent-for-tab-command--as-if-in-lisp-mode))))
#+end_src

I would like the TAB key to indent the code as it would if it were in a buffer in lisp mode.

What I need is:

  • A way to figure out whether the cursor is within a src block. It needs to not trigger when on the header line itself, as in that case the default org folding should take place.
  • A way to indent the code according to the mode (emacs-lisp in this case) specified in the header.

Org can already syntax highlight src blocks according to mode, and the TAB hooks are there. This looks do-able.

like image 231
user103576 Avatar asked Apr 02 '13 20:04

user103576


1 Answers

Since Emacs 24.1 you can now set the following option:

(setq org-src-tab-acts-natively t)

...and that should handle all src blocks.

like image 183
TabFace Avatar answered Sep 26 '22 15:09

TabFace