This is an org-mode
-bug.
The problem is that the case of "Lists" is handled before "Special blocks" in org-indent-line
.
If you exchange these cases the tab-indentation behaves better.
The corrected code for org-indent-line
in org-mode
8.2.10 is:
(require 'org)
(if (equal (mapcar 'string-to-number (split-string org-version "\\.")) '(8 2 10))
(defun org-indent-line ()
"Indent line depending on context."
(interactive)
(let* ((pos (point))
(itemp (org-at-item-p))
(case-fold-search t)
(org-drawer-regexp (or org-drawer-regexp "\000"))
(inline-task-p (and (featurep 'org-inlinetask)
(org-inlinetask-in-task-p)))
(inline-re (and inline-task-p
(org-inlinetask-outline-regexp)))
column)
(if (and orgstruct-is-++ (eq pos (point)))
(let ((indent-line-function (cadadr (assoc 'indent-line-function org-fb-vars))))
(indent-according-to-mode))
(beginning-of-line 1)
(cond
;; Headings
((looking-at org-outline-regexp) (setq column 0))
;; Footnote definition
((looking-at org-footnote-definition-re) (setq column 0))
;; Literal examples
((looking-at "[ \t]*:\\( \\|$\\)")
(setq column (org-get-indentation))) ; do nothing
;; Drawers
((and (looking-at "[ \t]*:END:")
(save-excursion (re-search-backward org-drawer-regexp nil t)))
(save-excursion
(goto-char (1- (match-beginning 1)))
(setq column (current-column))))
;; Special blocks
((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
(save-excursion
(re-search-backward
(concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
(setq column (org-get-indentation (match-string 0))))
((and (not (looking-at "[ \t]*#\\+begin_"))
(org-between-regexps-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
(save-excursion
(re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
(setq column
(cond ((equal (downcase (match-string 1)) "src")
;; src blocks: let `org-edit-src-exit' handle them
(org-get-indentation))
((equal (downcase (match-string 1)) "example")
(max (org-get-indentation)
(org-get-indentation (match-string 0))))
(t
(org-get-indentation (match-string 0))))))
;; Lists
((ignore-errors (goto-char (org-in-item-p)))
(setq column (if itemp
(org-get-indentation)
(org-list-item-body-column (point))))
(goto-char pos))
;; This line has nothing special, look at the previous relevant
;; line to compute indentation
(t
(beginning-of-line 0)
(while (and (not (bobp))
(not (looking-at org-table-line-regexp))
(not (looking-at org-drawer-regexp))
;; When point started in an inline task, do not move
;; above task starting line.
(not (and inline-task-p (looking-at inline-re)))
;; Skip drawers, blocks, empty lines, verbatim,
;; comments, tables, footnotes definitions, lists,
;; inline tasks.
(or (and (looking-at "[ \t]*:END:")
(re-search-backward org-drawer-regexp nil t))
(and (looking-at "[ \t]*#\\+end_")
(re-search-backward "[ \t]*#\\+begin_"nil t))
(looking-at "[ \t]*[\n:#|]")
(looking-at org-footnote-definition-re)
(and (not inline-task-p)
(featurep 'org-inlinetask)
(org-inlinetask-in-task-p)
(or (org-inlinetask-goto-beginning) t))))
(beginning-of-line 0))
(cond
;; There was a list item above.
((ignore-errors (goto-char (org-in-item-p)))
(goto-char (org-list-get-top-point (org-list-struct)))
(setq column (org-get-indentation)))
;; There was an heading above.
((looking-at "\\*+[ \t]+")
(if (not org-adapt-indentation)
(setq column 0)
(goto-char (match-end 0))
(setq column (current-column))))
;; A drawer had started and is unfinished
((looking-at org-drawer-regexp)
(goto-char (1- (match-beginning 1)))
(setq column (current-column)))
;; Else, nothing noticeable found: get indentation and go on.
(t (setq column (org-get-indentation))))))
;; Now apply indentation and move cursor accordingly
(goto-char pos)
(if (<= (current-column) (current-indentation))
(org-indent-line-to column)
(save-excursion (org-indent-line-to column)))
;; Special polishing for properties, see `org-property-format'
(setq column (current-column))
(beginning-of-line 1)
(if (looking-at org-property-re)
(replace-match (concat (match-string 4)
(format org-property-format
(match-string 1) (match-string 3)))
t t))
(org-move-to-column column))))
(error "Bugfix of `org-indent-line' is for org-version 8.2.10 only."))
Note, this source code is not tested thoroughly because of lack of time.
If this is not corrected in higher org-mode versions one should issue a bug-report.
Remark on your Update-2015-12-9: With this fix you still need to add a space in front of [[file:xx]]
to get it indented correctly.
#+begin_src sh ls -la #+end_src
. So it interrupt the number list. I success only whey I manually type this code. So it obviously different in the format. Then when I encounter the problem that the number list was interrupted. How can I recover that number list?