Function: org-fixup-indentation
org-fixup-indentation is a byte-compiled function defined in
org.el.gz.
Signature
(org-fixup-indentation DIFF)
Documentation
Change the indentation in the current entry by DIFF.
DIFF is an integer. Indentation is done according to the following rules:
- Planning information and property drawers are always indented
according to the new level of the headline;
- Footnote definitions and their contents are ignored;
- Inlinetasks' boundaries are not shifted;
- Empty lines are ignored;
- Other lines' indentation are shifted by DIFF columns, unless
it would introduce a structural change in the document, in
which case no shifting is done at all.
Assume point is at a heading or an inlinetask beginning.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-fixup-indentation (diff)
"Change the indentation in the current entry by DIFF.
DIFF is an integer. Indentation is done according to the
following rules:
- Planning information and property drawers are always indented
according to the new level of the headline;
- Footnote definitions and their contents are ignored;
- Inlinetasks' boundaries are not shifted;
- Empty lines are ignored;
- Other lines' indentation are shifted by DIFF columns, unless
it would introduce a structural change in the document, in
which case no shifting is done at all.
Assume point is at a heading or an inlinetask beginning."
(org-with-wide-buffer
(narrow-to-region (line-beginning-position)
(save-excursion
(if (org-with-limited-levels (org-at-heading-p))
(org-with-limited-levels (outline-next-heading))
(org-inlinetask-goto-end))
(point)))
(forward-line)
;; Indent properly planning info and property drawer.
(when (looking-at-p org-planning-line-re)
(org-indent-line)
(forward-line))
(when (looking-at org-property-drawer-re)
(goto-char (match-end 0))
(forward-line)
(org-indent-region (match-beginning 0) (match-end 0)))
(when (looking-at org-logbook-drawer-re)
(let ((end-marker (move-marker (make-marker) (match-end 0)))
(col (+ (current-indentation) diff)))
(when (wholenump col)
(while (< (point) end-marker)
(if (natnump diff)
(insert (make-string diff 32))
(delete-char (abs diff)))
(forward-line)))))
(catch 'no-shift
(when (or (zerop diff) (not (eq org-adapt-indentation t)))
(throw 'no-shift nil))
;; If DIFF is negative, first check if a shift is possible at all
;; (e.g., it doesn't break structure). This can only happen if
;; some contents are not properly indented.
(let ((case-fold-search t))
(when (< diff 0)
(let ((diff (- diff))
(forbidden-re (concat org-outline-regexp
"\\|"
(substring org-footnote-definition-re 1))))
(save-excursion
(while (not (eobp))
(cond
((looking-at-p "[ \t]*$") (forward-line))
((and (looking-at-p org-footnote-definition-re)
(let ((e (org-element-at-point)))
(and (org-element-type-p e 'footnote-definition)
(goto-char (org-element-end e))))))
((looking-at-p org-outline-regexp) (forward-line))
;; Give up if shifting would move before column 0 or
;; if it would introduce a headline or a footnote
;; definition.
(t
(skip-chars-forward " \t")
(let ((ind (current-column)))
(when (or (< ind diff)
(and (= ind diff) (looking-at-p forbidden-re)))
(throw 'no-shift nil)))
;; Ignore contents of example blocks and source
;; blocks if their indentation is meant to be
;; preserved. Jump to block's closing line.
(forward-line 0)
(or (and (looking-at-p "[ \t]*#\\+BEGIN_\\(EXAMPLE\\|SRC\\)")
(let ((e (org-element-at-point)))
(and (org-src-preserve-indentation-p e)
(goto-char (org-element-end e))
(progn (skip-chars-backward " \r\t\n")
(forward-line 0)
t))))
(forward-line))))))))
;; Shift lines but footnote definitions, inlinetasks boundaries
;; by DIFF. Also skip contents of source or example blocks
;; when indentation is meant to be preserved.
(while (not (eobp))
(cond
((and (looking-at-p org-footnote-definition-re)
(let ((e (org-element-at-point)))
(and (org-element-type-p e 'footnote-definition)
(goto-char (org-element-end e))))))
((looking-at-p org-outline-regexp) (forward-line))
((looking-at-p "[ \t]*$") (forward-line))
(t
(indent-line-to (+ (current-indentation) diff))
(forward-line 0)
(or (and (looking-at-p "[ \t]*#\\+BEGIN_\\(EXAMPLE\\|SRC\\)")
(let ((e (org-element-at-point)))
(and (org-src-preserve-indentation-p e)
(goto-char (org-element-end e))
(progn (skip-chars-backward " \r\t\n")
(forward-line 0)
t))))
(forward-line)))))))))