6

By default org mode source blocks looks like:

#+BEGIN_SRC emacs-lisp
  (dcg/add-to-list 'package-archives
                   '("melpa-stable" . "http://stable.melpa.org/packages/")
                   '("melpa" . "http://melpa.org/packages/")
                   '("marmalade" . "http://marmalade-repo.org/packages/"))
  (package-initialize)
  (setq package-enable-at-startup nil)
#+END_SRC

Is it possible to configure it to indent without the two beginning spaces like:

#+BEGIN_SRC emacs-lisp
(dcg/add-to-list 'package-archives
                 '("melpa-stable" . "http://stable.melpa.org/packages/")
                 '("melpa" . "http://melpa.org/packages/")
                 '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(setq package-enable-at-startup nil)
#+END_SRC

1 Answer 1

10

Try to customize org-edit-src-content-indentation. I think by default it is set to 2. I think this is what controls that behavior.

However, if you put (setq org-src-preserve-indentation t) in your init file, you will get your desired behaviour, plus indentation will be preserved on export. From the docs for org-src-preserve-indentation (notice the reference to org-edit-src-content-indentation):

If non-nil preserve leading whitespace characters on export. If non-nil leading whitespace characters in source code blocks are preserved on export, and when switching between the org buffer and the language mode edit buffer. If this variable is nil then, after editing with M-x org-edit-src-code, the minimum (across-lines) number of leading whitespace characters are removed from all lines, and the code block is uniformly indented according to the value of `org-edit-src-content-indentation'

Here is a bit of configuration code that I use to get nice indentation and syntax highlighting in the org buffer, among other things. Feel free to experiment with these settings!

(setq org-src-fontify-natively t
    org-src-window-setup 'current-window
    org-src-strip-leading-and-trailing-blank-lines t
    org-src-preserve-indentation t
    org-src-tab-acts-natively t)
1
  • 1
    I didn't know org-src-window-setup 'current-window existed. If we ever meet I owe you your choice of beverage.
    – itorres
    Oct 26, 2018 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.