Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have basic autoindentation in code blocks in org-mode

Emacs' fine org-mode has CODE and EXAMPLE blocks that are easily edited in a proper major mode using C-c '. But for quick alterations and minor edits one might prefer editing the block inline without opening new popup windows for a two-second operations.

Of course org lets you do that but the automatic indentations are off radar while editing inline like that. Where and what should I hack to make org's indentation logic to act like default dumb autoindentation (ie. copy the indent level of the previous line) while the cursor is in a code block?

  #+BEGIN_SRC python
    def foo():
        return 42
  #+END_SRC

  #+BEGIN_EXAMPLE
    Oh my
         hh
  #+END_EXAMPLE

If the cursor was at the end of the line containing hh, pressing C-j would get me a new line with the same indentation as the previous one.

like image 438
mike3996 Avatar asked Jun 08 '26 13:06

mike3996


1 Answers

The following allows me to edit (and indent) code "inline" without ever going to the indirect buffers (except for M-q on comments, which did work and does not anymore).

;; same effect for `tab' as in the language major mode buffer
(setq org-src-tab-acts-natively t)
like image 128
fniessen Avatar answered Jun 11 '26 21:06

fniessen