Function: org-indent-line

org-indent-line is an interactive and byte-compiled function defined in org.el.gz.

Signature

(org-indent-line)

Documentation

Indent line depending on context.

Indentation is done according to the following rules:

  - Footnote definitions, diary sexps, headlines and inline tasks
    have to start at column 0.

  - On the very first line of an element, consider, in order, the
    next rules until one matches:

    1. If there's a sibling element before, ignoring footnote
       definitions and inline tasks, indent like its first line.

    2. If element has a parent, indent like its contents. More
       precisely, if parent is an item, indent after the bullet.
       Else, indent like parent's first line.

    3. Otherwise, indent relatively to current level, if
       org-adapt-indentation is t, or to left margin.

  - On a blank line at the end of an element, indent according to
    the type of the element. More precisely

    1. If element is a plain list, an item, or a footnote
       definition, indent like the very last element within.

    2. If element is a paragraph, indent like its last non blank
       line.

    3. Otherwise, indent like its very first line.

  - In the code part of a source block, use language major mode
    to indent current line if org-src-tab-acts-natively is
    non-nil. If it is nil, do nothing.

  - Otherwise, indent like the first non-blank line above.

The function doesn't indent an item as it could break the whole list structure. Instead, use C-c C-x L (org-shiftmetaleft) or C-c C-x R (org-shiftmetaright).

Also align node properties according to org-property-format.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-indent-line ()
  "Indent line depending on context.

Indentation is done according to the following rules:

  - Footnote definitions, diary sexps, headlines and inline tasks
    have to start at column 0.

  - On the very first line of an element, consider, in order, the
    next rules until one matches:

    1. If there's a sibling element before, ignoring footnote
       definitions and inline tasks, indent like its first line.

    2. If element has a parent, indent like its contents.  More
       precisely, if parent is an item, indent after the bullet.
       Else, indent like parent's first line.

    3. Otherwise, indent relatively to current level, if
       `org-adapt-indentation' is t, or to left margin.

  - On a blank line at the end of an element, indent according to
    the type of the element.  More precisely

    1. If element is a plain list, an item, or a footnote
       definition, indent like the very last element within.

    2. If element is a paragraph, indent like its last non blank
       line.

    3. Otherwise, indent like its very first line.

  - In the code part of a source block, use language major mode
    to indent current line if `org-src-tab-acts-natively' is
    non-nil.  If it is nil, do nothing.

  - Otherwise, indent like the first non-blank line above.

The function doesn't indent an item as it could break the whole
list structure.  Instead, use \\<org-mode-map>`\\[org-shiftmetaleft]' or \
`\\[org-shiftmetaright]'.

Also align node properties according to `org-property-format'."
  (interactive)
  (let* ((element (save-excursion (beginning-of-line) (org-element-at-point-no-context)))
	 (type (org-element-type element)))
    (unless (or (org-at-heading-p)
                (and (eq org-adapt-indentation 'headline-data)
                     (not (org--at-headline-data-p nil element))
                     (save-excursion
                       (goto-char (1- (org-element-property :begin element)))
                       (or (org-at-heading-p)
                           (org--at-headline-data-p)))))
      (cond ((and (memq type '(plain-list item))
		  (= (line-beginning-position)
		     (org-element-property :post-affiliated element)))
	     nil)
	    ((and (eq type 'latex-environment)
		  (>= (point) (org-element-property :post-affiliated element))
		  (< (point)
		     (org-with-point-at (org-element-property :end element)
		       (skip-chars-backward " \t\n")
		       (line-beginning-position 2))))
	     nil)
	    ((and (eq type 'src-block)
		  org-src-tab-acts-natively
		  (> (line-beginning-position)
		     (org-element-property :post-affiliated element))
		  (< (line-beginning-position)
		     (org-with-point-at (org-element-property :end element)
		       (skip-chars-backward " \t\n")
		       (line-beginning-position))))
             ;; At the beginning of a blank line, do some preindentation.  This
             ;; signals org-src--edit-element to preserve the indentation on exit
             (when (and (looking-at-p "^[[:space:]]*$")
                        (not org-src-preserve-indentation))
               (let ((element (org-element-at-point))
                     block-content-ind some-ind)
                 (org-with-point-at (org-element-property :begin element)
                   (setq block-content-ind (+ (org-current-text-indentation)
                                              org-edit-src-content-indentation))
                   (forward-line)
		   (save-match-data (re-search-forward "^[ \t]*\\S-" nil t))
                   (backward-char)
                   (setq some-ind (if (looking-at-p "#\\+end_src")
                                      block-content-ind (org-current-text-indentation))))
                 (indent-line-to (min block-content-ind some-ind))))
	     (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))
	    (t
	     (let ((column (org--get-expected-indentation element nil)))
	       ;; Preserve current column.
	       (if (<= (current-column) (current-indentation))
		   (indent-line-to column)
		 (save-excursion (indent-line-to column))))
	     ;; Align node property.  Also preserve current column.
	     (when (eq type 'node-property)
	       (let ((column (current-column)))
		 (org--align-node-property)
		 (org-move-to-column column))))))))