Try this
I use the following methods to fix the indentation of src blocks under plain lists. After indentation is setup correctly, always use M-S-left and M-S-right to maintain the list indentation.
Fix Formatting for New Code Blocks
First indent cursor and then use built-in template <s
when creating a new src block under a plain list.
e.g. tab <s tab language
return
- [ ] My plain list item
Nicely indented paragraph, blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah.
<s
Fix Formatting for Existing Code Blocks
Step 1 - Figure out desired indent column number. For the example below use 2
.
- [ ] My plain list item
Nicely indented paragraph, blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah.
#+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
#+END_SRC
Step 2 - Place cursor at beginning of #+END_SRC
line then do M-xindent-to-column 2
return. After which you should see the following:
- [ ] My plain list item
Nicely indented paragraph, blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah.
#+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
#+END_SRC
Step 3 - Open and close src block by placing cursor inside block and using C-' C-'.
- [ ] My plain list item
Nicely indented paragraph, blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah.
#+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
#+END_SRC
Thanks for asking your question.
Hope that helped!
This answer was tested using:
GNU Emacs 25.3.1
org-mode: 9.1.13
org-indent-mode
. – wasamasa Aug 5 '16 at 17:54(org-list-in-valid-context-p)
in the src block will tell you that, by default, org doesn't want a src block to be the context where lists are allowed. Alteringorg-list-forbidden-blocks
may change that, it's not adefcustom
though. – mutbuerger Aug 6 '16 at 12:14